Class TStreamTools

java.lang.Object
com.saicone.rtag.stream.TStreamTools

public class TStreamTools extends Object
Class to invoke NbtIo methods across versions.
  • Method Details

    • getReadLimiter

      public static Object getReadLimiter()
      Get a NbtAccounter instance with no limit to read NBT data.
      Returns:
      A NbtAccounter instance.
    • getDataInput

      public static DataInputStream getDataInput(InputStream input) throws IOException
      Get the required data input stream to read.
      This method will use the new enhanced FastBufferedInputStream if the server version is 1.18 or higher, so this method checks if the provided InputStream is GZIP formatted to parse it correctly.
      Parameters:
      input - The InputStream to parse.
      Returns:
      A parsed input stream.
      Throws:
      IOException - if an I/O error occurs.
    • getDataInput

      public static DataInputStream getDataInput(InputStream input, boolean gzip) throws IOException
      Get the required data input stream to read.
      This method will use the new enhanced FastBufferedInputStream if the server version is 1.18 or higher.
      Parameters:
      input - The InputStream to parse.
      gzip - Set to true if the InputStream is on GZIP format.
      Returns:
      A parsed input stream.
      Throws:
      IOException - if an I/O error occurs.
    • isGzipFormat

      public static boolean isGzipFormat(File file) throws IOException
      Check if the provided file is a GZIP file.
      Parameters:
      file - The file to check.
      Returns:
      true if the file is GZIP formatted, false otherwise.
      Throws:
      IOException - if an I/O error occurs.
    • isGzipFormat

      public static boolean isGzipFormat(InputStream input) throws IOException
      Check if the provided InputStream is a GZIP formatted input.
      Parameters:
      input - The InputStream to check.
      Returns:
      true if the input stream is GZIP formatted, false otherwise.
      Throws:
      IOException - if an I/O error occurs.
    • isGzipHeader

      public static boolean isGzipHeader(byte[] bytes)
      Check if the provided byte array has GZIP header.
      Parameters:
      bytes - The byte array to check.
      Returns:
      true if it contains GZIP header.
    • isGzipHeader

      public static boolean isGzipHeader(int ID1, int ID2)
      Check if the provided ID1 and ID2 are the same has GZIP magic.
      Parameters:
      ID1 - The first ID.
      ID2 - The second ID.
      Returns:
      true if the IDs are the same has GZIP magic.
    • isNbtHeader

      public static boolean isNbtHeader(byte[] bytes)
      Check if the provided byte array has NBT header.
      Parameters:
      bytes - The byte array to check.
      Returns:
      true of it contains NBT header.
    • read

      public static Object read(File file) throws IOException
      Read Tag from file.
      Parameters:
      file - File to read.
      Returns:
      A Tag instance.
      Throws:
      IOException - if root object is not a nbt tag.
    • read

      public static Object read(byte[] bytes) throws IOException
      Read Tag from byte array.
      Parameters:
      bytes - The byte array to read.
      Returns:
      A Tag instance.
      Throws:
      IOException - if root object is not a nbt tag.
    • read

      public static Object read(InputStream input) throws IOException
      Read Tag from InputStream.
      Parameters:
      input - InputStream to read.
      Returns:
      A Tag instance.
      Throws:
      IOException - if root object is not a nbt tag.
    • read

      public static Object read(DataInputStream input) throws IOException
      Read Tag from DataInputStream.
      Parameters:
      input - DataInputStream to read.
      Returns:
      A Tag instance.
      Throws:
      IOException - if root object is not a nbt tag.
    • read

      public static Object read(DataInput input) throws IOException
      Read Tag from DataInput.
      Parameters:
      input - DataInput to read.
      Returns:
      A Tag instance.
      Throws:
      IOException - if root object is not a nbt tag.
    • write

      public static void write(Object tag, File file) throws IOException
      Write Tag to File.
      Parameters:
      tag - The tag to write.
      file - File to write in.
      Throws:
      IOException - if an I/O error occurs while writing.
    • write

      public static void write(Object tag, OutputStream output) throws IOException
      Write Tag to OutputStream.
      Parameters:
      tag - The tag to write.
      output - OutputStream to write in.
      Throws:
      IOException - if an I/O error occurs while writing.
    • write

      public static void write(Object tag, DataOutputStream output) throws IOException
      Write Tag to DataOutputStream.
      Parameters:
      tag - The tag to write.
      output - DataOutputStream to write in.
      Throws:
      IOException - if an I/O error occurs while writing.
    • write

      public static void write(Object tag, DataOutput output) throws IOException
      Write Tag to DataOutput.
      Parameters:
      tag - The tag to write.
      output - DataOutput to write in.
      Throws:
      IOException - if an I/O error occurs while writing.