Example usage for org.apache.hadoop.fs Seekable seekToNewSource

List of usage examples for org.apache.hadoop.fs Seekable seekToNewSource

Introduction

In this page you can find the example usage for org.apache.hadoop.fs Seekable seekToNewSource.

Prototype

@InterfaceAudience.Private
boolean seekToNewSource(long targetPos) throws IOException;

Source Link

Document

Seeks a different copy of the data.

Usage

From source file:co.cask.tigon.io.SeekableInputStream.java

License:Apache License

/**
 * Creates a {@link SeekableInputStream} from the given {@link java.io.InputStream}. Exception will be
 * thrown if failed to do so./*from w  ww  .j  av a2 s . com*/
 *
 * @throws java.io.IOException If the given input stream is not seekable.
 */
public static SeekableInputStream create(InputStream input) throws IOException {
    if (input instanceof SeekableInputStream) {
        return (SeekableInputStream) input;
    }
    if (input instanceof FileInputStream) {
        return create((FileInputStream) input);
    }
    if (input instanceof Seekable) {
        final Seekable seekable = (Seekable) input;
        return new SeekableInputStream(input) {
            @Override
            public void seek(long pos) throws IOException {
                seekable.seek(pos);
            }

            @Override
            public long getPos() throws IOException {
                return seekable.getPos();
            }

            @Override
            public boolean seekToNewSource(long targetPos) throws IOException {
                return seekable.seekToNewSource(targetPos);
            }
        };
    }

    throw new IOException("Failed to create SeekableInputStream from " + input.getClass());
}