/** * Copies all characters from a file to an appendable object, using the given character set. * * @param from the source file * @param charset the charset used to decode the input stream; see {@link StandardCharsets} for * helpful predefined constants * @param to the appendable object * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSource(from, charset).copyTo(to)}. This method is scheduled to * be removed in January 2019. */ @Deprecated public static void copy(File from, Charset charset, Appendable to) throws IOException { asCharSource(from, charset).copyTo(to); }
/** * Copies all characters from a file to an appendable object, using the given character set. * * @param from the source file * @param charset the charset used to decode the input stream; see {@link StandardCharsets} for * helpful predefined constants * @param to the appendable object * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSource(from, charset).copyTo(to)}. This method is scheduled to * be removed in January 2019. */ @Deprecated public static void copy(File from, Charset charset, Appendable to) throws IOException { asCharSource(from, charset).copyTo(to); }
/** * Copies all characters from a file to an appendable object, using the given character set. * * @param from the source file * @param charset the charset used to decode the input stream; see {@link StandardCharsets} for * helpful predefined constants * @param to the appendable object * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSource(from, charset).copyTo(to)}. This method is scheduled to * be removed in January 2019. */ @Deprecated public static void copy(File from, Charset charset, Appendable to) throws IOException { asCharSource(from, charset).copyTo(to); }
private static void runFailureTest(CharSource in, CharSink out) { try { in.copyTo(out); fail(); } catch (IOException expected) { } }
public void testCopyTo_appendable() throws IOException { StringBuilder builder = new StringBuilder(); assertEquals(expected.length(), source.copyTo(builder)); assertExpectedString(builder.toString()); }
/** @return the number of exceptions that were suppressed on the expected thrown exception */ private static int runSuppressionFailureTest(CharSource in, CharSink out) { try { in.copyTo(out); fail(); } catch (IOException expected) { return CloserTest.getSuppressed(expected).length; } throw new AssertionError(); // can't happen }
public void testCopyTo_charSink() throws IOException { TestCharSink sink = new TestCharSink(); assertEquals(expected.length(), source.copyTo(sink)); assertExpectedString(sink.getString()); }
/** * Copies all characters from a file to an appendable object, * using the given character set. * * @param from the source file * @param charset the charset used to decode the input stream; see {@link * Charsets} for helpful predefined constants * @param to the appendable object * @throws IOException if an I/O error occurs */ public static void copy(File from, Charset charset, Appendable to) throws IOException { asCharSource(from, charset).copyTo(to); }
/** * 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 { return asCharSource(from).copyTo(to); }
/** * Copies all characters from a file to an appendable object, * using the given character set. * * @param from the source file * @param charset the charset used to decode the input stream; see {@link * Charsets} for helpful predefined constants * @param to the appendable object * @throws IOException if an I/O error occurs */ public static void copy(File from, Charset charset, Appendable to) throws IOException { asCharSource(from, charset).copyTo(to); }
/** * 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 { return asCharSource(from).copyTo(to); }
/** * Copies all characters from a file to an appendable object, * using the given character set. * * @param from the source file * @param charset the charset used to decode the input stream; see {@link * Charsets} for helpful predefined constants * @param to the appendable object * @throws IOException if an I/O error occurs */ public static void copy(File from, Charset charset, Appendable to) throws IOException { asCharSource(from, charset).copyTo(to); }
/** * Copies all characters from a file to an appendable object, * using the given character set. * * @param from the source file * @param charset the charset used to decode the input stream; see {@link * Charsets} for helpful predefined constants * @param to the appendable object * @throws IOException if an I/O error occurs */ public static void copy(File from, Charset charset, Appendable to) throws IOException { asCharSource(from, charset).copyTo(to); }
/** * 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 { return asCharSource(from).copyTo(to); }
/** * 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 { return asCharSource(from).copyTo(to); }
private static void storeCacheVersionsFile(String json, File cacheFile) { //noinspection ResultOfMethodCallIgnored cacheFile.getParentFile().mkdirs(); try { CharSource.wrap(json).copyTo(Files.asCharSink(cacheFile, Charsets.UTF_8)); } catch (IOException e) { LOG.error("Cannot write Gradle version information cache file.", e); // do not throw an exception if cache file cannot be written to be more robust against file system problems } }
private static void runFailureTest(CharSource in, CharSink out) { try { in.copyTo(out); fail(); } catch (IOException expected) { } }
public void testCopyTo_appendable() throws IOException { StringBuilder builder = new StringBuilder(); assertEquals(expected.length(), source.copyTo(builder)); assertExpectedString(builder.toString()); }
/** * @return the number of exceptions that were suppressed on the expected thrown exception */ private static int runSuppressionFailureTest(CharSource in, CharSink out) { try { in.copyTo(out); fail(); } catch (IOException expected) { return CloserTest.getSuppressed(expected).length; } throw new AssertionError(); // can't happen }
public void testCopyTo_charSink() throws IOException { TestCharSink sink = new TestCharSink(); assertEquals(expected.length(), source.copyTo(sink)); assertExpectedString(sink.getString()); }