Class BufferedDirectBufInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.drill.exec.util.filereader.DirectBufInputStream
org.apache.drill.exec.util.filereader.BufferedDirectBufInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
BufferedDirectBufInputStream reads from the
underlying InputStream in blocks of data, into an
internal buffer. The internal buffer is a direct memory backed
buffer. The implementation is similar to the BufferedInputStream
class except that the internal buffer is a Drillbuf and
not a byte array. The mark and reset methods of the underlying
InputStreamare not supported.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe number of valid bytes ininternalBuffer.protected intThe current read position in the buffer; the index of the next character to be read from theinternalBufferarray.protected longprotected DrillBufThe internal buffer to keep data read from the underlying inputStream.Fields inherited from class org.apache.drill.exec.util.filereader.DirectBufInputStream
allocator, enableHints, enforceTotalByteSize, startOffset, streamId, totalByteSizeFields inherited from class java.io.FilterInputStream
in -
Constructor Summary
ConstructorsConstructorDescriptionBufferedDirectBufInputStream(InputStream in, BufferAllocator allocator, String id, long startOffset, long totalByteSize, boolean enforceTotalByteSize, boolean enableHints) Creates aBufferedDirectBufInputStreamwith the default (8 MiB) buffer size.BufferedDirectBufInputStream(InputStream in, BufferAllocator allocator, String id, long startOffset, long totalByteSize, int bufSize, boolean enforceTotalByteSize, boolean enableHints) Creates aBufferedDirectBufInputStreamwith the specified buffer size. -
Method Summary
Modifier and TypeMethodDescriptionintvoidclose()longgetPos()voidinit()voidmark(int readlimit) booleanintread()Implements thereadmethod ofInputStream.intread(byte[] b) intread(byte[] buf, int off, int len) intHas the same contract asInputStream.read(byte[], int, int)Except with DrillBufvoidreset()longskip(long n) Has the same contract asInputStream.skip(long)Skips upto the next n bytes.Methods inherited from class org.apache.drill.exec.util.filereader.DirectBufInputStream
checkInputStreamState, checkStreamSupportsByteBuffer, fadviseIfAvailable, getInputStream, getNext, hasRemainderMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
-
Field Details
-
internalBuffer
The internal buffer to keep data read from the underlying inputStream.internalBuffer[0]throughinternalBuffer[count-1]contains data read from the underlying input stream. -
count
protected int countThe number of valid bytes ininternalBuffer.countis always in the range[0,internalBuffer.capacity]internalBuffer[count-1]is the last valid byte in the buffer. -
curPosInBuffer
protected int curPosInBufferThe current read position in the buffer; the index of the next character to be read from theinternalBufferarray. This value is always in the range[0,count]. IfcurPosInBufferis equal tocount>then we have read all the buffered data and the next read (or skip) will require more data to be read from the underlying input stream. -
curPosInStream
protected long curPosInStream
-
-
Constructor Details
-
BufferedDirectBufInputStream
public BufferedDirectBufInputStream(InputStream in, BufferAllocator allocator, String id, long startOffset, long totalByteSize, boolean enforceTotalByteSize, boolean enableHints) Creates aBufferedDirectBufInputStreamwith the default (8 MiB) buffer size. -
BufferedDirectBufInputStream
public BufferedDirectBufInputStream(InputStream in, BufferAllocator allocator, String id, long startOffset, long totalByteSize, int bufSize, boolean enforceTotalByteSize, boolean enableHints) Creates aBufferedDirectBufInputStreamwith the specified buffer size.
-
-
Method Details
-
init
- Overrides:
initin classDirectBufInputStream- Throws:
UnsupportedOperationExceptionIOException
-
read
Implements thereadmethod ofInputStream. returns one more byte or -1 if end of stream is reached.- Overrides:
readin classDirectBufInputStream- Throws:
IOException
-
read
Has the same contract asInputStream.read(byte[], int, int)Except with DrillBuf- Overrides:
readin classDirectBufInputStream- Throws:
IOException
-
read
- Overrides:
readin classFilterInputStream- Throws:
IOException
-
read
- Overrides:
readin classFilterInputStream- Throws:
IOException
-
skip
Has the same contract asInputStream.skip(long)Skips upto the next n bytes. Skip may return with less than n bytes skipped- Overrides:
skipin classFilterInputStream- Throws:
IOException
-
available
- Overrides:
availablein classFilterInputStream- Throws:
IOException
-
mark
public void mark(int readlimit) - Overrides:
markin classFilterInputStream
-
reset
- Overrides:
resetin classFilterInputStream- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classFilterInputStream
-
getPos
- Overrides:
getPosin classDirectBufInputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classDirectBufInputStream- Throws:
IOException
-