Example usage for com.google.common.io ByteSink writeFrom

List of usage examples for com.google.common.io ByteSink writeFrom

Introduction

In this page you can find the example usage for com.google.common.io ByteSink writeFrom.

Prototype

public long writeFrom(InputStream input) throws IOException 

Source Link

Document

Writes all the bytes from the given InputStream to this sink.

Usage

From source file:org.queeg.hadoop.tar.TarExtractor.java

public void extract(ByteSource source) throws IOException {
    TarArchiveInputStream archiveInputStream = new TarArchiveInputStream(source.openStream());

    TarArchiveEntry entry;//from  w  w  w . ja va 2 s.  c  om
    while ((entry = archiveInputStream.getNextTarEntry()) != null) {
        if (entry.isFile()) {
            BoundedInputStream entryInputStream = new BoundedInputStream(archiveInputStream, entry.getSize());
            ByteSink sink = new PathByteSink(conf, new Path(destination, entry.getName()));
            sink.writeFrom(entryInputStream);
        } else if (entry.isDirectory()) {
            ByteStreams.skipFully(archiveInputStream, entry.getSize());
            fs.mkdirs(new Path(destination, entry.getName()));
        }
    }

    archiveInputStream.close();
}