@Test public void reportNonExistingFile() throws IOException { File file = folder.newFile(); Files.delete(file.toPath()); new GzipEncoder(file).run(); assertThat(systemStream.consumeErrorOutput()) .containsOnlyOnce("ERROR") .contains(file.getAbsolutePath()); }
@Override public void run() { try { FileInputStream fileInputStream = new FileInputStream(sourceFile); try { FileOutputStream fileOutputStream = new FileOutputStream(targetFile); try { GZIPOutputStream gzipOutputStream = new GZIPOutputStream(fileOutputStream, BUFFER_SIZE); try { byte[] buffer = new byte[BUFFER_SIZE]; int count; while ((count = fileInputStream.read(buffer)) >= 0) { gzipOutputStream.write(buffer, 0, count); } } finally { gzipOutputStream.close(); } } finally { fileOutputStream.close(); } } finally { fileInputStream.close(); } if (!sourceFile.delete()) { InternalLogger.log(Level.WARN, "Failed to delete original log file '" + sourceFile + "'"); } } catch (IOException ex) { InternalLogger.log(Level.ERROR, ex, "Failed to compress log file '" + sourceFile + "'"); } }
GzipEncoder implements Runnable { @Override public void run() { try { FileInputStream fileInputStream = new FileInputStream(sourceFile); try { FileOutputStream fileOutputStream = new FileOutputStream(targetFile); try { GZIPOutputStream gzipOutputStream = new GZIPOutputStream(fileOutputStream, BUFFER_SIZE); try { byte[] buffer = new byte[BUFFER_SIZE]; int count; while ((count = fileInputStream.read(buffer)) >= 0) { gzipOutputStream.write(buffer, 0, count); } } finally { gzipOutputStream.close(); } } finally { fileOutputStream.close(); } } finally { fileInputStream.close(); } if (!sourceFile.delete()) { InternalLogger.log(Level.WARN, "Failed to delete original log file '" + sourceFile + "'"); } } catch (IOException ex) { InternalLogger.log(Level.ERROR, ex, "Failed to compress log file '" + sourceFile + "'"); } } }
GzipEncoder implements Runnable { @Override public void run() { try { FileInputStream fileInputStream = new FileInputStream(sourceFile); try { FileOutputStream fileOutputStream = new FileOutputStream(targetFile); try { GZIPOutputStream gzipOutputStream = new GZIPOutputStream(fileOutputStream, BUFFER_SIZE); try { byte[] buffer = new byte[BUFFER_SIZE]; int count; while ((count = fileInputStream.read(buffer)) >= 0) { gzipOutputStream.write(buffer, 0, count); } } finally { gzipOutputStream.close(); } } finally { fileOutputStream.close(); } } finally { fileInputStream.close(); } if (!sourceFile.delete()) { InternalLogger.log(Level.WARN, "Failed to delete original log file '" + sourceFile + "'"); } } catch (IOException ex) { InternalLogger.log(Level.ERROR, ex, "Failed to compress log file '" + sourceFile + "'"); } } GzipEncoder(final File file); }
GzipEncoder implements Runnable { @Override public void run() { try { FileInputStream fileInputStream = new FileInputStream(sourceFile); try { FileOutputStream fileOutputStream = new FileOutputStream(targetFile); try { GZIPOutputStream gzipOutputStream = new GZIPOutputStream(fileOutputStream, BUFFER_SIZE); try { byte[] buffer = new byte[BUFFER_SIZE]; int count; while ((count = fileInputStream.read(buffer)) >= 0) { gzipOutputStream.write(buffer, 0, count); } } finally { gzipOutputStream.close(); } } finally { fileOutputStream.close(); } } finally { fileInputStream.close(); } if (!sourceFile.delete()) { InternalLogger.log(Level.WARN, "Failed to delete original log file '" + sourceFile + "'"); } } catch (IOException ex) { InternalLogger.log(Level.ERROR, ex, "Failed to compress log file '" + sourceFile + "'"); } } GzipEncoder(final File file); @Override void run(); }
GzipEncoder implements Runnable { @Override public void run() { try { FileInputStream fileInputStream = new FileInputStream(sourceFile); try { FileOutputStream fileOutputStream = new FileOutputStream(targetFile); try { GZIPOutputStream gzipOutputStream = new GZIPOutputStream(fileOutputStream, BUFFER_SIZE); try { byte[] buffer = new byte[BUFFER_SIZE]; int count; while ((count = fileInputStream.read(buffer)) >= 0) { gzipOutputStream.write(buffer, 0, count); } } finally { gzipOutputStream.close(); } } finally { fileOutputStream.close(); } } finally { fileInputStream.close(); } if (!sourceFile.delete()) { InternalLogger.log(Level.WARN, "Failed to delete original log file '" + sourceFile + "'"); } } catch (IOException ex) { InternalLogger.log(Level.ERROR, ex, "Failed to compress log file '" + sourceFile + "'"); } } GzipEncoder(final File file); @Override void run();  }