Class BinaryWriter

All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class BinaryWriter extends OutputStream
Class used to write to a byte array. WARNING: not thread-safe.
  • Constructor Details

    • BinaryWriter

      public BinaryWriter(@NotNull @NotNull NetworkBuffer buffer)
    • BinaryWriter

      public BinaryWriter(@NotNull @NotNull ByteBuffer buffer)
    • BinaryWriter

      public BinaryWriter(int initialCapacity)
    • BinaryWriter

      public BinaryWriter()
  • Method Details

    • view

      @Experimental public static BinaryWriter view(ByteBuffer buffer)
    • writeComponent

      public void writeComponent(@NotNull @NotNull Component component)
    • 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

      public void writeSizedString(@NotNull @NotNull String string)
    • writeNullTerminatedString

      public void writeNullTerminatedString(@NotNull @NotNull String string, @NotNull @NotNull Charset charset)
    • 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

      public void writeStringArray(@NotNull @NotNull String[] array)
    • writeUuid

      public void writeUuid(@NotNull @NotNull UUID uuid)
    • writeBlockPosition

      public void writeBlockPosition(@NotNull @NotNull Point point)
    • writeBlockPosition

      public void writeBlockPosition(int x, int y, int z)
    • writeItemStack

      public void writeItemStack(@NotNull @NotNull ItemStack itemStack)
    • 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

      public void write(@NotNull @NotNull Writeable writeable)
      Writes the given writeable object into this writer.
      writeable - the object to write
    • write

      public void write(@NotNull @NotNull ByteBuffer buffer)
    • write

      public void write(@NotNull @NotNull BinaryWriter writer)
    • writeArray

      public void writeArray(@NotNull @NotNull Writeable[] writeables)
      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.
      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.
      the byte array containing all the BinaryWriter data
    • write

      public void write(int b)
      Specified by:
      write in class OutputStream
    • writeUnsignedShort

      public void writeUnsignedShort(int yourShort)
    • makeArray

      public static byte[] makeArray(@NotNull @NotNull Consumer<@NotNull BinaryWriter> writing)
      Returns a byte[] with the contents written via BinaryWriter