public class RedshiftStream extends Object implements Closeable, Flushable
Wrapper around the raw connection to the server that implements some basic primitives (reading/writing formatted data, doing string encoding, etc).
In general, instances of RedshiftStream are not threadsafe; the caller must ensure that only one thread at a time is accessing a particular RedshiftStream instance.
| Constructor and Description |
|---|
RedshiftStream(SocketFactory socketFactory,
HostSpec hostSpec,
int timeout,
RedshiftLogger logger,
boolean disableCompressionForSSL,
Properties info)
Constructor: Connect to the Redshift back end and return a stream connection.
|
RedshiftStream(SocketFactory socketFactory,
HostSpec hostSpec,
RedshiftLogger logger,
Properties info)
|
| Modifier and Type | Method and Description |
|---|---|
void |
changeSocket(Socket socket,
Boolean disableCompressionForSSL,
Properties info)
Switch this stream to using a new socket.
|
void |
changeStream(Boolean disableCompressionForSSL,
Properties info) |
void |
clearResultBufferCount()
Method to clear count of byte buffer.
|
void |
close()
Closes the connection.
|
void |
flush()
Flush any pending output to the backend.
|
long |
getBytesFromStream() |
Encoding |
getEncoding() |
Writer |
getEncodingWriter()
Get a Writer instance that encodes directly onto the underlying stream.
|
HostSpec |
getHostSpec() |
RedshiftLogger |
getLogger() |
int |
getNetworkTimeout() |
Socket |
getSocket() |
SocketFactory |
getSocketFactory() |
boolean |
hasMessagePending()
Check for pending backend messages without blocking.
|
boolean |
isClosed() |
int |
peekChar()
Receives a single character from the backend, without advancing the current protocol stream
position.
|
void |
receive(byte[] buf,
int off,
int siz)
Reads in a given number of bytes from the backend.
|
byte[] |
receive(int siz)
Reads in a given number of bytes from the backend.
|
int |
receiveChar()
Receives a single character from the backend.
|
void |
receiveEOF()
Consume an expected EOF from the backend.
|
EncodingPredictor.DecodeResult |
receiveErrorString(int len)
Receives a fixed-size string from the backend, and tries to avoid "UTF-8 decode failed"
errors.
|
int |
receiveInteger2()
Receives a two byte integer from the backend.
|
int |
receiveInteger4()
Receives a four byte integer from the backend.
|
String |
receiveString()
Receives a null-terminated string from the backend.
|
String |
receiveString(int len)
Receives a fixed-size string from the backend.
|
Tuple |
receiveTupleV3()
Read a tuple from the back end.
|
void |
send(byte[] buf)
Send an array of bytes to the backend.
|
void |
send(byte[] buf,
int siz)
Send a fixed-size array of bytes to the backend.
|
void |
send(byte[] buf,
int off,
int siz)
Send a fixed-size array of bytes to the backend.
|
void |
send(ByteStreamWriter writer)
Send a fixed-size array of bytes to the backend.
|
void |
sendChar(int val)
Sends a single character to the back end.
|
void |
sendInteger2(int val)
Sends a 2-byte integer (short) to the back end.
|
void |
sendInteger4(int val)
Sends a 4-byte integer to the back end.
|
void |
sendStream(InputStream inStream,
int remaining)
Copy data from an input stream to the connection.
|
void |
setEncoding(Encoding encoding)
Change the encoding used by this connection.
|
void |
setMaxResultBuffer(String value)
Method to set MaxResultBuffer inside RedshiftStream.
|
void |
setMinStreamAvailableCheckDelay(int delay) |
void |
setNetworkTimeout(int milliseconds) |
void |
skip(int size) |
public RedshiftStream(SocketFactory socketFactory, HostSpec hostSpec, int timeout, RedshiftLogger logger, boolean disableCompressionForSSL, Properties info) throws IOException
socketFactory - socket factory to use when creating socketshostSpec - the host and port to connect totimeout - timeout in milliseconds, or 0 if no timeout setlogger - the logger to log the entry for debugging.IOException - if an IOException occurs below it.@Deprecated public RedshiftStream(SocketFactory socketFactory, HostSpec hostSpec, RedshiftLogger logger, Properties info) throws IOException
RedshiftStream(SocketFactory, com.amazon.redshift.util.HostSpec, int, RedshiftLogger, boolean, Properties)socketFactory - socket factoryhostSpec - the host and port to connect tologger - the logger to log the entry for debugging.IOException - if an IOException occurs below it.public RedshiftLogger getLogger()
public HostSpec getHostSpec()
public Socket getSocket()
public SocketFactory getSocketFactory()
public boolean hasMessagePending()
throws IOException
IOException - if something wrong happenspublic void setMinStreamAvailableCheckDelay(int delay)
public void changeSocket(Socket socket, Boolean disableCompressionForSSL, Properties info) throws IOException
socket - the new socket to change toIOException - if something goes wrongpublic void changeStream(Boolean disableCompressionForSSL, Properties info) throws IOException
IOExceptionpublic long getBytesFromStream()
public Encoding getEncoding()
public void setEncoding(Encoding encoding) throws IOException
encoding - the new encoding to useIOException - if something goes wrongpublic Writer getEncodingWriter() throws IOException
Get a Writer instance that encodes directly onto the underlying stream.
The returned Writer should not be closed, as it's a shared object. Writer.flush needs to be
called when switching between use of the Writer and use of the RedshiftStream write methods, but it
won't actually flush output all the way out -- call flush() to actually ensure all
output has been pushed to the server.
IOException - if something goes wrong.public void sendChar(int val)
throws IOException
val - the character to be sentIOException - if an I/O error occurspublic void sendInteger4(int val)
throws IOException
val - the integer to be sentIOException - if an I/O error occurspublic void sendInteger2(int val)
throws IOException
val - the integer to be sentIOException - if an I/O error occurs or val cannot be encoded in 2 bytespublic void send(byte[] buf)
throws IOException
buf - The array of bytes to be sentIOException - if an I/O error occurspublic void send(byte[] buf,
int siz)
throws IOException
buf.length < siz, pad with zeros.
If buf.lengh > siz, truncate the array.buf - the array of bytes to be sentsiz - the number of bytes to be sentIOException - if an I/O error occurspublic void send(byte[] buf,
int off,
int siz)
throws IOException
length < siz, pad with zeros. If
length > siz, truncate the array.buf - the array of bytes to be sentoff - offset in the array to start sending fromsiz - the number of bytes to be sentIOException - if an I/O error occurspublic void send(ByteStreamWriter writer) throws IOException
length < siz, pad with zeros. If
length > siz, truncate the array.writer - the stream writer to invoke to send the bytesIOException - if an I/O error occurspublic int peekChar()
throws IOException
IOException - if an I/O Error occurspublic int receiveChar()
throws IOException
IOException - if an I/O Error occurspublic int receiveInteger4()
throws IOException
IOException - if an I/O error occurspublic int receiveInteger2()
throws IOException
IOException - if an I/O error occurspublic String receiveString(int len) throws IOException
len - the length of the string to receive, in bytes.IOException - if something wrong happenspublic EncodingPredictor.DecodeResult receiveErrorString(int len) throws IOException
len - the length of the string to receive, in bytes.IOException - if something wrong happenspublic String receiveString() throws IOException
IOException - if an I/O error occurs, or end of filepublic Tuple receiveTupleV3() throws IOException, OutOfMemoryError, SQLException
IOException - if a data I/O error occursSQLException - if read more bytes than set maxResultBufferOutOfMemoryErrorpublic byte[] receive(int siz)
throws IOException
siz - number of bytes to readIOException - if a data I/O error occurspublic void receive(byte[] buf,
int off,
int siz)
throws IOException
buf - buffer to store resultoff - offset in buffersiz - number of bytes to readIOException - if a data I/O error occurspublic void skip(int size)
throws IOException
IOExceptionpublic void sendStream(InputStream inStream, int remaining) throws IOException
inStream - the stream to read data fromremaining - the number of bytes to copyIOException - if a data I/O error occurspublic void flush()
throws IOException
flush in interface FlushableIOException - if an I/O error occurspublic void receiveEOF()
throws SQLException,
IOException
IOException - if an I/O error occursSQLException - if we get something other than an EOFpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOException - if an I/O Error occurspublic void setNetworkTimeout(int milliseconds)
throws IOException
IOExceptionpublic int getNetworkTimeout()
throws IOException
IOExceptionpublic void setMaxResultBuffer(String value) throws RedshiftException
value - value of new max result buffer as string (cause we can expect % or chars to use
multiplier)RedshiftException - exception returned when occurred parsing problem.public void clearResultBufferCount()
public boolean isClosed()
Copyright © 2024 Amazon.com Inc.. All rights reserved.