|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.postgresql.core.PGStream
public class PGStream
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 PGStream are not threadsafe; the caller must ensure that only one thread at a time is accessing a particular PGStream instance.
| Constructor Summary | |
|---|---|
PGStream(SocketFactory socketFactory,
HostSpec hostSpec)
Deprecated. use PGStream(SocketFactory, org.postgresql.util.HostSpec, int) |
|
PGStream(SocketFactory socketFactory,
HostSpec hostSpec,
int timeout)
Constructor: Connect to the PostgreSQL back end and return a stream connection. |
|
| Method Summary | |
|---|---|
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()
|
SocketFactory |
getSocketFactory()
|
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)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public PGStream(SocketFactory socketFactory,
HostSpec hostSpec,
int timeout)
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 set
IOException - if an IOException occurs below it.
public PGStream(SocketFactory socketFactory,
HostSpec hostSpec)
throws IOException
PGStream(SocketFactory, org.postgresql.util.HostSpec, int)
socketFactory - socket factoryhostSpec - the host and port to connect to
IOException - if an IOException occurs below it.| Method Detail |
|---|
public HostSpec getHostSpec()
public Socket getSocket()
public SocketFactory getSocketFactory()
public boolean hasMessagePending()
throws IOException
IOException - if something wrong happens
public void changeSocket(Socket socket)
throws IOException
socket - the new socket to change to
IOException - if something goes wrongpublic Encoding getEncoding()
public void setEncoding(Encoding encoding)
throws IOException
encoding - the new encoding to use
IOException - if something goes wrong
public 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 sent
IOException - if an I/O error occurs
public void SendInteger4(int val)
throws IOException
val - the integer to be sent
IOException - if an I/O error occurs
public void SendInteger2(int val)
throws IOException
val - the integer to be sent
IOException - if an I/O error occurs or val cannot be encoded in 2 bytes
public void Send(byte[] buf)
throws IOException
buf - The array of bytes to be sent
IOException - if an I/O error occurs
public 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 sent
IOException - if an I/O error occurs
public 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 sent
IOException - if an I/O error occurs
public int PeekChar()
throws IOException
IOException - if an I/O Error occurs
public int ReceiveChar()
throws IOException
IOException - if an I/O Error occurs
public int ReceiveInteger4()
throws IOException
IOException - if an I/O error occurs
public int ReceiveInteger2()
throws IOException
IOException - if an I/O error occurs
public String ReceiveString(int len)
throws IOException
len - the length of the string to receive, in bytes.
IOException - if something wrong happens
public String ReceiveString()
throws IOException
IOException - if an I/O error occurs, or end of file
public byte[][] ReceiveTupleV3()
throws IOException,
OutOfMemoryError
IOException - if a data I/O error occurs
OutOfMemoryError
public byte[][] ReceiveTupleV2(int nf,
boolean bin)
throws IOException,
OutOfMemoryError
nf - the number of fields expectedbin - true if the tuple is a binary tuple
IOException - if a data I/O error occurs
OutOfMemoryError
public byte[] Receive(int siz)
throws IOException
siz - number of bytes to read
IOException - if a data I/O error occurs
public void Receive(byte[] buf,
int off,
int siz)
throws IOException
buf - buffer to store resultoff - offset in buffersiz - number of bytes to read
IOException - if a data I/O error occurs
public 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 copy
IOException - if a data I/O error occurs
public void flush()
throws IOException
IOException - if an I/O error occurs
public void ReceiveEOF()
throws SQLException,
IOException
IOException - if an I/O error occurs
SQLException - if we get something other than an EOF
public void close()
throws IOException
IOException - if an I/O Error occurs
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||