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
InputStream
are not supported.-
Field Summary
Modifier and TypeFieldDescriptionprotected int
The number of valid bytes ininternalBuffer
.protected int
The current read position in the buffer; the index of the next character to be read from theinternalBuffer
array.protected long
protected DrillBuf
The 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, totalByteSize
Fields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ConstructorDescriptionBufferedDirectBufInputStream
(InputStream in, BufferAllocator allocator, String id, long startOffset, long totalByteSize, boolean enforceTotalByteSize, boolean enableHints) Creates aBufferedDirectBufInputStream
with the default (8 MiB) buffer size.BufferedDirectBufInputStream
(InputStream in, BufferAllocator allocator, String id, long startOffset, long totalByteSize, int bufSize, boolean enforceTotalByteSize, boolean enableHints) Creates aBufferedDirectBufInputStream
with the specified buffer size. -
Method Summary
Modifier and TypeMethodDescriptionint
void
close()
long
getPos()
void
init()
void
mark
(int readlimit) boolean
int
read()
Implements theread
method ofInputStream
.int
read
(byte[] b) int
read
(byte[] buf, int off, int len) int
Has the same contract asInputStream.read(byte[], int, int)
Except with DrillBufvoid
reset()
long
skip
(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, hasRemainder
-
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
.count
is 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 theinternalBuffer
array. This value is always in the range[0,count]
. IfcurPosInBuffer
is 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 aBufferedDirectBufInputStream
with 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 aBufferedDirectBufInputStream
with the specified buffer size.
-
-
Method Details
-
init
- Overrides:
init
in classDirectBufInputStream
- Throws:
UnsupportedOperationException
IOException
-
read
Implements theread
method ofInputStream
. returns one more byte or -1 if end of stream is reached.- Overrides:
read
in classDirectBufInputStream
- Throws:
IOException
-
read
Has the same contract asInputStream.read(byte[], int, int)
Except with DrillBuf- Overrides:
read
in classDirectBufInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
read
- Overrides:
read
in 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:
skip
in classFilterInputStream
- Throws:
IOException
-
available
- Overrides:
available
in classFilterInputStream
- Throws:
IOException
-
mark
public void mark(int readlimit) - Overrides:
mark
in classFilterInputStream
-
reset
- Overrides:
reset
in classFilterInputStream
- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupported
in classFilterInputStream
-
getPos
- Overrides:
getPos
in classDirectBufInputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classDirectBufInputStream
- Throws:
IOException
-