com.partnersoft.io
Interface IOCopier

All Known Implementing Classes:
DataCopier, ReaderCopier, StreamCopier

public interface IOCopier

Interface for tools that copy data from an input source to an output sink.

Implementation should be designed for a single copy task; they are thrown away and garbage collected after the copy is complete. Partial or fixed-length copies are allowed via the copy(long) method. Full copies are done by the copy(). Closing of the streams is optional, and should be performed by the close() method.

Typical usage is:

 copier = new StreamCopier(input, output);
 copier.copy();
 copier.close();
 

Copyright 2006 Partner Software, Inc.

Author:
Paul Reavis

Method Summary
 void close()
          Closes input source and output sink.
 long copy()
          Copies all available data from the source to the sink.
 long copy(long howMuch)
          Copies the specified amount of data from the source to the sink.
 long copyBlockingOnce()
          Block only once, copying available data, but quit as soon as a block would occur.
 long copyWithoutBlocking()
          Copies only available data.
 

Method Detail

copy

long copy()
          throws java.io.IOException
Copies all available data from the source to the sink. Flushes the output when done but does not close either source or sink.

Returns:
total number of items (bytes, characters, etc.) copied
Throws:
java.io.IOException - if something prevents the copy

copyWithoutBlocking

long copyWithoutBlocking()
                         throws java.io.IOException
Copies only available data. No blocking is done; if no data is available, stop.

This method is optional, if it's not appropriate for the kind of copy, throws an UnsupportedOperationException.

Throws:
java.io.IOException

copyBlockingOnce

long copyBlockingOnce()
                      throws java.io.IOException
Block only once, copying available data, but quit as soon as a block would occur.

This method is optional, if it's not appropriate for the kind of copy, throws an UnsupportedOperationException.

Throws:
java.io.IOException

copy

long copy(long howMuch)
          throws java.io.IOException
Copies the specified amount of data from the source to the sink. Flushes the output when done but does not close either source or sink. Can be called multiple times, as long as there is available data.

Parameters:
howMuch - how many items (bytes, characters, etc.) to copy
Returns:
total number of items (bytes, characters, etc.) copied
Throws:
java.io.IOException - if something prevents the copy or if there are not enough items to copy

close

void close()
           throws java.io.IOException
Closes input source and output sink. Optional; in some cases you may want to leave the streams open for other purposes.

Throws:
java.io.IOException - if anything prevents closing.