Class DefaultFileChunkedPacketHandler

java.lang.Object
eu.cloudnetservice.driver.impl.network.chunk.DefaultChunkedPacketProvider
eu.cloudnetservice.driver.impl.network.chunk.DefaultFileChunkedPacketHandler
All Implemented Interfaces:
eu.cloudnetservice.driver.network.chunk.ChunkedPacketHandler, eu.cloudnetservice.driver.network.chunk.ChunkedPacketProvider

public class DefaultFileChunkedPacketHandler extends DefaultChunkedPacketProvider implements eu.cloudnetservice.driver.network.chunk.ChunkedPacketHandler
Represents a handler for a chunked packet transfer which transfers a file.
Since:
4.0
  • Field Details

    • FILE_CHANNEL_OPEN_OPTIONS

      protected static final Set<OpenOption> FILE_CHANNEL_OPEN_OPTIONS
    • tempFilePath

      protected final Path tempFilePath
    • targetFile

      protected final FileChannel targetFile
    • writeCompleteHandler

      protected final eu.cloudnetservice.driver.network.chunk.ChunkedPacketHandler.Callback writeCompleteHandler
    • lock

      protected final Lock lock
    • writtenFileParts

      protected int writtenFileParts
    • expectedFileParts

      protected int expectedFileParts
  • Constructor Details

    • DefaultFileChunkedPacketHandler

      public DefaultFileChunkedPacketHandler(@NonNull @NonNull eu.cloudnetservice.driver.network.chunk.ChunkSessionInformation sessionInformation, @Nullable @Nullable eu.cloudnetservice.driver.network.chunk.ChunkedPacketHandler.Callback completeHandler)
      Creates the session handler initially. Sessions should be manged by some sort of handler that is responsible for handling incoming chunk parts as well.
      Parameters:
      sessionInformation - the information transferred by the sender initially.
      completeHandler - the handler to call when the file transfer finished successfully.
      Throws:
      NullPointerException - if the given session information is null.
    • DefaultFileChunkedPacketHandler

      public DefaultFileChunkedPacketHandler(@NonNull @NonNull eu.cloudnetservice.driver.network.chunk.ChunkSessionInformation sessionInformation, @Nullable @Nullable eu.cloudnetservice.driver.network.chunk.ChunkedPacketHandler.Callback completeHandler, @NonNull @NonNull Path tempFilePath)
      Creates the session handler initially. Sessions should be manged by some sort of handler that is responsible for handling incoming chunk parts as well.
      Parameters:
      sessionInformation - the information transferred by the sender initially.
      completeHandler - the handler to call when the file transfer finished successfully.
      tempFilePath - the path to the temp file to write the received data to.
      Throws:
      NullPointerException - if the given session information or temp path is null.
  • Method Details

    • openTempFile

      @NonNull private @NonNull FileChannel openTempFile()
      Opens a file channel to the provided temp path, creating the file if it does not exist. Note that this method does not create the parent directory of the file, it must exist prior to invocation.
      Returns:
      the opened file channel to the target file.
      Throws:
      IllegalStateException - if the temp file cannot be opened or created.
    • handleChunkPart

      public boolean handleChunkPart(int chunkPosition, @NonNull @NonNull eu.cloudnetservice.driver.network.buffer.DataBuf dataBuf)
      Specified by:
      handleChunkPart in interface eu.cloudnetservice.driver.network.chunk.ChunkedPacketHandler
    • writePacketContent

      protected void writePacketContent(int chunkPosition, @NonNull @NonNull eu.cloudnetservice.driver.network.buffer.DataBuf dataBuf) throws IOException
      Writes the content of a chunk part to the backing file channel.
      Parameters:
      chunkPosition - the index of the chunk to write.
      dataBuf - the buf transferred to this handler, the next content should be the actual chunk data.
      Throws:
      IOException - if an i/o error occurs during the chunk write.
      NullPointerException - if the given buffer is null.