Class DataTransfer

java.lang.Object
noaa.coastwatch.io.DataTransfer
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
URLTransfer

public class DataTransfer extends Object implements Runnable
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 Details

    • DataTransfer

      protected DataTransfer()
      Creates a new empty transfer.
    • DataTransfer

      public DataTransfer(InputStream input, OutputStream output, int bufferSize)
      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

      public void addDataTransferListener(DataTransferListener listener)
      Adds a data transfer listener to the list.
    • removeDataTransferListener

      public void removeDataTransferListener(DataTransferListener listener)
      Removes a data transfer listener from the list.
    • setStreams

      protected void setStreams(InputStream input, OutputStream output, int bufferSize)
      Initializes a transfer with new input and output streams.
    • setupIO

      protected void setupIO() throws IOException
      Performs any setup necessary before I/O actually occurs. This method is called from run() 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.
      Specified by:
      run in interface Runnable
    • abort

      public void abort()
      Aborts a transfer in progress. This is only useful if the transfer is taking place in a separate thread.
    • close

      public void close() throws IOException
      Closes the input and output streams.
      Throws:
      IOException