@VisibleForTesting public List<String> diff(InputStream actual, InputStream expected) throws IOException { BufferedReader reader1 = null; BufferedReader reader2 = null; try { reader1 = readerFor(actual); reader2 = readerFor(expected); return unmodifiableList(diff(reader1, reader2)); } finally { closeQuietly(reader1); closeQuietly(reader2); } }
/** * Closes the given {@link Closeable}s, ignoring any thrown exceptions. * * @param closeables the {@code Closeable}s to close. */ public static void closeQuietly(Closeable... closeables) { for (Closeable c : closeables) { closeCloseable(c); } }
@VisibleForTesting public List<String> diff(File actual, File expected) throws IOException { BufferedReader reader1 = null; BufferedReader reader2 = null; try { reader1 = readerFor(actual); reader2 = readerFor(expected); return unmodifiableList(diff(reader1, reader2)); } finally { closeQuietly(reader1); closeQuietly(reader2); } }
@VisibleForTesting public List<String> diff(File actual, String expected, Charset charset) throws IOException { BufferedReader reader1 = null; try { reader1 = readerFor(actual, charset); BufferedReader reader2 = readerFor(expected); return unmodifiableList(diff(reader1, reader2)); } finally { closeQuietly(reader1); } }
public void write(File file, Charset charset, String... content) throws IOException { PrintWriter writer = null; try { writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), charset)); for (String line : content) { writer.println(line); } } finally { closeQuietly(writer); } }
/** * Flushes and closes the given <code>{@link OutputStream}</code>. Any I/O errors catched by this method are ignored * and not rethrown. * * @param out the output stream to flush and close. */ public static void flushAndClose(OutputStream out) { if (out == null) { return; } flush(out); closeQuietly(out); }
/** * Flushes and closes the given <code>{@link Writer}</code>. Any I/O errors catched by this method are ignored and not * rethrown. * * @param writer the writer to flush and close. */ public static void flushAndClose(Writer writer) { if (writer == null) { return; } flush(writer); closeQuietly(writer); }