Class ChunkedPacket
java.lang.Object
eu.cloudnetservice.driver.network.protocol.BasePacket
eu.cloudnetservice.driver.network.chunk.network.ChunkedPacket
- All Implemented Interfaces:
Packet
A chunked packet which gets transferred from the sender to the target each time holding necessary information for
packet processing on the other side.
- Since:
- 4.0
-
Field Summary
Fields inherited from class eu.cloudnetservice.driver.network.protocol.BasePacket
channel, creationStamp, dataBuf, prioritized, uniqueId -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull ChunkedPacketcreateChunk(@NonNull ChunkSessionInformation information, int chunkIndex, byte[] data) Creates a new chunk part.static @NonNull ChunkedPacketcreateChunk(@NonNull ChunkSessionInformation information, @Nullable Integer chunkAmount, int chunkIndex, int dataLength, byte[] data) Creates a new chunk part based on the given information.Methods inherited from class eu.cloudnetservice.driver.network.protocol.BasePacket
channel, constructResponse, content, creation, prioritized, readable, uniqueId, uniqueId
-
Constructor Details
-
ChunkedPacket
Creates a new chunk part. The given buffer must contain all needed information for the receiver.Using this constructor is not recommended, better use
createChunk(ChunkSessionInformation, int, byte[])orcreateChunk(ChunkSessionInformation, Integer, int, int, byte[]), based on the state of the transfer.- Parameters:
dataBuf- the backing buffer.- Throws:
NullPointerException- if the given buffer is null.
-
-
Method Details
-
createChunk
@NonNull public static @NonNull ChunkedPacket createChunk(@NonNull @NonNull ChunkSessionInformation information, int chunkIndex, byte[] data) Creates a new chunk part. This method is used when the full chunk data is not yet known. It gives no information about the amount of chunks in the full transfer and uses the length of the given array as the data length.This call is equivalent to
ChunkedPacket.createChunk(information, null, chunkIndex, data.length, data).- Parameters:
information- the session information this chunk belongs to.chunkIndex- the index of the written chunk.data- the data of the chunk.- Returns:
- the created chunk packet based on the information.
- Throws:
NullPointerException- if the given chunk information is null.
-
createChunk
@NonNull public static @NonNull ChunkedPacket createChunk(@NonNull @NonNull ChunkSessionInformation information, @Nullable @Nullable Integer chunkAmount, int chunkIndex, int dataLength, byte[] data) Creates a new chunk part based on the given information. This method is used primarily to create a chunk part when all information needed to complete the transfer are available (normally when the last chunk was read from the backing stream)- Parameters:
information- the session information this chunk belongs to.chunkAmount- the amount of chunks which were read from the backing buffer.chunkIndex- the index of the written chunk.dataLength- the amount of bytes in the current packet chunk.data- the data of the chunk.- Returns:
- the created chunk packet based on the information.
- Throws:
NullPointerException- if the given chunk information is null.
-