List of usage examples for org.apache.hadoop.fs Seekable seek
void seek(long pos) throws IOException;
From source file:alluxio.client.hadoop.HdfsFileInputStreamIntegrationTest.java
License:Apache License
private void seekTest(Seekable stream) throws Exception { stream.seek(0); Assert.assertEquals(0, stream.getPos()); stream.seek(FILE_LEN / 2);/*from w w w. java2 s .c o m*/ Assert.assertEquals(FILE_LEN / 2, stream.getPos()); stream.seek(1); Assert.assertEquals(1, stream.getPos()); }
From source file:alluxio.hadoop.HdfsFileInputStreamIntegrationTest.java
License:Apache License
private void seekTest(Seekable stream) throws IOException { stream.seek(0); Assert.assertEquals(0, stream.getPos()); stream.seek(FILE_LEN / 2);/*from w w w . ja va2 s .c om*/ Assert.assertEquals(FILE_LEN / 2, stream.getPos()); stream.seek(1); Assert.assertEquals(1, stream.getPos()); }
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 w w .j a v a 2 s.c o m * * @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()); }