パッケージ org.postgresql.core
クラス PGStream
java.lang.Object
org.postgresql.core.PGStream
- すべての実装されたインタフェース:
Closeable
,Flushable
,AutoCloseable
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.
-
コンストラクタの概要
コンストラクタコンストラクタ説明PGStream
(SocketFactory socketFactory, HostSpec hostSpec) 推奨されていません。PGStream
(SocketFactory socketFactory, HostSpec hostSpec, int timeout) Constructor: Connect to the PostgreSQL back end and return a stream connection. -
メソッドの概要
修飾子とタイプメソッド説明void
changeSocket
(Socket socket) Switch this stream to using a new socket.void
Clear value of max row size noticed so far.void
Clear count of byte buffer.void
close()
Closes the connection.void
flush()
Flush any pending output to the backend.Get a Writer instance that encodes directly onto the underlying stream.long
Get MaxResultBuffer from PGStream.int
Get actual max row size noticed so far.int
boolean
Check for pending backend messages without blocking.boolean
hasMessagePending
(int n, int milliSec, boolean avoidWait) Check for pending backend messages without blocking.boolean
isClosed()
boolean
isCM()
boolean
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.void
receive
(byte[] buf, int off, int siz, boolean fastmode) Reads in a given number of bytes from the backend.byte[]
receive
(int siz) Reads in a given number of bytes from the backend.Receives a null-terminated string from the backend and attempts to decode to acanonical
String
.Receives a null-terminated string from the backend and attempts to decode to acanonical
String
.int
Receives a single character from the backend.void
Consume an expected EOF from the backend.receiveErrorString
(int len) Receives a fixed-size string from the backend, and tries to avoid "UTF-8 decode failed" errors.int
Receives a two byte integer from the backend.int
receiveInteger2
(boolean fastmode) Receives a two byte integer from the backend.int
Receives a four byte integer from the backend.int
receiveInteger4
(boolean fastmode) Receives a four byte integer from the backend.Receives a null-terminated string from the backend.receiveString
(int len) Receives a fixed-size string from the backend.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
setCM
(boolean isCM) void
setCMStream
(PGStream cmStream) void
setEncoding
(Encoding encoding) Change the encoding used by this connection.void
setMaxResultBuffer
(@Nullable String value) Method to set MaxResultBuffer inside PGStream.void
setMaxRowSizeBytes
(int rowSizeBytes) The idea behind this method is to keep in maxRowSize the size of biggest read data row.void
setMinStreamAvailableCheckDelay
(int delay) void
setNetworkTimeout
(int milliseconds) void
setSecContext
(GSSContext secContext) void
setWaitMilliSec
(int waitMilliSec) void
skip
(int size) boolean
viaCM()
-
コンストラクタの詳細
-
PGStream
Constructor: Connect to the PostgreSQL back end and return a stream connection.- パラメータ:
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.
-
PGStream
- 例外:
IOException
-
PGStream
推奨されていません。Constructor: Connect to the PostgreSQL back end and return a stream connection.- パラメータ:
socketFactory
- socket factoryhostSpec
- the host and port to connect to- 例外:
IOException
- if an IOException occurs below it.
-
-
メソッドの詳細
-
isGssEncrypted
public boolean isGssEncrypted() -
setSecContext
-
viaCM
public boolean viaCM() -
getHostSpec
-
getSocket
-
getSocketFactory
-
hasMessagePending
Check for pending backend messages without blocking. Might return false when there actually are messages waiting, depending on the characteristics of the underlying socket. This is used to detect asynchronous notifies from the backend, when available.- 戻り値:
- true if there is a pending backend message
- 例外:
IOException
- if something wrong happens
-
hasMessagePending
Check for pending backend messages without blocking. Might return false when there actually are messages waiting, depending on the characteristics of the underlying socket. This is used to detect asynchronous notifies from the backend, when available.- パラメータ:
n
- required bytesmilliSec
- timeout milli secondsavoidWait
- not adding minStreamAvailableCheckDelay- 戻り値:
- true if there is a pending backend message
- 例外:
IOException
- if something wrong happens
-
setMinStreamAvailableCheckDelay
public void setMinStreamAvailableCheckDelay(int delay) -
setWaitMilliSec
public void setWaitMilliSec(int waitMilliSec) -
setCM
public void setCM(boolean isCM) -
isCM
public boolean isCM() -
changeSocket
Switch this stream to using a new socket. Any existing socket is not closed; it's assumed that we are changing to a new socket that delegates to the original socket (e.g. SSL).- パラメータ:
socket
- the new socket to change to- 例外:
IOException
- if something goes wrong
-
getEncoding
-
setEncoding
Change the encoding used by this connection.- パラメータ:
encoding
- the new encoding to use- 例外:
IOException
- if something goes wrong
-
getEncodingWriter
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 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.- 戻り値:
- the shared Writer instance
- 例外:
IOException
- if something goes wrong.
-
sendChar
Sends a single character to the back end.- パラメータ:
val
- the character to be sent- 例外:
IOException
- if an I/O error occurs
-
sendInteger4
Sends a 4-byte integer to the back end.- パラメータ:
val
- the integer to be sent- 例外:
IOException
- if an I/O error occurs
-
sendInteger2
Sends a 2-byte integer (short) to the back end.- パラメータ:
val
- the integer to be sent- 例外:
IOException
- if an I/O error occurs orval
cannot be encoded in 2 bytes
-
send
Send an array of bytes to the backend.- パラメータ:
buf
- The array of bytes to be sent- 例外:
IOException
- if an I/O error occurs
-
send
Send a fixed-size array of bytes to the backend. Ifbuf.length < siz
, pad with zeros. Ifbuf.length > 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
-
send
Send a fixed-size array of bytes to the backend. Iflength < siz
, pad with zeros. Iflength > 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
-
send
Send a fixed-size array of bytes to the backend. Iflength < siz
, pad with zeros. Iflength > siz
, truncate the array.- パラメータ:
writer
- the stream writer to invoke to send the bytes- 例外:
IOException
- if an I/O error occurs
-
peekChar
Receives a single character from the backend, without advancing the current protocol stream position.- 戻り値:
- the character received
- 例外:
IOException
- if an I/O Error occurs
-
receiveChar
Receives a single character from the backend.- 戻り値:
- the character received
- 例外:
IOException
- if an I/O Error occurs
-
receiveInteger4
Receives a four byte integer from the backend.- 戻り値:
- the integer received from the backend
- 例外:
IOException
- if an I/O error occurs
-
receiveInteger4
Receives a four byte integer from the backend.- パラメータ:
fastmode
- skip monitoring Connection Manager- 戻り値:
- the integer received from the backend
- 例外:
IOException
- if an I/O error occurs
-
receiveInteger2
Receives a two byte integer from the backend.- 戻り値:
- the integer received from the backend
- 例外:
IOException
- if an I/O error occurs
-
receiveInteger2
Receives a two byte integer from the backend.- パラメータ:
fastmode
- skip monitoring Connection Manager- 戻り値:
- the integer received from the backend
- 例外:
IOException
- if an I/O error occurs
-
receiveString
Receives a fixed-size string from the backend.- パラメータ:
len
- the length of the string to receive, in bytes.- 戻り値:
- the decoded string
- 例外:
IOException
- if something wrong happens
-
receiveErrorString
Receives a fixed-size string from the backend, and tries to avoid "UTF-8 decode failed" errors.- パラメータ:
len
- the length of the string to receive, in bytes.- 戻り値:
- the decoded string
- 例外:
IOException
- if something wrong happens
-
receiveString
Receives a null-terminated string from the backend. If we don't see a null, then we assume something has gone wrong.- 戻り値:
- string from back end
- 例外:
IOException
- if an I/O error occurs, or end of file
-
receiveCanonicalString
Receives a null-terminated string from the backend and attempts to decode to acanonical
String
. If we don't see a null, then we assume something has gone wrong.- 戻り値:
- string from back end
- 例外:
IOException
- if an I/O error occurs, or end of file- 関連項目:
-
receiveCanonicalStringIfPresent
Receives a null-terminated string from the backend and attempts to decode to acanonical
String
. If we don't see a null, then we assume something has gone wrong.- 戻り値:
- string from back end
- 例外:
IOException
- if an I/O error occurs, or end of file- 関連項目:
-
receiveTupleV3
Read a tuple from the back end. A tuple is a two dimensional array of bytes. This variant reads the V3 protocol's tuple representation.- 戻り値:
- tuple from the back end
- 例外:
IOException
- if a data I/O error occursSQLException
- if read more bytes than set maxResultBufferOutOfMemoryError
-
receive
Reads in a given number of bytes from the backend.- パラメータ:
siz
- number of bytes to read- 戻り値:
- array of bytes received
- 例外:
IOException
- if a data I/O error occurs
-
receive
Reads in a given number of bytes from the backend.- パラメータ:
buf
- buffer to store resultoff
- offset in buffersiz
- number of bytes to read- 例外:
IOException
- if a data I/O error occurs
-
receive
Reads in a given number of bytes from the backend.- パラメータ:
buf
- buffer to store resultoff
- offset in buffersiz
- number of bytes to readfastmode
- skip monitoring Connection Manager- 例外:
IOException
- if a data I/O error occurs
-
skip
- 例外:
IOException
-
sendStream
Copy data from an input stream to the connection.- パラメータ:
inStream
- the stream to read data fromremaining
- the number of bytes to copy- 例外:
IOException
- if a data I/O error occurs
-
flush
Flush any pending output to the backend.- 定義:
flush
インタフェース内Flushable
- 例外:
IOException
- if an I/O error occurs
-
receiveEOF
Consume an expected EOF from the backend.- 例外:
IOException
- if an I/O error occursSQLException
- if we get something other than an EOF
-
close
Closes the connection.- 定義:
close
インタフェース内AutoCloseable
- 定義:
close
インタフェース内Closeable
- 例外:
IOException
- if an I/O Error occurs
-
setNetworkTimeout
- 例外:
IOException
-
getNetworkTimeout
- 例外:
IOException
-
setMaxResultBuffer
Method to set MaxResultBuffer inside PGStream.- パラメータ:
value
- value of new max result buffer as string (cause we can expect % or chars to use multiplier)- 例外:
PSQLException
- exception returned when occurred parsing problem.
-
getMaxResultBuffer
public long getMaxResultBuffer()Get MaxResultBuffer from PGStream.- 戻り値:
- size of MaxResultBuffer
-
setMaxRowSizeBytes
public void setMaxRowSizeBytes(int rowSizeBytes) The idea behind this method is to keep in maxRowSize the size of biggest read data row. As there may be many data rows send after each other for a query, then value in maxRowSize would contain value noticed so far, because next data rows and their sizes are not read for that moment. We want it increasing, because the size of the biggest among data rows will be used during computing new adaptive fetch size for the query.- パラメータ:
rowSizeBytes
- new value to be set as maxRowSizeBytes
-
getMaxRowSizeBytes
public int getMaxRowSizeBytes()Get actual max row size noticed so far.- 戻り値:
- value of max row size
-
clearMaxRowSizeBytes
public void clearMaxRowSizeBytes()Clear value of max row size noticed so far. -
clearResultBufferCount
public void clearResultBufferCount()Clear count of byte buffer. -
isClosed
public boolean isClosed() -
setCMStream
-
getCMStream
-
PGStream(SocketFactory, org.postgresql.util.HostSpec, int)