Top Description Fields Constructors Methods
org.postgresql.copy

public Class PGCopyOutputStream

extends OutputStream
implements CopyIn
Class Inheritance
All Implemented Interfaces
org.postgresql.copy.CopyIn, org.postgresql.copy.CopyOperation
Static Imports
org.postgresql.util.internal.Nullness.castNonNull

OutputStream for buffered input into a PostgreSQL COPY FROM STDIN operation.

Field Summary

Modifier and TypeField and Description
private int
private final byte[]
private @Nullable CopyIn
private final byte[]

Constructor Summary

AccessConstructor and Description
public
PGCopyOutputStream(PGConnection
database connection to use for copying (protocol version 3 required)
connection
,
String
COPY FROM STDIN statement
sql
)

Uses given connection for specified COPY FROM STDIN operation.

public
PGCopyOutputStream(PGConnection
database connection to use for copying (protocol version 3 required)
connection
,
String
COPY FROM STDIN statement
sql
,
int
try to send this many bytes at a time
bufferSize
)

Uses given connection for specified COPY FROM STDIN operation.

public
PGCopyOutputStream(CopyIn
COPY FROM STDIN operation
op
)

Use given CopyIn operation for writing.

public
PGCopyOutputStream(CopyIn
COPY FROM STDIN operation
op
,
int
try to send this many bytes at a time
bufferSize
)

Use given CopyIn operation for writing.

Method Summary

Modifier and TypeMethod and Description
public void
cancelCopy()

Implements org.postgresql.copy.CopyOperation.cancelCopy.

Cancels this copy operation, discarding any exchanged data.

private void
public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.

public long
endCopy()

Implements org.postgresql.copy.CopyIn.endCopy.

Finishes copy operation successfully.

public void
flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output bytes to be written out.

public void
flushCopy()

Implements org.postgresql.copy.CopyIn.flushCopy.

Force any buffered output to be sent over the network to the backend.

public int
public int
getFieldFormat(int
number of field (0..fieldCount()-1)
field
)

Implements org.postgresql.copy.CopyOperation.getFieldFormat.

public int
public long
getHandledRowCount()

Implements org.postgresql.copy.CopyOperation.getHandledRowCount.

After successful end of copy, returns the number of database records handled in that operation.

