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
  • Field Details

    • EMPTY_BYTE_ARRAY

      protected static final byte[] EMPTY_BYTE_ARRAY
    • source

      protected final InputStream source
    • packetSplitter

      protected final Consumer<Packet> packetSplitter
  • Constructor Details

  • Method Details

    • source

      @NonNull public @NonNull InputStream source()
      Get the source of data to stream and transfer through the network. The stream gets closed automatically when the transfer succeeded.
      Specified by:
      source in interface ChunkedPacketSender
      Returns:
      the source of data to stream and transfer.
    • packetSplitter

      @NonNull public @NonNull Consumer<Packet> 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:
      packetSplitter in interface ChunkedPacketSender
      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:
      transferChunkedData in interface ChunkedPacketSender
      Returns:
      a future completed when the transfer finishes.