Class DefaultFileSender

java.lang.Object
host.anzo.simon.filetransmit.DefaultFileSender

public class DefaultFileSender extends Object
A default implementation to send files to DefaultFileReceiver. You can create your own by overwriting methods, or by creating an own implementation which makes use of server's FileReceiver implementation.
Since:
1.2.0
  • Field Details

  • Constructor Details

    • DefaultFileSender

      public DefaultFileSender(FileReceiver fileReceiver)
      Creates a file sender and connects it to the given file receiver. Files will be sent sequentially.
      Parameters:
      fileReceiver - the receiving object
    • DefaultFileSender

      public DefaultFileSender(FileReceiver fileReceiver, int txThreads)
      Creates a file sender and connects it to the given receiver.
      Parameters:
      fileReceiver - the receiving object
      txThreads - number of max. concurrent uploads
  • Method Details

    • close

      public void close()
      Close the file sender. All uploads in progress will continue until completion or in case of error abort.
    • closeAndWait

      public boolean closeAndWait(int timeout) throws InterruptedException
      Close the file sender and wait at most timeout milliseconds to complete or in case of error abort all downloads
      Parameters:
      timeout - milliseconds to wait for close completion
      Returns:
      true if this file sender completed all uploads and terminated, or false if the timeout elapsed before termination
      Throws:
      InterruptedException - if interrupted while waiting
    • setTxBlockSize

      public void setTxBlockSize(int blockSize)
      Set the block size for writing data
      Parameters:
      blockSize - number of bytes to write in one block
    • getTxBLockSize

      public int getTxBLockSize()
      Gets the block size for writing data
      Returns:
      number of bytes to write in one block
    • sendFile

      public int sendFile(File f)
      Send local file to connected file receiver
      Parameters:
      f - the file to send.
      Returns:
      a generated ID for the file. Can be used to identify the file in progress listener. Especially useful when transmitting files with same names one after another. When Integer.MAX_VALUE is reached, ID is reset back to 0.
    • sendFile

      public int sendFile(File f, boolean overwriteExisting)
      Parameters:
      f - the file to send.
      overwriteExisting - if true, any existing file with same name will be overwritten on target
      Returns:
      a generated ID for the file. Can be used to identify the file in progress listener. Especially useful when transmitting files with same names one after another. When Integer.MAX_VALUE is reached, ID is reset back to 0.
      See Also:
    • addProgressListener

      public void addProgressListener(FileSenderProgressListener progressListener)
      Adds a progress listener
      Parameters:
      progressListener - progress listener implementation
    • removeProgressListener

      public void removeProgressListener(FileSenderProgressListener progressListener)
      Removes a progress listener
      Parameters:
      progressListener - progress listener implementation