Example usage for com.google.common.io ByteSource copyTo

List of usage examples for com.google.common.io ByteSource copyTo

Introduction

In this page you can find the example usage for com.google.common.io ByteSource copyTo.

Prototype

public long copyTo(ByteSink sink) throws IOException 

Source Link

Document

Copies the contents of this byte source to the given ByteSink .

Usage

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
 *//*from w w w . ja va 2s  .c  o  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);
}