/** * Reads all characters from a {@link Readable} object into a new * {@link StringBuilder} instance. Does not close the {@code Readable}. * * @param r the object to read from * @return a {@link StringBuilder} containing all the characters * @throws IOException if an I/O error occurs */ private static StringBuilder toStringBuilder(Readable r) throws IOException { StringBuilder sb = new StringBuilder(); copy(r, sb); return sb; }
/** * Reads all characters from a {@link Readable} object into a new * {@link StringBuilder} instance. Does not close the {@code Readable}. * * @param r the object to read from * @return a {@link StringBuilder} containing all the characters * @throws IOException if an I/O error occurs */ private static StringBuilder toStringBuilder(Readable r) throws IOException { StringBuilder sb = new StringBuilder(); copy(r, sb); return sb; }
/** * Reads all characters from a {@link Readable} object into a new * {@link StringBuilder} instance. Does not close the {@code Readable}. * * @param r the object to read from * @return a {@link StringBuilder} containing all the characters * @throws IOException if an I/O error occurs */ private static StringBuilder toStringBuilder(Readable r) throws IOException { StringBuilder sb = new StringBuilder(); copy(r, sb); return sb; }
/** * Opens a {@link Readable} object from the supplier, copies all characters * to the {@link Appendable} object, and closes the input. Does not close * or flush the output. * * @param from the input factory * @param to the object to write to * @return the number of characters copied * @throws IOException if an I/O error occurs */ public static <R extends Readable & Closeable> long copy(InputSupplier<R> from, Appendable to) throws IOException { boolean threw = true; R in = from.getInput(); try { long count = copy(in, to); threw = false; return count; } finally { Closeables.close(in, threw); } }
/** * Opens a {@link Readable} object from the supplier, copies all characters * to the {@link Appendable} object, and closes the input. Does not close * or flush the output. * * @param from the input factory * @param to the object to write to * @return the number of characters copied * @throws IOException if an I/O error occurs */ public static <R extends Readable & Closeable> long copy(InputSupplier<R> from, Appendable to) throws IOException { boolean threw = true; R in = from.getInput(); try { long count = copy(in, to); threw = false; return count; } finally { Closeables.close(in, threw); } }
/** * Opens a {@link Readable} object from the supplier, copies all characters * to the {@link Appendable} object, and closes the input. Does not close * or flush the output. * * @param from the input factory * @param to the object to write to * @return the number of characters copied * @throws IOException if an I/O error occurs */ public static <R extends Readable & Closeable> long copy(InputSupplier<R> from, Appendable to) throws IOException { boolean threw = true; R in = from.getInput(); try { long count = copy(in, to); threw = false; return count; } finally { Closeables.close(in, threw); } }
/** * Opens {@link Readable} and {@link Appendable} objects from the * given factories, copies all characters between the two, and closes * them. * * @param from the input factory * @param to the output factory * @return the number of characters copied * @throws IOException if an I/O error occurs */ public static <R extends Readable & Closeable, W extends Appendable & Closeable> long copy(InputSupplier<R> from, OutputSupplier<W> to) throws IOException { boolean threw = true; R in = from.getInput(); try { W out = to.getOutput(); try { long count = copy(in, out); threw = false; return count; } finally { Closeables.close(out, threw); } } finally { Closeables.close(in, threw); } }
/** * Opens {@link Readable} and {@link Appendable} objects from the * given factories, copies all characters between the two, and closes * them. * * @param from the input factory * @param to the output factory * @return the number of characters copied * @throws IOException if an I/O error occurs */ public static <R extends Readable & Closeable, W extends Appendable & Closeable> long copy(InputSupplier<R> from, OutputSupplier<W> to) throws IOException { boolean threw = true; R in = from.getInput(); try { W out = to.getOutput(); try { long count = copy(in, out); threw = false; return count; } finally { Closeables.close(out, threw); } } finally { Closeables.close(in, threw); } }
/** * Opens {@link Readable} and {@link Appendable} objects from the * given factories, copies all characters between the two, and closes * them. * * @param from the input factory * @param to the output factory * @return the number of characters copied * @throws IOException if an I/O error occurs */ public static <R extends Readable & Closeable, W extends Appendable & Closeable> long copy(InputSupplier<R> from, OutputSupplier<W> to) throws IOException { boolean threw = true; R in = from.getInput(); try { W out = to.getOutput(); try { long count = copy(in, out); threw = false; return count; } finally { Closeables.close(out, threw); } } finally { Closeables.close(in, threw); } }