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
-
Nested Class Summary
Nested classes/interfaces inherited from interface eu.cloudnetservice.driver.network.chunk.ChunkedPacketHandler
eu.cloudnetservice.driver.network.chunk.ChunkedPacketHandler.Callback -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected static final Set<OpenOption> protected final Lockprotected final FileChannelprotected final Pathprotected final eu.cloudnetservice.driver.network.chunk.ChunkedPacketHandler.Callbackprotected intFields inherited from class DefaultChunkedPacketProvider
chunkSessionInformation, transferStatus -
Constructor Summary
ConstructorsConstructorDescriptionDefaultFileChunkedPacketHandler(@NonNull eu.cloudnetservice.driver.network.chunk.ChunkSessionInformation sessionInformation, @Nullable eu.cloudnetservice.driver.network.chunk.ChunkedPacketHandler.Callback completeHandler) Creates the session handler initially.DefaultFileChunkedPacketHandler(@NonNull eu.cloudnetservice.driver.network.chunk.ChunkSessionInformation sessionInformation, @Nullable eu.cloudnetservice.driver.network.chunk.ChunkedPacketHandler.Callback completeHandler, @NonNull Path tempFilePath) Creates the session handler initially. -
Method Summary
Modifier and TypeMethodDescriptionbooleanhandleChunkPart(int chunkPosition, @NonNull eu.cloudnetservice.driver.network.buffer.DataBuf dataBuf) private @NonNull FileChannelOpens a file channel to the provided temp path, creating the file if it does not exist.protected voidwritePacketContent(int chunkPosition, @NonNull eu.cloudnetservice.driver.network.buffer.DataBuf dataBuf) Writes the content of a chunk part to the backing file channel.Methods inherited from class DefaultChunkedPacketProvider
sessionInformation, transferStatusMethods inherited from class 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
-
FILE_CHANNEL_OPEN_OPTIONS
-
tempFilePath
-
targetFile
-
writeCompleteHandler
protected final eu.cloudnetservice.driver.network.chunk.ChunkedPacketHandler.Callback writeCompleteHandler -
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
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
-
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.
-