Package org.postgresql.copy
Class PGCopyOutputStream
java.lang.Object
java.io.OutputStream
org.postgresql.copy.PGCopyOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,CopyIn,CopyOperation
OutputStream for buffered input into a PostgreSQL COPY FROM STDIN operation.
-
Constructor Summary
ConstructorsConstructorDescriptionUse given CopyIn operation for writing.PGCopyOutputStream(CopyIn op, int bufferSize) Use given CopyIn operation for writing.PGCopyOutputStream(PGConnection connection, String sql) Uses given connection for specified COPY FROM STDIN operation.PGCopyOutputStream(PGConnection connection, String sql, int bufferSize) Uses given connection for specified COPY FROM STDIN operation. -
Method Summary
Modifier and TypeMethodDescriptionvoidCancels this copy operation, discarding any exchanged data.voidclose()longendCopy()Finishes copy operation successfully.voidflush()voidForce any buffered output to be sent over the network to the backend.intintgetFieldFormat(int field) intlongAfter successful end of copy, returns the number of database records handled in that operation.booleanisActive()voidwrite(byte[] buf) voidwrite(byte[] buf, int off, int siz) voidwrite(int b) voidwriteToCopy(byte[] buf, int off, int siz) Writes specified part of given byte array to an open and writable copy operation.voidwriteToCopy(ByteStreamWriter from) Writes a ByteStreamWriter to an open and writable copy operation.Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
PGCopyOutputStream
Uses given connection for specified COPY FROM STDIN operation.- Parameters:
connection- database connection to use for copying (protocol version 3 required)sql- COPY FROM STDIN statement- Throws:
SQLException- if initializing the operation fails
-
PGCopyOutputStream
Uses given connection for specified COPY FROM STDIN operation.- Parameters:
connection- database connection to use for copying (protocol version 3 required)sql- COPY FROM STDIN statementbufferSize- try to send this many bytes at a time- Throws:
SQLException- if initializing the operation fails
-
PGCopyOutputStream
Use given CopyIn operation for writing.- Parameters:
op- COPY FROM STDIN operation
-
PGCopyOutputStream
Use given CopyIn operation for writing.- Parameters:
op- COPY FROM STDIN operationbufferSize- try to send this many bytes at a time
-
-
Method Details
-
write
- Specified by:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
writeToCopy
Description copied from interface:CopyInWrites specified part of given byte array to an open and writable copy operation.- Specified by:
writeToCopyin interfaceCopyIn- Parameters:
buf- array of bytes to writeoff- offset of first byte to write (normally zero)siz- number of bytes to write (normally buf.length)- Throws:
SQLException- if the operation fails
-
writeToCopy
Description copied from interface:CopyInWrites a ByteStreamWriter to an open and writable copy operation.- Specified by:
writeToCopyin interfaceCopyIn- Parameters:
from- the source of bytes, e.g. a ByteBufferByteStreamWriter- Throws:
SQLException- if the operation 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
-
cancelCopy
Description copied from interface:CopyOperationCancels this copy operation, discarding any exchanged data.- Specified by:
cancelCopyin interfaceCopyOperation- Throws:
SQLException- if cancelling fails
-
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?
-
flushCopy
Description copied from interface:CopyInForce any buffered output to be sent over the network to the backend. In general this is a useless operation as it will get pushed over in due time or when endCopy is called. Some specific modified server versions (Truviso) want this data sooner. If you are unsure if you need to use this method, don't.- Specified by:
flushCopyin interfaceCopyIn- Throws:
SQLException- if the operation fails.
-
endCopy
Description copied from interface:CopyInFinishes copy operation successfully.- Specified by:
endCopyin interfaceCopyIn- Returns:
- number of updated rows for server 8.2 or newer (see getHandledRowCount())
- Throws:
SQLException- if the operation fails.
-
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
-