Class ChunkedPacket

java.lang.Object
eu.cloudnetservice.driver.network.protocol.BasePacket
eu.cloudnetservice.driver.network.chunk.network.ChunkedPacket
All Implemented Interfaces:
Packet

public final class ChunkedPacket extends BasePacket
A transfer packet that holds data about a chunk of data to transfer.
Since:
4.0
  • Constructor Details

    • ChunkedPacket

      private ChunkedPacket(@NonNull @NonNull DataBuf dataBuf)
      Constructs a new chunked transfer part packet.
      Parameters:
      dataBuf - the data for the handling process of the chunk part.
      Throws:
      NullPointerException - if the given buffer is null.
  • Method Details

    • createFullChunk

      @NonNull public static @NonNull ChunkedPacket createFullChunk(int chunkIndex, byte[] sourceData, @NonNull @NonNull ChunkSessionInformation sessionInfo)
      Creates a new full chunk in the middle of a transfer. This method assumes that tbe amount of bytes that were read from the underlying source is the same as the chunk size of the transfer, only the last chunk is allowed to contain less or no data.
      Parameters:
      chunkIndex - the 0-based index of the chunk that is being sent.
      sourceData - the data that was read from the underlying source.
      sessionInfo - the information about the transfer session that this packet is related to.
      Returns:
      a full chunk packet containing all the information provided to this method.
      Throws:
      NullPointerException - if the given source data or chunk information is null.
    • createFinalChunk

      @NonNull public static @NonNull ChunkedPacket createFinalChunk(int chunkIndex, int readBytes, byte[] sourceData, @NonNull @NonNull ChunkSessionInformation sessionInfo)
      Creates a new final chunk which must be sent to terminate a chunked data transfer on the remote side. Due to this the provided chunk index is assumed to be the last index, which means that the total amount of chunks will be set to index + 1. The final chunk of a transfer is allowed to contain fewer or no bytes than the chunk size of the session. To properly serialize the smaller chunk data which can be provided in a bigger data byte array, the given read bytes will be used to only serialize the chunk of bytes in the given array that are actually relevant.
      Parameters:
      chunkIndex - the 0-based index of the chunk that is being sent.
      readBytes - the amount of bytes that were read from the underlying source.
      sourceData - the data that was read from the underlying source.
      sessionInfo - the information about the transfer session that this packet is related to.
      Returns:
      the created chunk packet based on the information.
      Throws:
      NullPointerException - if the given chunk information is null.