Package net.sansa_stack.hadoop.util
Class DeferredSeekablePushbackInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.io.PushbackInputStream
net.sansa_stack.hadoop.util.DeferredSeekablePushbackInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable,SeekableDecorator,org.apache.hadoop.fs.Seekable
public class DeferredSeekablePushbackInputStream
extends PushbackInputStream
implements SeekableDecorator
A wrapper for hadoop input streams created from codecs in ReadMode.BY_BLOCK:
Defers reading by one byte such that position changes are advertised on the byte BEFORE
the block boundary rather than on the byte AFTER it.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]protected net.sansa_stack.hadoop.util.DeferredSeekablePushbackInputStream.ReadModeUnsafe reads modify the byte after the reported number of read bytes in the read buffer.protected org.apache.hadoop.fs.SeekableFields inherited from class java.io.PushbackInputStream
buf, posFields inherited from class java.io.FilterInputStream
in -
Constructor Summary
ConstructorsConstructorDescriptionDeferredSeekablePushbackInputStream(InputStream in, org.apache.hadoop.fs.Seekable seekable) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidvoidclose()longgetPos()org.apache.hadoop.fs.Seekableintread()intread(byte[] b, int off, int len) This method essentially delays reads by one byte.protected intreadInternal(byte[] b, int off, int len) This method is assumed to be invoked with len >= 2voidseek(long l) booleanseekToNewSource(long l) Methods inherited from class java.io.PushbackInputStream
available, mark, markSupported, reset, skip, unread, unread, unreadMethods inherited from class java.io.FilterInputStream
readMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
seekable
protected org.apache.hadoop.fs.Seekable seekable -
readMode
protected net.sansa_stack.hadoop.util.DeferredSeekablePushbackInputStream.ReadMode readModeUnsafe reads modify the byte after the reported number of read bytes in the read buffer. Example: If buf := [a, b, c, d] and "read(buf)" returns 3, then buf[3] may no longer hold a 'd'. As this may cause data corruption, safe read mode uses an intermediate buffer with additional copying to prevent changing data outside of the reported range. -
fallbackBuffer
protected byte[] fallbackBuffer
-
-
Constructor Details
-
DeferredSeekablePushbackInputStream
-
DeferredSeekablePushbackInputStream
-
-
Method Details
-
getSeekable
public org.apache.hadoop.fs.Seekable getSeekable()- Specified by:
getSeekablein interfaceSeekableDecorator
-
read
- Overrides:
readin classPushbackInputStream- Throws:
IOException
-
read
This method essentially delays reads by one byte. Whereas hadoop's codec protocol reads one byte past block boundaries, this method buffers one byte on every read such that once the underlying stream reads accross the block boundary -- indicated by a position change -- only the byte before the block boundary is returned.- Overrides:
readin classPushbackInputStream- Returns:
- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classPushbackInputStream- Throws:
IOException
-
readInternal
This method is assumed to be invoked with len >= 2- Throws:
IOException
-
afterSeek
protected void afterSeek() -
seek
- Specified by:
seekin interfaceorg.apache.hadoop.fs.Seekable- Specified by:
seekin interfaceSeekableDecorator- Throws:
IOException
-
getPos
- Specified by:
getPosin interfaceorg.apache.hadoop.fs.Seekable- Specified by:
getPosin interfaceSeekableDecorator- Throws:
IOException
-
seekToNewSource
- Specified by:
seekToNewSourcein interfaceorg.apache.hadoop.fs.Seekable- Specified by:
seekToNewSourcein interfaceSeekableDecorator- Throws:
IOException
-