Package net.minestom.server.utils.binary
Class BinaryWriter
java.lang.Object
java.io.OutputStream
net.minestom.server.utils.binary.BinaryWriter
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
Class used to write to a byte array.
WARNING: not thread-safe.
-
Constructor Summary
ConstructorsConstructorDescriptionBinaryWriter(int initialCapacity) BinaryWriter(@NotNull ByteBuffer buffer) BinaryWriter(@NotNull NetworkBuffer buffer) -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]makeArray(@NotNull Consumer<@NotNull BinaryWriter> writing) Returns a byte[] with the contents written via BinaryWriterbyte[]Converts the internal buffer to a byte array.static BinaryWriterview(ByteBuffer buffer) voidwrite(int b) voidwrite(@NotNull ByteBuffer buffer) voidwrite(@NotNull BinaryWriter writer) voidWrites the given writeable object into this writer.voidwriteArray(@NotNull Writeable[] writeables) Writes an array of writeable objects to this writer.voidwriteBlockPosition(int x, int y, int z) voidwriteBlockPosition(@NotNull Point point) voidwriteBoolean(boolean b) voidwriteByte(byte b) voidwriteByteArray(byte[] array) <T> voidwriteByteList(Collection<T> list, @NotNull BiConsumer<BinaryWriter, T> consumer) voidwriteBytes(byte @NotNull [] bytes) voidwriteComponent(@NotNull Component component) voidwriteDouble(double d) <L,R> void writeEither(Either<L, R> either, BiConsumer<BinaryWriter, L> leftWriter, BiConsumer<BinaryWriter, R> rightWriter) voidwriteFloat(float f) voidwriteInt(int i) voidwriteItemStack(@NotNull ItemStack itemStack) voidwriteLong(long l) voidwriteLongArray(long[] array) voidvoidwriteNullTerminatedString(@NotNull String string, @NotNull Charset charset) voidwriteShort(short s) voidwriteSizedString(@NotNull String string) voidwriteStringArray(@NotNull String[] array) voidwriteUnsignedShort(int yourShort) voidvoidwriteVarInt(int i) voidwriteVarIntArray(int[] array) <T> voidwriteVarIntList(Collection<T> list, @NotNull BiConsumer<BinaryWriter, T> consumer) voidwriteVarLong(long l) voidwriteVarLongArray(long[] array) Methods inherited from class java.io.OutputStream
close, flush, nullOutputStream, write, write
-
Constructor Details
-
BinaryWriter
-
BinaryWriter
-
BinaryWriter
public BinaryWriter(int initialCapacity) -
BinaryWriter
public BinaryWriter()
-
-
Method Details
-
view
-
writeComponent
-
writeByte
public void writeByte(byte b) -
writeBoolean
public void writeBoolean(boolean b) -
writeShort
public void writeShort(short s) -
writeInt
public void writeInt(int i) -
writeLong
public void writeLong(long l) -
writeFloat
public void writeFloat(float f) -
writeDouble
public void writeDouble(double d) -
writeVarInt
public void writeVarInt(int i) -
writeVarLong
public void writeVarLong(long l) -
writeSizedString
-
writeNullTerminatedString
-
writeVarIntArray
public void writeVarIntArray(int[] array) -
writeVarLongArray
public void writeVarLongArray(long[] array) -
writeLongArray
public void writeLongArray(long[] array) -
writeByteArray
public void writeByteArray(byte[] array) -
writeBytes
public void writeBytes(byte @NotNull [] bytes) -
writeStringArray
-
writeUuid
-
writeBlockPosition
-
writeBlockPosition
public void writeBlockPosition(int x, int y, int z) -
writeItemStack
-
writeNBT
public void writeNBT(@NotNull @NotNull String name, @NotNull @NotNull org.jglrxavpok.hephaistos.nbt.NBT tag) -
writeEither
public <L,R> void writeEither(Either<L, R> either, BiConsumer<BinaryWriter, L> leftWriter, BiConsumer<BinaryWriter, R> rightWriter) -
write
Writes the given writeable object into this writer.- Parameters:
writeable- the object to write
-
write
-
write
-
writeArray
Writes an array of writeable objects to this writer. Will prepend the binary stream with a var int to denote the length of the array.- Parameters:
writeables- the array of writeables to write
-
writeVarIntList
public <T> void writeVarIntList(Collection<T> list, @NotNull @NotNull BiConsumer<BinaryWriter, T> consumer) -
writeByteList
public <T> void writeByteList(Collection<T> list, @NotNull @NotNull BiConsumer<BinaryWriter, T> consumer) -
toByteArray
public byte[] toByteArray()Converts the internal buffer to a byte array.- Returns:
- the byte array containing all the
BinaryWriterdata
-
write
public void write(int b) - Specified by:
writein classOutputStream
-
writeUnsignedShort
public void writeUnsignedShort(int yourShort) -
makeArray
Returns a byte[] with the contents written via BinaryWriter
-