List of usage examples for com.google.common.io CharSink CharSink
CharSink
From source file:org.dishevelled.compress.Sinks.java
/** * Create and return a new bzip2 compressed char sink for the specified file. * * @since 1.3//from www .j a v a 2 s . co m * @param file file, must not be null * @param append true to append to the specified file * @return a new bzip2 compressed char sink for the specified file */ public static CharSink bzip2FileCharSink(final File file, final boolean append) { checkNotNull(file); return new CharSink() { @Override public Writer openStream() throws IOException { return new BufferedWriter(new OutputStreamWriter( new BZip2CompressorOutputStream(new FileOutputStream(file, append)))); } }; }
From source file:dagger.internal.codegen.writer.JavaWriter.java
public void file(Filer filer, CharSequence name, Iterable<? extends Element> originatingElements) throws IOException { final JavaFileObject sourceFile = filer.createSourceFile(name, Iterables.toArray(originatingElements, Element.class)); try {//from w w w . ja va 2s .c om new Formatter().formatSource(CharSource.wrap(write(new StringBuilder())), new CharSink() { @Override public Writer openStream() throws IOException { return sourceFile.openWriter(); } }); } catch (FormatterException e) { throw new IllegalStateException("The writer produced code that could not be parsed by the formatter", e); } }
From source file:microsoft.exchange.webservices.data.core.EwsServiceXmlWriter.java
/** * Writes the base64-encoded element value. * * @param source the source containing bytes to be written * @throws IOException signals that an I/O exception has occurred *//* ww w . j a va2 s. co m*/ public void writeBase64ElementValue(ByteSource source) throws IOException { ByteSink sink = base64().encodingSink(new CharSink() { @Override public Writer openStream() throws IOException { return new BufferedWriter(new Writer() { @Override public void write(char[] cbuf, int off, int len) throws IOException { try { xmlWriter.writeCharacters(cbuf, off, len); } catch (XMLStreamException e) { throw new IOException("Error writing XML", e); } } @Override public void flush() { } @Override public void close() { } }); } }); source.copyTo(sink); }