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
ConstructorDescriptionBinaryWriter
(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 BinaryWriter
view
(ByteBuffer buffer) void
write
(int b) void
write
(@NotNull ByteBuffer buffer) void
write
(@NotNull BinaryWriter writer) void
Writes the given writeable object into this writer.void
writeArray
(@NotNull Writeable[] writeables) Writes an array of writeable objects to this writer.void
writeBlockPosition
(int x, int y, int z) void
writeBlockPosition
(@NotNull Point point) void
writeBoolean
(boolean b) void
writeByte
(byte b) void
writeByteArray
(byte[] array) <T> void
writeByteList
(Collection<T> list, @NotNull BiConsumer<BinaryWriter, T> consumer) void
writeBytes
(byte @NotNull [] bytes) void
writeComponent
(@NotNull Component component) void
writeDouble
(double d) <L,
R> void writeEither
(Either<L, R> either, BiConsumer<BinaryWriter, L> leftWriter, BiConsumer<BinaryWriter, R> rightWriter) void
writeFloat
(float f) void
writeInt
(int i) void
writeItemStack
(@NotNull ItemStack itemStack) void
writeLong
(long l) void
writeLongArray
(long[] array) void
void
writeNullTerminatedString
(@NotNull String string, @NotNull Charset charset) void
writeShort
(short s) void
writeSizedString
(@NotNull String string) void
writeStringArray
(@NotNull String[] array) void
writeUnsignedShort
(int yourShort) void
void
writeVarInt
(int i) void
writeVarIntArray
(int[] array) <T> void
writeVarIntList
(Collection<T> list, @NotNull BiConsumer<BinaryWriter, T> consumer) void
writeVarLong
(long l) void
writeVarLongArray
(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
BinaryWriter
data
-
write
public void write(int b) - Specified by:
write
in classOutputStream
-
writeUnsignedShort
public void writeUnsignedShort(int yourShort) -
makeArray
Returns a byte[] with the contents written via BinaryWriter
-