public class PGStream extends Object
In general, instances of PGStream are not threadsafe; the caller must ensure that only one thread at a time is accessing a particular PGStream instance.
Constructor and Description |
---|
PGStream(HostSpec hostSpec)
Deprecated.
|
PGStream(HostSpec hostSpec,
int timeout)
Constructor: Connect to the PostgreSQL back end and return
a stream connection.
|
Modifier and Type | Method and Description |
---|---|
void |
changeSocket(Socket socket)
Switch this stream to using a new socket.
|
void |
close()
Closes the connection
|
void |
flush()
Flush any pending output to the backend.
|
Encoding |
getEncoding() |
Writer |
getEncodingWriter()
Get a Writer instance that encodes directly onto the underlying stream.
|
HostSpec |
getHostSpec() |
Socket |
getSocket() |
boolean |
hasMessagePending()
Check for pending backend messages without blocking.
|
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
|
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.
|
byte[][] |
ReceiveTupleV2(int nf,
boolean bin)
Read a tuple from the back end.
|
byte[][] |
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 |
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 |
Skip(int size) |
public PGStream(HostSpec hostSpec, int timeout) throws IOException
hostSpec
- the host and port to connect totimeout
- timeout in milliseconds, or 0 if no timeout setIOException
- if an IOException occurs below it.public PGStream(HostSpec hostSpec) throws IOException
PGStream(org.postgresql.util.HostSpec, int)
hostSpec
- the host and port to connect toIOException
- if an IOException occurs below it.public HostSpec getHostSpec()
public Socket getSocket()
public boolean hasMessagePending() throws IOException
IOException
- if something wrong happenspublic void changeSocket(Socket socket) throws IOException
socket
- the new socket to change toIOException
- if something goes wrongpublic Encoding getEncoding()
public void setEncoding(Encoding encoding) throws IOException
encoding
- the new encoding to useIOException
- if something goes wrongpublic Writer getEncodingWriter() throws IOException
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 PGStream 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 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 String ReceiveString() throws IOException
IOException
- if an I/O error occurs, or end of filepublic byte[][] ReceiveTupleV3() throws IOException, OutOfMemoryError
IOException
- if a data I/O error occursOutOfMemoryError
public byte[][] ReceiveTupleV2(int nf, boolean bin) throws IOException, OutOfMemoryError
nf
- the number of fields expectedbin
- true if the tuple is a binary tupleIOException
- if a data I/O error occursOutOfMemoryError
public 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
IOException
public 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
IOException
- 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
IOException
- if an I/O Error occursCopyright © 2015 PostgreSQL Global Development Group. All rights reserved.