com.amazon.redshift.copy

## Class RedshiftCopyInputStream

- java.lang.Object
- - java.io.InputStream
  - - com.amazon.redshift.copy.RedshiftCopyInputStream

All Implemented Interfaces:
  CopyOperation, CopyOut, Closeable, AutoCloseable

    public class RedshiftCopyInputStream
    extends InputStream
    implements CopyOut

InputStream for reading from a Redshift COPY TO STDOUT operation.

### Constructor Summary

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

### Method Summary

All Methods Instance Methods Concrete 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 successful 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()` Blocks wait for a row of data to be received from server on an active copy operation.
`byte[]` `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, reset, skip`

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

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

### Constructor Detail

#### RedshiftCopyInputStream

    public RedshiftCopyInputStream(RedshiftConnection connection,
                                   String sql)
                            throws 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:
  `SQLException` - if initializing the operation fails

#### RedshiftCopyInputStream

    public RedshiftCopyInputStream(CopyOut op)

Use given CopyOut operation for reading.

Parameters:
  `op` - COPY TO STDOUT operation

### Method Detail

#### available

    public int available()
                  throws IOException

Overrides:
  `available` in class `InputStream`
Throws:
  `IOException`

#### read

    public int read()
             throws IOException

Specified by:
  `read` in class `InputStream`
Throws:
  `IOException`

#### read

    public int read(byte[] buf)
             throws IOException

Overrides:
  `read` in class `InputStream`
Throws:
  `IOException`

#### read

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

Overrides:
  `read` in class `InputStream`
Throws:
  `IOException`

#### readFromCopy

    public byte[] readFromCopy()
                        throws SQLException

Description copied from interface: `CopyOut`
Blocks wait for a row of data to be received from server on an active copy operation.

Specified by:
  `readFromCopy` in interface `CopyOut`
Returns:
  byte array received from server, null if server complete copy operation
Throws:
  `SQLException` - if something goes wrong for example socket timeout

#### readFromCopy

    public byte[] readFromCopy(boolean block)
                        throws SQLException

Description copied from interface: `CopyOut`
Wait for a row of data to be received from server on an active copy operation.

Specified by:
  `readFromCopy` in interface `CopyOut`
Parameters:
  `block` - `true` if need wait data from server otherwise `false` and 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

    public void close()
               throws IOException

Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `AutoCloseable`
Overrides:
  `close` in class `InputStream`
Throws:
  `IOException`

#### cancelCopy

    public void cancelCopy()
                    throws SQLException

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

Specified by:
  `cancelCopy` in interface `CopyOperation`
Throws:
  `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 successful end of copy, returns the number of database records handled in that operation. Unimplemented in Redshift server. Returns -1.

Specified by:
  `getHandledRowCount` in interface `CopyOperation`
Returns:
  number of handled rows or -1