Package org.postgresql.copy
Class PGCopyInputStream
java.lang.Object
java.io.InputStream
org.postgresql.copy.PGCopyInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable,CopyOperation,CopyOut
InputStream for reading from a PostgreSQL COPY TO STDOUT operation.
-
Constructor Summary
ConstructorsConstructorDescriptionUse given CopyOut operation for reading.PGCopyInputStream(PGConnection connection, String sql) Uses given connection for specified COPY TO STDOUT operation. -
Method Summary
Modifier and TypeMethodDescriptionintvoidCancels this copy operation, discarding any exchanged data.voidclose()intintgetFieldFormat(int field) intlongAfter successful end of copy, returns the number of database records handled in that operation.booleanisActive()intread()intread(byte[] buf) intread(byte[] buf, int off, int siz) byte @Nullable []Blocks wait for a row of data to be received from server on an active copy operation.byte @Nullable []readFromCopy(boolean block) Wait for a row of data to be received from server on an active copy operation.Methods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Constructor Details
-
PGCopyInputStream
Uses given connection for specified COPY TO STDOUT operation.- Parameters:
connection- database connection to use for copying (protocol version 3 required)sql- COPY TO STDOUT statement- Throws:
SQLException- if initializing the operation fails
-
PGCopyInputStream
Use given CopyOut operation for reading.- Parameters:
op- COPY TO STDOUT operation
-
-
Method Details
-
available
- Overrides:
availablein classInputStream- Throws:
IOException
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
readFromCopy
Description copied from interface:CopyOutBlocks wait for a row of data to be received from server on an active copy operation.- Specified by:
readFromCopyin interfaceCopyOut- Returns:
- byte array received from server, null if server complete copy operation
- Throws:
SQLException- if something goes wrong for example socket timeout
-
readFromCopy
Description copied from interface:CopyOutWait for a row of data to be received from server on an active copy operation.- Specified by:
readFromCopyin interfaceCopyOut- Parameters:
block-trueif need wait data from server otherwisefalseand will read pending message from server- Returns:
- byte array received from server, if pending message from server absent and use no blocking mode return null
- Throws:
SQLException- if something goes wrong for example socket timeout
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
cancelCopy
Description copied from interface:CopyOperationCancels this copy operation, discarding any exchanged data.- Specified by:
cancelCopyin interfaceCopyOperation- Throws:
SQLException- if cancelling fails
-
getFormat
public int getFormat()- Specified by:
getFormatin interfaceCopyOperation- Returns:
- overall format of each row: 0 = textual, 1 = binary
-
getFieldFormat
public int getFieldFormat(int field) - Specified by:
getFieldFormatin interfaceCopyOperation- Parameters:
field- number of field (0..fieldCount()-1)- Returns:
- format of requested field: 0 = textual, 1 = binary
-
getFieldCount
public int getFieldCount()- Specified by:
getFieldCountin interfaceCopyOperation- Returns:
- number of fields in each row for this operation
-
isActive
public boolean isActive()- Specified by:
isActivein interfaceCopyOperation- Returns:
- is connection reserved for this Copy operation?
-
getHandledRowCount
public long getHandledRowCount()Description copied from interface:CopyOperationAfter successful end of copy, returns the number of database records handled in that operation. Only implemented in PostgreSQL server version 8.2 and up. Otherwise, returns -1.- Specified by:
getHandledRowCountin interfaceCopyOperation- Returns:
- number of handled rows or -1
-