public class PGStream
extends java.lang.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(java.lang.String host,
int port)
Constructor: Connect to the PostgreSQL back end and return
a stream connection.
|
| Modifier and Type | Method and Description |
|---|---|
void |
changeSocket(java.net.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() |
java.io.Writer |
getEncodingWriter()
Get a Writer instance that encodes directly onto the underlying stream.
|
java.lang.String |
getHost() |
int |
getPort() |
java.net.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
|
java.lang.String |
ReceiveString()
Receives a null-terminated string from the backend.
|
java.lang.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(java.io.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(java.lang.String host,
int port)
throws java.io.IOException
host - the hostname to connect toport - the port number that the postmaster is sitting onjava.io.IOException - if an IOException occurs below it.public java.lang.String getHost()
public int getPort()
public java.net.Socket getSocket()
public boolean hasMessagePending()
throws java.io.IOException
java.io.IOExceptionpublic void changeSocket(java.net.Socket socket)
throws java.io.IOException
socket - the new socket to change tojava.io.IOException - if something goes wrongpublic Encoding getEncoding()
public void setEncoding(Encoding encoding) throws java.io.IOException
encoding - the new encoding to usejava.io.IOException - if something goes wrongpublic java.io.Writer getEncodingWriter()
throws java.io.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.
java.io.IOException - if something goes wrong.public void SendChar(int val)
throws java.io.IOException
val - the character to be sentjava.io.IOException - if an I/O error occurspublic void SendInteger4(int val)
throws java.io.IOException
val - the integer to be sentjava.io.IOException - if an I/O error occurspublic void SendInteger2(int val)
throws java.io.IOException
val - the integer to be sentjava.io.IOException - if an I/O error occurs or val cannot be encoded in 2 bytespublic void Send(byte[] buf)
throws java.io.IOException
buf - The array of bytes to be sentjava.io.IOException - if an I/O error occurspublic void Send(byte[] buf,
int siz)
throws java.io.IOException
buf - the array of bytes to be sentsiz - the number of bytes to be sentjava.io.IOException - if an I/O error occurspublic void Send(byte[] buf,
int off,
int siz)
throws java.io.IOException
buf - the array of bytes to be sentoff - offset in the array to start sending fromsiz - the number of bytes to be sentjava.io.IOException - if an I/O error occurspublic int PeekChar()
throws java.io.IOException
java.io.IOException - if an I/O Error occurspublic int ReceiveChar()
throws java.io.IOException
java.io.IOException - if an I/O Error occurspublic int ReceiveInteger4()
throws java.io.IOException
java.io.IOException - if an I/O error occurspublic int ReceiveInteger2()
throws java.io.IOException
java.io.IOException - if an I/O error occurspublic java.lang.String ReceiveString(int len)
throws java.io.IOException
len - the length of the string to receive, in bytes.java.io.IOExceptionpublic java.lang.String ReceiveString()
throws java.io.IOException
java.io.IOException - if an I/O error occurs, or end of filepublic byte[][] ReceiveTupleV3()
throws java.io.IOException,
java.lang.OutOfMemoryError
java.io.IOException - if a data I/O error occursjava.lang.OutOfMemoryErrorpublic byte[][] ReceiveTupleV2(int nf,
boolean bin)
throws java.io.IOException,
java.lang.OutOfMemoryError
nf - the number of fields expectedbin - true if the tuple is a binary tuplejava.io.IOException - if a data I/O error occursjava.lang.OutOfMemoryErrorpublic byte[] Receive(int siz)
throws java.io.IOException
siz - number of bytes to readjava.io.IOException - if a data I/O error occurspublic void Receive(byte[] buf,
int off,
int siz)
throws java.io.IOException
buf - buffer to store resultoff - offset in buffersiz - number of bytes to readjava.io.IOException - if a data I/O error occurspublic void Skip(int size)
throws java.io.IOException
java.io.IOExceptionpublic void SendStream(java.io.InputStream inStream,
int remaining)
throws java.io.IOException
inStream - the stream to read data fromremaining - the number of bytes to copyjava.io.IOExceptionpublic void flush()
throws java.io.IOException
java.io.IOException - if an I/O error occurspublic void ReceiveEOF()
throws java.sql.SQLException,
java.io.IOException
java.sql.SQLException - if we get something other than an EOFjava.io.IOExceptionpublic void close()
throws java.io.IOException
java.io.IOException - if an I/O Error occurs