/** * Opens a new buffered {@link Writer} for writing to this sink. The returned stream is not * required to be a {@link BufferedWriter} in order to allow implementations to simply delegate to * {@link #openStream()} when the stream returned by that method does not benefit from additional * buffering. This method returns a new, independent writer each time it is called. * * <p>The caller is responsible for ensuring that the returned writer is closed. * * @throws IOException if an I/O error occurs while opening the writer * @since 15.0 (in 14.0 with return type {@link BufferedWriter}) */ public Writer openBufferedStream() throws IOException { Writer writer = openStream(); return (writer instanceof BufferedWriter) ? (BufferedWriter) writer : new BufferedWriter(writer); }
@Override public OutputStream openStream() throws IOException { return encodingStream(encodedSink.openStream()); } };
/** * Opens a new buffered {@link Writer} for writing to this sink. The returned stream is not * required to be a {@link BufferedWriter} in order to allow implementations to simply delegate to * {@link #openStream()} when the stream returned by that method does not benefit from additional * buffering. This method returns a new, independent writer each time it is called. * * <p>The caller is responsible for ensuring that the returned writer is closed. * * @throws IOException if an I/O error occurs while opening the writer * @since 15.0 (in 14.0 with return type {@link BufferedWriter}) */ public Writer openBufferedStream() throws IOException { Writer writer = openStream(); return (writer instanceof BufferedWriter) ? (BufferedWriter) writer : new BufferedWriter(writer); }
@Override public long copyTo(CharSink sink) throws IOException { checkNotNull(sink); Closer closer = Closer.create(); try { Writer writer = closer.register(sink.openStream()); writer.write((String) seq); return seq.length(); } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } } }
/** * Writes the given character sequence to this sink. * * @throws IOException if an I/O error while writing to this sink */ public void write(CharSequence charSequence) throws IOException { checkNotNull(charSequence); Closer closer = Closer.create(); try { Writer out = closer.register(openStream()); out.append(charSequence); out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330 } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } }
/** * Opens a new buffered {@link Writer} for writing to this sink. The returned stream is not * required to be a {@link BufferedWriter} in order to allow implementations to simply delegate to * {@link #openStream()} when the stream returned by that method does not benefit from additional * buffering. This method returns a new, independent writer each time it is called. * * <p>The caller is responsible for ensuring that the returned writer is closed. * * @throws IOException if an I/O error occurs while opening the writer * @since 15.0 (in 14.0 with return type {@link BufferedWriter}) */ public Writer openBufferedStream() throws IOException { Writer writer = openStream(); return (writer instanceof BufferedWriter) ? (BufferedWriter) writer : new BufferedWriter(writer); }
@Override public OutputStream openStream() throws IOException { return encodingStream(encodedSink.openStream()); } };
@Override public OutputStream openStream() throws IOException { return encodingStream(encodedSink.openStream()); } };
/** * Writes the given character sequence to this sink. * * @throws IOException if an I/O error while writing to this sink */ public void write(CharSequence charSequence) throws IOException { checkNotNull(charSequence); Closer closer = Closer.create(); try { Writer out = closer.register(openStream()); out.append(charSequence); out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330 } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } }
/** * Writes all the text from the given {@link Readable} (such as a {@link Reader}) to this sink. * Does not close {@code readable} if it is {@code Closeable}. * * @return the number of characters written * @throws IOException if an I/O error occurs while reading from {@code readable} or writing to * this sink */ @CanIgnoreReturnValue public long writeFrom(Readable readable) throws IOException { checkNotNull(readable); Closer closer = Closer.create(); try { Writer out = closer.register(openStream()); long written = CharStreams.copy(readable, out); out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330 return written; } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } } }
/** * Copies the contents of this source to the given sink. * * @return the number of characters copied * @throws IOException if an I/O error occurs while reading from this source or writing to {@code * sink} */ @CanIgnoreReturnValue public long copyTo(CharSink sink) throws IOException { checkNotNull(sink); Closer closer = Closer.create(); try { Reader reader = closer.register(openStream()); Writer writer = closer.register(sink.openStream()); return CharStreams.copy(reader, writer); } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } }
@Override public long copyTo(CharSink sink) throws IOException { checkNotNull(sink); Closer closer = Closer.create(); try { Writer writer = closer.register(sink.openStream()); writer.write((String) seq); return seq.length(); } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } } }
/** * Writes the given character sequence to this sink. * * @throws IOException if an I/O error while writing to this sink */ public void write(CharSequence charSequence) throws IOException { checkNotNull(charSequence); Closer closer = Closer.create(); try { Writer out = closer.register(openStream()); out.append(charSequence); out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330 } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } }
public void testOpenStream() throws IOException { Writer writer = sink.openStream(); try { writer.write(data); } finally { writer.close(); } assertContainsExpectedString(); }
Closer closer = Closer.create(); try { Writer writer = closer.register(sink.openStream()); writer.write((String) seq); return seq.length();
/** * Writes all the text from the given {@link Readable} (such as a {@link Reader}) to this sink. * Does not close {@code readable} if it is {@code Closeable}. * * @return the number of characters written * @throws IOException if an I/O error occurs while reading from {@code readable} or writing to * this sink */ @CanIgnoreReturnValue public long writeFrom(Readable readable) throws IOException { checkNotNull(readable); Closer closer = Closer.create(); try { Writer out = closer.register(openStream()); long written = CharStreams.copy(readable, out); out.flush(); // https://code.google.com/p/guava-libraries/issues/detail?id=1330 return written; } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } } }
/** * Copies the contents of this source to the given sink. * * @return the number of characters copied * @throws IOException if an I/O error occurs while reading from this source or writing to {@code * sink} */ @CanIgnoreReturnValue public long copyTo(CharSink sink) throws IOException { checkNotNull(sink); Closer closer = Closer.create(); try { Reader reader = closer.register(openStream()); Writer writer = closer.register(sink.openStream()); return CharStreams.copy(reader, writer); } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } }
@Override public W getOutput() throws IOException { return (W) sink.openStream(); } };
@Override public OutputStream openStream() throws IOException { return encodingStream(encodedSink.openStream()); } };
@Override public OutputStream openStream() throws IOException { return encodingStream(encodedSink.openStream()); } };