public class BuffersInputStream
extends java.io.InputStream
Modifier and Type | Class and Description |
---|---|
class |
BuffersInputStream.Connection<T extends SourceData>
Maintains state for writers to this BuffersInputStream.
|
class |
BuffersInputStream.Line
To avoid making objects, represent an input line as a range in a byte
array, and not as a String or a byte[].
|
static class |
BuffersInputStream.SimpleSourceDataHandler
Simple handler for SourceDatas.
|
Modifier and Type | Field and Description |
---|---|
protected static LogLevel |
logLevel |
protected static java.util.logging.Logger |
tracer |
protected static java.nio.charset.Charset |
utf8 |
Constructor and Description |
---|
BuffersInputStream() |
BuffersInputStream(SourceDataFactory<?> sourceDataFactory) |
Modifier and Type | Method and Description |
---|---|
void |
addBuffer(SourceWorkUnit<SourceData> buf)
Add a SourceData to queue for reading.
|
void |
addRowtimeBound(java.sql.Timestamp t)
Add a rowtime bound to stream.
|
int |
available()
Guaranteed to not return more bytes than that left in the current message
- or the next on-empty message if the current one is already exhausted.
|
int |
buffersAvailable()
Get number of buffers available for reading
|
void |
close() |
void |
enableEosAtMessageEnd()
Request eos at end of every message.
|
<T extends SourceData> |
getConnection() |
byte[] |
getCurrentPayload(int maxBytes)
Return the byte contents of the last (consumed) buffer, up to a max number of bytes.
|
boolean |
getLine(BuffersInputStream.Line out,
byte[] delimiter)
Get the next input line, by scanning up to but not including the next
unquoted DELIMITER or end of message.
|
long |
getPayloadCount()
Get the number of SourceDatas we have seen so far.
|
long |
getPosition()
Gives the offset in bytes of the next read from the start of the stream.
|
byte[] |
getQuoteCharacters()
Gets the quoteCharacter used for searching.
|
long |
getQuoteCount()
Gets the count of quote characters seen in the most recent
unquoted search.
|
SourceDataFactory<?> |
getSourceDataFactory()
Get the data factory.
|
SourceData.Handler |
getSourceDataHandler()
Get the sourceDataHandler.
|
boolean |
isAtEos()
Is this stream at eos (but perhaps resettable)
|
boolean |
isBlocked()
Is a read blocked waiting for buffer.
|
boolean |
isClosed()
Is this stream closed.
|
boolean |
isDisallowRowSeparatorwithinQuotes() |
boolean |
isStartOfMessage()
Return true if the current payload is the start of a message.
|
java.lang.String |
locationDescription()
Get locationDescription of current SourceData.
|
void |
mark(int readlimit) |
boolean |
markSupported() |
BuffersInputStream.Line |
newLine() |
int |
peek() |
int |
peek(int n) |
protected SourceData |
peekBuffer() |
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] b,
int offset,
int len) |
void |
reset() |
boolean |
resetEos()
Reset eos if possible (because at record end).
|
void |
sendEndOfMessage()
Send message to indicate end of multi-part message.
|
void |
sendEOS()
Send final eos to stream.
|
void |
setBufferHook(java.util.function.LongConsumer getBufferHook) |
void |
setDataSourceHandler(RowInserter inserter)
Creates a SourceDataHandler that just calls
SourceData.updateLocation(RowInserter) . |
void |
setDataSourceHandler(SourceData.Handler sourceDataHandler)
Sets the sourceDataHandler
|
void |
setDisallowRowSeparatorwithinQuotes(boolean disallowRowSeparatorwithinQuotes) |
void |
setQuoteCharacters(byte[] quoteCharacter)
Sets the quote character for quote sensitive searches.
|
int |
skip(int n) |
void |
skipCurrentMessage()
Skip to the start of a message.
|
void |
startRecording(ByteRecorder byteRecorder)
Start recording bytes into the indicated byte recorder.
|
long |
unblockedTime() |
boolean |
waitABitTillBlockedOrClosed(long maxWaitTime)
Wait for blocked read or close.
|
boolean |
waitForBuffer()
Wait for buffer to be available for reading.
|
boolean |
waitForBuffer(long maxTime)
Wait for buffer to be available for reading.
|
void |
waitUntilAllConsumed()
Wait for all buffers to be consumed.
|
protected static final java.util.logging.Logger tracer
protected static final LogLevel logLevel
protected static final java.nio.charset.Charset utf8
public BuffersInputStream()
public BuffersInputStream(SourceDataFactory<?> sourceDataFactory)
public SourceDataFactory<?> getSourceDataFactory()
public <T extends SourceData> BuffersInputStream.Connection<T> getConnection()
public void startRecording(ByteRecorder byteRecorder)
byteRecorder
- The recorder to hold the bytes.public boolean isStartOfMessage()
public long getPayloadCount()
public byte[] getCurrentPayload(int maxBytes)
maxBytes
- The maximum number of bytes to retrieve.public void addBuffer(SourceWorkUnit<SourceData> buf)
buf
- SourceData to queuepublic boolean waitForBuffer()
public boolean waitForBuffer(long maxTime)
maxTime
- maximum time to wait.public long unblockedTime()
public boolean isBlocked()
public boolean waitABitTillBlockedOrClosed(long maxWaitTime)
maxWaitTime
- milliseconds to waitpublic void setQuoteCharacters(byte[] quoteCharacter)
quoteCharacter
- quotation markpublic boolean isDisallowRowSeparatorwithinQuotes()
public void setDisallowRowSeparatorwithinQuotes(boolean disallowRowSeparatorwithinQuotes)
public SourceData.Handler getSourceDataHandler()
public void setDataSourceHandler(SourceData.Handler sourceDataHandler)
sourceDataHandler
- SourceDataHandler to setpublic void setBufferHook(java.util.function.LongConsumer getBufferHook)
public void setDataSourceHandler(RowInserter inserter)
SourceData.updateLocation(RowInserter)
.inserter
- RowInserter to updatepublic byte[] getQuoteCharacters()
public long getQuoteCount()
public int available() throws java.io.IOException
InputStream.available()
available
in class java.io.InputStream
java.io.IOException
public void mark(int readlimit)
mark
in class java.io.InputStream
public void reset()
reset
in class java.io.InputStream
public boolean markSupported()
markSupported
in class java.io.InputStream
public long getPosition()
public int buffersAvailable()
public void waitUntilAllConsumed()
public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int peek() throws java.io.IOException
java.io.IOException
public int peek(int n) throws java.io.IOException
java.io.IOException
public int read(byte[] b) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int read(byte[] b, int offset, int len) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int skip(int n) throws java.io.IOException
java.io.IOException
public BuffersInputStream.Line newLine()
public boolean getLine(BuffersInputStream.Line out, byte[] delimiter) throws java.io.IOException
out
- Line to returndelimiter
- end of line delimiter or null for full messagejava.io.IOException
public boolean isClosed()
public boolean isAtEos()
public void enableEosAtMessageEnd()
public boolean resetEos()
public java.lang.String locationDescription()
public void skipCurrentMessage() throws java.io.IOException
java.io.IOException
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
public void sendEOS()
protected SourceData peekBuffer()
public void sendEndOfMessage()
public void addRowtimeBound(java.sql.Timestamp t)
t
- new rowtime boundCopyright (C) 2003-2021 SQLstream, Inc.