Package net.minestom.server.utils.binary
Class BinaryReader
java.lang.Object
java.io.InputStream
net.minestom.server.utils.binary.BinaryReader
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class BinaryReader
extends java.io.InputStream
Class used to read from a byte array.
WARNING: not thread-safe.
-
Constructor Summary
Constructors Constructor Description BinaryReader(byte[] bytes)
BinaryReader(io.netty.buffer.ByteBuf buffer)
-
Method Summary
Modifier and Type Method Description int
available()
io.netty.buffer.ByteBuf
getBuffer()
byte[]
getRemainingBytes()
int
read()
BlockPosition
readBlockPosition()
boolean
readBoolean()
byte
readByte()
byte[]
readBytes(int length)
char
readChar()
double
readDouble()
float
readFloat()
int
readInteger()
JsonMessage
readJsonMessage(int maxLength)
long
readLong()
short
readShort()
java.lang.String
readSizedString(int maxLength)
Reads a string size by a var-int.java.lang.String[]
readSizedStringArray(int maxLength)
ItemStack
readSlot()
Tries to read anItemStack
.org.jglrxavpok.hephaistos.nbt.NBT
readTag()
int
readUnsignedShort()
java.util.UUID
readUuid()
int
readVarInt()
int[]
readVarIntArray()
-
Constructor Details
-
BinaryReader
public BinaryReader(@NotNull io.netty.buffer.ByteBuf buffer) -
BinaryReader
public BinaryReader(byte[] bytes)
-
-
Method Details
-
readVarInt
public int readVarInt() -
readBoolean
public boolean readBoolean() -
readByte
public byte readByte() -
readShort
public short readShort() -
readChar
public char readChar() -
readUnsignedShort
public int readUnsignedShort() -
readInteger
public int readInteger() -
readLong
public long readLong() -
readFloat
public float readFloat() -
readDouble
public double readDouble() -
readSizedString
public java.lang.String readSizedString(int maxLength)Reads a string size by a var-int.If the string length is higher than
maxLength
, the code throws an exception and the string bytes are not read.- Parameters:
maxLength
- the max length of the string- Returns:
- the string
- Throws:
java.lang.IllegalStateException
- if the string length is higher thanmaxLength
-
readBytes
public byte[] readBytes(int length) -
readSizedStringArray
public java.lang.String[] readSizedStringArray(int maxLength) -
readVarIntArray
public int[] readVarIntArray() -
getRemainingBytes
public byte[] getRemainingBytes() -
readBlockPosition
-
readUuid
public java.util.UUID readUuid() -
readSlot
Tries to read anItemStack
.- Returns:
- the read item
- Throws:
java.lang.NullPointerException
- if the item could not get read
-
readJsonMessage
-
getBuffer
public io.netty.buffer.ByteBuf getBuffer() -
read
public int read()- Specified by:
read
in classjava.io.InputStream
-
available
public int available()- Overrides:
available
in classjava.io.InputStream
-
readTag
public org.jglrxavpok.hephaistos.nbt.NBT readTag() throws java.io.IOException, org.jglrxavpok.hephaistos.nbt.NBTException- Throws:
java.io.IOException
org.jglrxavpok.hephaistos.nbt.NBTException
-