Package host.anzo.simon.filetransmit
Class DefaultFileSender
java.lang.Object
host.anzo.simon.filetransmit.DefaultFileSender
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefaultFileSender(FileReceiver fileReceiver) Creates a file sender and connects it to the given file receiver.DefaultFileSender(FileReceiver fileReceiver, int txThreads) Creates a file sender and connects it to the given receiver. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddProgressListener(FileSenderProgressListener progressListener) Adds a progress listenervoidclose()Close the file sender.booleancloseAndWait(int timeout) Close the file sender and wait at mosttimeoutmilliseconds to complete or in case of error abort all downloadsintGets the block size for writing datavoidremoveProgressListener(FileSenderProgressListener progressListener) Removes a progress listenerintSend local file to connected file receiverintvoidsetTxBlockSize(int blockSize) Set the block size for writing data
-
Field Details
-
listeners
-
-
Constructor Details
-
DefaultFileSender
Creates a file sender and connects it to the given file receiver. Files will be sent sequentially.- Parameters:
fileReceiver- the receiving object
-
DefaultFileSender
Creates a file sender and connects it to the given receiver.- Parameters:
fileReceiver- the receiving objecttxThreads- 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
Close the file sender and wait at mosttimeoutmilliseconds 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
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
- 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
Adds a progress listener- Parameters:
progressListener- progress listener implementation
-
removeProgressListener
Removes a progress listener- Parameters:
progressListener- progress listener implementation
-