Class DefaultFileChunkPacketSender
java.lang.Object
eu.cloudnetservice.driver.network.chunk.defaults.DefaultChunkedPacketProvider
eu.cloudnetservice.driver.network.chunk.defaults.DefaultFileChunkPacketSender
- All Implemented Interfaces:
ChunkedPacketProvider,ChunkedPacketSender
public class DefaultFileChunkPacketSender
extends DefaultChunkedPacketProvider
implements ChunkedPacketSender
Represents a default implementation of a chunked packet sender specifically created for chunked transferring of a
huge file, e.g. a zip archive.
This class shouldn't get instantiated directly, use ChunkedPacketSender.forFileTransfer() instead.
- Since:
- 4.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface eu.cloudnetservice.driver.network.chunk.ChunkedPacketSender
ChunkedPacketSender.Builder -
Field Summary
FieldsFields inherited from class eu.cloudnetservice.driver.network.chunk.defaults.DefaultChunkedPacketProvider
chunkSessionInformation, transferStatus -
Constructor Summary
ConstructorsConstructorDescriptionDefaultFileChunkPacketSender(@NonNull ChunkSessionInformation sessionInformation, @NonNull InputStream source, @NonNull Consumer<Packet> packetSplitter) Constructs a new chunked packet sender for file transfer. -
Method Summary
Modifier and TypeMethodDescriptionGet the splitter of each packet which is sent through the network.source()Get the source of data to stream and transfer through the network.@NonNull eu.cloudnetservice.common.concurrent.Task<TransferStatus>Transfers the data from the data source to all targets of this sender.Methods inherited from class eu.cloudnetservice.driver.network.chunk.defaults.DefaultChunkedPacketProvider
sessionInformation, transferStatusMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface eu.cloudnetservice.driver.network.chunk.ChunkedPacketProvider
sessionInformation, transferStatus
-
Field Details
-
EMPTY_BYTE_ARRAY
protected static final byte[] EMPTY_BYTE_ARRAY -
source
-
packetSplitter
-
-
Constructor Details
-
DefaultFileChunkPacketSender
public DefaultFileChunkPacketSender(@NonNull @NonNull ChunkSessionInformation sessionInformation, @NonNull @NonNull InputStream source, @NonNull @NonNull Consumer<Packet> packetSplitter) Constructs a new chunked packet sender for file transfer.- Parameters:
sessionInformation- the information about the chunked session.source- the source stream of the file, will be closed automatically.packetSplitter- the splitter for each chunk part to transfer.- Throws:
NullPointerException- if either the information, source or splitter is null.
-
-
Method Details
-
source
Get the source of data to stream and transfer through the network. The stream gets closed automatically when the transfer succeeded.- Specified by:
sourcein interfaceChunkedPacketSender- Returns:
- the source of data to stream and transfer.
-
packetSplitter
Get the splitter of each packet which is sent through the network. The splitter is responsible to send the packet to the network component(s) which this sender is targeting. It's for example used to allow transfer of a single chunk packet to multiple network components by multiplying it.- Specified by:
packetSplitterin interfaceChunkedPacketSender- Returns:
- the packet splitter.
-
transferChunkedData
@NonNull public @NonNull eu.cloudnetservice.common.concurrent.Task<TransferStatus> transferChunkedData()Transfers the data from the data source to all targets of this sender. The returned future is completed when:- The transfer completed successfully.
- The transfer failed for any reason. The returned task will be completed holding the reason exception.
- Specified by:
transferChunkedDatain interfaceChunkedPacketSender- Returns:
- a future completed when the transfer finishes.
-