private CopyIn
public boolean
public void
write(int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.

public void
write(byte[]
the data.
buf
)

Overrides java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream.

public void
write(byte[]
the data.
buf
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
siz
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.

public void
writeToCopy(byte[]
array of bytes to write
buf
,
int
offset of first byte to write (normally zero)
off
,
int
number of bytes to write (normally buf.length)
siz
)

Implements org.postgresql.copy.CopyIn.writeToCopy.

Writes specified part of given byte array to an open and writable copy operation.

public void
writeToCopy(ByteStreamWriter
the source of bytes, e.g. a ByteBufferByteStreamWriter
from
)

Implements org.postgresql.copy.CopyIn.writeToCopy.

Writes a ByteStreamWriter to an open and writable copy operation.

Inherited from java.io.OutputStream:
nullOutputStream

Field Detail

atback to summary
private int at
copyBufferback to summary
private final byte[] copyBuffer
opback to summary
private @Nullable CopyIn op
singleByteBufferback to summary
private final byte[] singleByteBuffer

Constructor Detail

PGCopyOutputStreamback to summary
public PGCopyOutputStream(PGConnection connection, String sql) throws SQLException

Uses given connection for specified COPY FROM STDIN operation.

Parameters
connection:PGConnection

database connection to use for copying (protocol version 3 required)

sql:String

COPY FROM STDIN statement

Exceptions
SQLException:
if initializing the operation fails
PGCopyOutputStreamback to summary
public PGCopyOutputStream(PGConnection connection, String sql, int bufferSize) throws SQLException

Uses given connection for specified COPY FROM STDIN operation.

Parameters
connection:PGConnection

database connection to use for copying (protocol version 3 required)

sql:String

COPY FROM STDIN statement

bufferSize:int

try to send this many bytes at a time

Exceptions
SQLException:
if initializing the operation fails
PGCopyOutputStreamback to summary
public PGCopyOutputStream(CopyIn op)

Use given CopyIn operation for writing.

Parameters
op:CopyIn

COPY FROM STDIN operation

PGCopyOutputStreamback to summary
public PGCopyOutputStream(CopyIn op, int bufferSize)

Use given CopyIn operation for writing.

Parameters
op:CopyIn

COPY FROM STDIN operation

bufferSize:int

try to send this many bytes at a time

Method Detail

cancelCopyback to summary
public void cancelCopy() throws SQLException

Implements org.postgresql.copy.CopyOperation.cancelCopy.

Doc from org.postgresql.copy.CopyOperation.cancelCopy.

Cancels this copy operation, discarding any exchanged data.

Annotations
@Override
Exceptions
SQLException:
if cancelling fails
checkClosedback to summary
private void checkClosed() throws IOException
closeback to summary
public void close() throws IOException

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.OutputStream.close.

Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
endCopyback to summary
public long endCopy() throws SQLException

Implements org.postgresql.copy.CopyIn.endCopy.

Doc from org.postgresql.copy.CopyIn.endCopy.

Finishes copy operation successfully.

Returns:long

number of updated rows for server 8.2 or newer (see getHandledRowCount())

Annotations
@Override
Exceptions
SQLException:
if the operation fails.
flushback to summary
public void flush() throws IOException

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Doc from java.io.OutputStream.flush.

Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
flushCopyback to summary
public void flushCopy() throws SQLException

Implements org.postgresql.copy.CopyIn.flushCopy.

Doc from org.postgresql.copy.CopyIn.flushCopy.

Force 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.

Annotations
@Override
Exceptions
SQLException:
if the operation fails.
getFieldCountback to summary
public int getFieldCount()

Implements org.postgresql.copy.CopyOperation.getFieldCount.

Returns:int

Doc from org.postgresql.copy.CopyOperation.getFieldCount.

number of fields in each row for this operation

Annotations
@Override
getFieldFormatback to summary
public int getFieldFormat(int field)

Implements org.postgresql.copy.CopyOperation.getFieldFormat.

Parameters
field:int

Doc from org.postgresql.copy.CopyOperation.getFieldFormat.

number of field (0..fieldCount()-1)

Returns:int

Doc from org.postgresql.copy.CopyOperation.getFieldFormat.

format of requested field: 0 = textual, 1 = binary

Annotations
@Override
getFormatback to summary
public int getFormat()

Implements org.postgresql.copy.CopyOperation.getFormat.

Returns:int

Doc from org.postgresql.copy.CopyOperation.getFormat.

overall format of each row: 0 = textual, 1 = binary

Annotations
@Override
getHandledRowCountback to summary
public long getHandledRowCount()

Implements org.postgresql.copy.CopyOperation.getHandledRowCount.

Doc from org.postgresql.copy.CopyOperation.getHandledRowCount.

After 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.

Returns:long

number of handled rows or -1

Annotations
@Override
getOpback to summary
private CopyIn getOp()
isActiveback to summary
public boolean isActive()

Implements org.postgresql.copy.CopyOperation.isActive.

Returns:boolean

Doc from org.postgresql.copy.CopyOperation.isActive.

is connection reserved for this Copy operation?

Annotations
@Override
writeback to summary
public void write(int b) throws IOException

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
b:int

the byte.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
writeback to summary
public void write(byte[] buf) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream. The general contract for write(b) is that it should have exactly the same effect as the call write(b, 0, b.length).

Parameters
buf:byte[]

the data.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(byte[] buf, int off, int siz) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
buf:byte[]

the data.

off:int

the start offset in the data.

siz:int

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.
writeToCopyback to summary
public void writeToCopy(byte[] buf, int off, int siz) throws SQLException

Implements org.postgresql.copy.CopyIn.writeToCopy.

Doc from org.postgresql.copy.CopyIn.writeToCopy.

Writes specified part of given byte array to an open and writable copy operation.

Parameters
buf:byte[]

array of bytes to write

off:int

offset of first byte to write (normally zero)

siz:int

number of bytes to write (normally buf.length)

Annotations
@Override
Exceptions
SQLException:
if the operation fails
writeToCopyback to summary
public void writeToCopy(ByteStreamWriter from) throws SQLException

Implements org.postgresql.copy.CopyIn.writeToCopy.

Doc from org.postgresql.copy.CopyIn.writeToCopy.

Writes a ByteStreamWriter to an open and writable copy operation.

Parameters
from:ByteStreamWriter

the source of bytes, e.g. a ByteBufferByteStreamWriter

Annotations
@Override
Exceptions
SQLException:
if the operation fails