org.postgresql.copy

## Class PGCopyInputStream

- java.lang.Object
- - java.io.InputStream
  - - org.postgresql.copy.PGCopyInputStream

All Implemented Interfaces:
  java.io.Closeable, java.lang.AutoCloseable, CopyOperation, CopyOut

    public class PGCopyInputStream
    extends java.io.InputStream
    implements CopyOut

InputStream for reading from a PostgreSQL COPY TO STDOUT operation

### Constructor Summary

Constructors
Constructor and Description
`PGCopyInputStream(CopyOut op)` Use given CopyOut operation for reading
`PGCopyInputStream(PGConnection connection, java.lang.String sql)` Uses given connection for specified COPY TO STDOUT operation

### Method Summary

Methods
`int` `available()`
`void` `cancelCopy()` Cancels this copy operation, discarding any exchanged data.
`void` `close()`
`int` `getFieldCount()`
`int` `getFieldFormat(int field)`
`int` `getFormat()`
`long` `getHandledRowCount()` After succesful end of copy, returns the number of database records handled in that operation.
`boolean` `isActive()`
`int` `read()`
`int` `read(byte[] buf)`
`int` `read(byte[] buf, int off, int siz)`
`byte[]` `readFromCopy()`

### Methods inherited from class java.io.InputStream

`mark, markSupported, reset, skip`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### PGCopyInputStream

    public PGCopyInputStream(PGConnection connection,
                     java.lang.String sql)
                      throws java.sql.SQLException

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:
  `java.sql.SQLException` - if initializing the operation fails

#### PGCopyInputStream

    public PGCopyInputStream(CopyOut op)

Use given CopyOut operation for reading

Parameters:
  `op` - COPY TO STDOUT operation
Throws:
  `java.sql.SQLException` - if initializing the operation fails

### Method Detail

#### available

    public int available()
                  throws java.io.IOException

Overrides:
  `available` in class `java.io.InputStream`
Throws:
  `java.io.IOException`

#### read

    public int read()
             throws java.io.IOException

Specified by:
  `read` in class `java.io.InputStream`
Throws:
  `java.io.IOException`

#### read

    public int read(byte[] buf)
             throws java.io.IOException

Overrides:
  `read` in class `java.io.InputStream`
Throws:
  `java.io.IOException`

#### read

    public int read(byte[] buf,
           int off,
           int siz)
             throws java.io.IOException

Overrides:
  `read` in class `java.io.InputStream`
Throws:
  `java.io.IOException`

#### readFromCopy

    public byte[] readFromCopy()
                        throws java.sql.SQLException

Specified by:
  `readFromCopy` in interface `CopyOut`
Throws:
  `java.sql.SQLException`

#### close

    public void close()
               throws java.io.IOException

Specified by:
  `close` in interface `java.io.Closeable`
Specified by:
  `close` in interface `java.lang.AutoCloseable`
Overrides:
  `close` in class `java.io.InputStream`
Throws:
  `java.io.IOException`

#### cancelCopy

    public void cancelCopy()
                    throws java.sql.SQLException

Description copied from interface: `CopyOperation`
Cancels this copy operation, discarding any exchanged data.

Specified by:
  `cancelCopy` in interface `CopyOperation`
Throws:
  `java.sql.SQLException` - if cancelling fails

#### getFormat

    public int getFormat()

Specified by:
  `getFormat` in interface `CopyOperation`
Returns:
  overall format of each row: 0 = textual, 1 = binary

#### getFieldFormat

    public int getFieldFormat(int field)

Specified by:
  `getFieldFormat` in interface `CopyOperation`
Parameters:
  `field` - number of field (0..fieldCount()-1)
Returns:
  format of requested field: 0 = textual, 1 = binary

#### getFieldCount

    public int getFieldCount()

Specified by:
  `getFieldCount` in interface `CopyOperation`
Returns:
  number of fields in each row for this operation

#### isActive

    public boolean isActive()

Specified by:
  `isActive` in interface `CopyOperation`
Returns:
  is connection reserved for this Copy operation?

#### getHandledRowCount

    public long getHandledRowCount()

Description copied from interface: `CopyOperation`
After succesful 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:
  `getHandledRowCount` in interface `CopyOperation`
Returns:
  number of handled rows or -1