Package com.comphenix.protocol.utility
Class StreamSerializer
java.lang.Object
com.comphenix.protocol.utility.StreamSerializer
Utility methods for reading and writing Minecraft objects to streams.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionRead or deserialize an NBT compound from a input stream.org.bukkit.inventory.ItemStackdeserializeItemStack(String input) Deserialize an item stack from a base-64 encoded string.org.bukkit.inventory.ItemStackdeserializeItemStackFromByteArray(byte[] input) Deserialize an item stack from a byte array.deserializeString(DataInputStream input, int maximumLength) Deserialize a string using the standard Minecraft UTF-16 encoding.intdeserializeVarInt(DataInputStream source) Read a variable integer from an input stream.byte[]getBytesAndRelease(io.netty.buffer.ByteBuf buf) static StreamSerializerRetrieve a default stream serializer.voidserializeCompound(DataOutputStream output, NbtCompound compound) Write or serialize a NBT compound to the given output stream.voidserializeItemStack(DataOutputStream output, org.bukkit.inventory.ItemStack stack) Write or serialize an item stack to the given output stream.serializeItemStack(org.bukkit.inventory.ItemStack stack) Serialize an item stack as a base-64 encoded string.byte[]serializeItemStackToByteArray(org.bukkit.inventory.ItemStack stack) Serialize an item stack as byte array.voidserializeString(DataOutputStream output, String text) Serialize a string using the standard Minecraft UTF-16 encoding.voidserializeVarInt(DataOutputStream destination, int value) Write a variable integer to an output stream.
-
Constructor Details
-
StreamSerializer
public StreamSerializer()
-
-
Method Details
-
getDefault
Retrieve a default stream serializer.- Returns:
- A serializer.
-
serializeVarInt
Write a variable integer to an output stream.- Parameters:
destination- - the destination.value- - the value to write.- Throws:
IOException- The destination stream threw an exception.
-
deserializeVarInt
Read a variable integer from an input stream.- Parameters:
source- - the source.- Returns:
- The integer.
- Throws:
IOException- The source stream threw an exception.
-
serializeCompound
Write or serialize a NBT compound to the given output stream.Note: An NBT compound can be written to a stream even if it's NULL.
- Parameters:
output- - the target output stream.compound- - the NBT compound to be serialized, or NULL to represent nothing.
-
deserializeCompound
Read or deserialize an NBT compound from a input stream.- Parameters:
input- - the target input stream.- Returns:
- The resulting compound, or NULL.
-
serializeString
Serialize a string using the standard Minecraft UTF-16 encoding.Note that strings cannot exceed 32767 characters, regardless if maximum lenght.
- Parameters:
output- - the output stream.text- - the string to serialize.
-
deserializeString
Deserialize a string using the standard Minecraft UTF-16 encoding.Note that strings cannot exceed 32767 characters, regardless if maximum length.
- Parameters:
input- - the input stream.maximumLength- - the maximum length of the string.- Returns:
- The deserialized string.
-
serializeItemStack
Serialize an item stack as a base-64 encoded string.Note: An ItemStack can be written to the serialized text even if it's NULL.
- Parameters:
stack- - the item stack to serialize, or NULL to represent air/nothing.- Returns:
- A base-64 representation of the given item stack.
- Throws:
IOException- If the operation fails due to reflection problems.
-
deserializeItemStack
Deserialize an item stack from a base-64 encoded string.- Parameters:
input- - base-64 encoded string.- Returns:
- A deserialized item stack, or NULL if the serialized ItemStack was also NULL.
-
serializeItemStackToByteArray
public byte[] serializeItemStackToByteArray(org.bukkit.inventory.ItemStack stack) throws IOException Serialize an item stack as byte array.Note: An ItemStack can be written to the serialized text even if it's NULL.
- Parameters:
stack- - the item stack to serialize, or NULL to represent air/nothing.- Returns:
- A binary representation of the given item stack.
- Throws:
IOException- If the operation fails due to reflection problems.
-
deserializeItemStackFromByteArray
public org.bukkit.inventory.ItemStack deserializeItemStackFromByteArray(byte[] input) Deserialize an item stack from a byte array.- Parameters:
input- - serialized item.- Returns:
- A deserialized item stack, or NULL if the serialized ItemStack was also NULL.
-
serializeItemStack
public void serializeItemStack(DataOutputStream output, org.bukkit.inventory.ItemStack stack) throws IOException Write or serialize an item stack to the given output stream.To supply a byte array, wrap it in a
ByteArrayOutputStreamandDataOutputStream.Note: An ItemStack can be written to a stream even if it's NULL.
- Parameters:
output- - the target output stream.stack- - the item stack that will be written, or NULL to represent air/nothing.- Throws:
IOException- If the operation fails due to reflection problems.
-
getBytesAndRelease
public byte[] getBytesAndRelease(io.netty.buffer.ByteBuf buf)
-