@Test public void fileToZipBytesZip() throws Exception { final File zipFile = new File("src/test/resources/archive/testfile.zip"); final byte[] zipBytes = ZipByteArrayUtils.fileToZipBytes(zipFile); assertArrayEquals(zipBytes, Files.readAllBytes(zipFile.toPath())); }
public static byte[] fileToZipBytes(final File file) throws IOException { if (file == null || !file.exists()) { throw new IllegalArgumentException("File must not be null"); } if (file.isFile() && file.getName().endsWith(".zip")) { return FileUtils.readFileToByteArray(file); } else { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ZipOutputStream zos = new ZipOutputStream(baos); appendFile(zos, null, file); zos.close(); return baos.toByteArray(); } }
ZipByteArrayUtils { public static byte[] fileToZipBytes(final File file) throws IOException { if (file == null || !file.exists()) { throw new IllegalArgumentException("File must not be null"); } if (file.isFile() && file.getName().endsWith(".zip")) { return FileUtils.readFileToByteArray(file); } else { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ZipOutputStream zos = new ZipOutputStream(baos); appendFile(zos, null, file); zos.close(); return baos.toByteArray(); } } }
ZipByteArrayUtils { public static byte[] fileToZipBytes(final File file) throws IOException { if (file == null || !file.exists()) { throw new IllegalArgumentException("File must not be null"); } if (file.isFile() && file.getName().endsWith(".zip")) { return FileUtils.readFileToByteArray(file); } else { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ZipOutputStream zos = new ZipOutputStream(baos); appendFile(zos, null, file); zos.close(); return baos.toByteArray(); } } private  ZipByteArrayUtils(); }
ZipByteArrayUtils { public static byte[] fileToZipBytes(final File file) throws IOException { if (file == null || !file.exists()) { throw new IllegalArgumentException("File must not be null"); } if (file.isFile() && file.getName().endsWith(".zip")) { return FileUtils.readFileToByteArray(file); } else { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ZipOutputStream zos = new ZipOutputStream(baos); appendFile(zos, null, file); zos.close(); return baos.toByteArray(); } } private  ZipByteArrayUtils(); static byte[] fileToZipBytes(final File file); }
ZipByteArrayUtils { public static byte[] fileToZipBytes(final File file) throws IOException { if (file == null || !file.exists()) { throw new IllegalArgumentException("File must not be null"); } if (file.isFile() && file.getName().endsWith(".zip")) { return FileUtils.readFileToByteArray(file); } else { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ZipOutputStream zos = new ZipOutputStream(baos); appendFile(zos, null, file); zos.close(); return baos.toByteArray(); } } private  ZipByteArrayUtils(); static byte[] fileToZipBytes(final File file);  }