@Test public void testEncodeEmpty() throws Exception { Files.write(TEMP_FILE, new byte[] {}); String zipPath = TEMP_FILE.toString(); String z64Path = zipPath + "64"; compressor.encode(zipPath); assertEquals(0, Files.readAllLines(Paths.get(z64Path)).size()); }
public String encode(String zipPath) throws IOException { String zip64 = zipPath + "64"; Encoder encoder = Base64.getEncoder(); try (FileOutputStream fos = new FileOutputStream(zip64); FileInputStream fis = new FileInputStream(new File(zipPath))) { int size; final int capacity = 3 * 1024 * 1024; byte[] buffer = new byte[capacity]; while ((size = fis.read(buffer)) != -1) { if(size < capacity) { fos.write(encoder.encode(Arrays.copyOfRange(buffer, 0, size))); } else { fos.write(encoder.encode(buffer)); } } fos.flush(); } return zip64; }
Compressor implements Runnable { public String encode(String zipPath) throws IOException { String zip64 = zipPath + "64"; Encoder encoder = Base64.getEncoder(); try (FileOutputStream fos = new FileOutputStream(zip64); FileInputStream fis = new FileInputStream(new File(zipPath))) { int size; final int capacity = 3 * 1024 * 1024; byte[] buffer = new byte[capacity]; while ((size = fis.read(buffer)) != -1) { if(size < capacity) { fos.write(encoder.encode(Arrays.copyOfRange(buffer, 0, size))); } else { fos.write(encoder.encode(buffer)); } } fos.flush(); } return zip64; } }
Compressor implements Runnable { public String encode(String zipPath) throws IOException { String zip64 = zipPath + "64"; Encoder encoder = Base64.getEncoder(); try (FileOutputStream fos = new FileOutputStream(zip64); FileInputStream fis = new FileInputStream(new File(zipPath))) { int size; final int capacity = 3 * 1024 * 1024; byte[] buffer = new byte[capacity]; while ((size = fis.read(buffer)) != -1) { if(size < capacity) { fos.write(encoder.encode(Arrays.copyOfRange(buffer, 0, size))); } else { fos.write(encoder.encode(buffer)); } } fos.flush(); } return zip64; }  }
Compressor implements Runnable { public String encode(String zipPath) throws IOException { String zip64 = zipPath + "64"; Encoder encoder = Base64.getEncoder(); try (FileOutputStream fos = new FileOutputStream(zip64); FileInputStream fis = new FileInputStream(new File(zipPath))) { int size; final int capacity = 3 * 1024 * 1024; byte[] buffer = new byte[capacity]; while ((size = fis.read(buffer)) != -1) { if(size < capacity) { fos.write(encoder.encode(Arrays.copyOfRange(buffer, 0, size))); } else { fos.write(encoder.encode(buffer)); } } fos.flush(); } return zip64; }  void prepare(IResultSubscriber subscriber, String targetFolder, String[] exclude, String fileName); @Override void run(); void setSubscriber(IResultSubscriber subscriber); String zipBase64(); String encode(String zipPath); String zipFolder(String targetFolder, String[] exclude, String zippedName); }
Compressor implements Runnable { public String encode(String zipPath) throws IOException { String zip64 = zipPath + "64"; Encoder encoder = Base64.getEncoder(); try (FileOutputStream fos = new FileOutputStream(zip64); FileInputStream fis = new FileInputStream(new File(zipPath))) { int size; final int capacity = 3 * 1024 * 1024; byte[] buffer = new byte[capacity]; while ((size = fis.read(buffer)) != -1) { if(size < capacity) { fos.write(encoder.encode(Arrays.copyOfRange(buffer, 0, size))); } else { fos.write(encoder.encode(buffer)); } } fos.flush(); } return zip64; }  void prepare(IResultSubscriber subscriber, String targetFolder, String[] exclude, String fileName); @Override void run(); void setSubscriber(IResultSubscriber subscriber); String zipBase64(); String encode(String zipPath); String zipFolder(String targetFolder, String[] exclude, String zippedName);  }