@Test public void fileToZipBytesDir() throws Exception { final File zipFile = new File("src/test/resources/imgrepo/C"); final byte[] zipBytes = ZipByteArrayUtils.fileToZipBytes(zipFile); assertFalse(zipBytes.length == zipFile.length()); final File zipFileTarget = new File("target/test-classes/ziptest/C.zip"); Files.write(zipFileTarget.toPath(), zipBytes); final File unzipFileTarget = new File("target/test-classes/ziptest/"); new ZipUtils("UTF-8").unzipArchive(zipFileTarget, unzipFileTarget); final File[] files = unzipFileTarget.listFiles(); boolean found = false; for (File file : files) { if (file.getName().equals("C")) { found = true; assertEquals(file.length(), zipFile.length()); break; } } assertTrue(found); }
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);  }