Package noaa.coastwatch.io
Class DataTransfer
java.lang.Object
noaa.coastwatch.io.DataTransfer
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
URLTransfer
The data transfer class allows for the generic connection between
input and output streams. Data is copied from the input stream to
the output stream until no more data is available. The progress of
data copying may be monitored with a data transfer listener.
- Since:
- 3.1.5
- Author:
- Peter Hollemans
-
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a new empty transfer.DataTransfer
(InputStream input, OutputStream output, int bufferSize) Creates a new data transfer with the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoid
abort()
Aborts a transfer in progress.void
addDataTransferListener
(DataTransferListener listener) Adds a data transfer listener to the list.void
close()
Closes the input and output streams.double
getRate()
Gets the average transfer rate in kilobytes per second.long
Gets the transfer start time in milliseconds.int
Gets the current count of transferred data in bytes.void
Removes a data transfer listener from the list.void
run()
Starts the transfer of data from the input stream to the output stream.protected void
setStreams
(InputStream input, OutputStream output, int bufferSize) Initializes a transfer with new input and output streams.protected void
setupIO()
Performs any setup necessary before I/O actually occurs.
-
Constructor Details
-
DataTransfer
protected DataTransfer()Creates a new empty transfer. -
DataTransfer
Creates a new data transfer with the specified parameters.- Parameters:
input
- the input stream to read.output
- the output stream to write.bufferSize
- the size of the buffer to use for each transfer.
-
-
Method Details
-
getTransferred
public int getTransferred()Gets the current count of transferred data in bytes. -
getStartTime
public long getStartTime()Gets the transfer start time in milliseconds. If the data transfer is not yet running, the start time is -1. -
getRate
public double getRate()Gets the average transfer rate in kilobytes per second. -
addDataTransferListener
Adds a data transfer listener to the list. -
removeDataTransferListener
Removes a data transfer listener from the list. -
setStreams
Initializes a transfer with new input and output streams. -
setupIO
Performs any setup necessary before I/O actually occurs. This method is called fromrun()
before any actual data is transferred. By default, it does nothing unless overridden in the child class. The state after this method runs should be that the input and output streams are assigned valid stream values.- Throws:
IOException
-
run
public void run()Starts the transfer of data from the input stream to the output stream. -
abort
public void abort()Aborts a transfer in progress. This is only useful if the transfer is taking place in a separate thread. -
close
Closes the input and output streams.- Throws:
IOException
-