Class NbtIo

java.lang.Object
net.minecraft.nbt.NbtIo

public class NbtIo extends Object
A set of utility functions for reading, writing, and scanning NBT files. Methods that do not require NbtSizeTracker accept any bytes of data, provided that its depth does not exceed 512.

When writing an invalid string, methods in this class will write an empty string instead of crashing, with the exception of writeUnsafe(net.minecraft.nbt.NbtElement, java.io.DataOutput) which throws instead.

Mappings:
Namespace Name
named net/minecraft/nbt/NbtIo
intermediary net/minecraft/class_2507
official vf
  • Field Details

    • OPEN_OPTIONS

      private static final OpenOption[] OPEN_OPTIONS
      Mappings:
      Namespace Name Mixin selector
      named OPEN_OPTIONS Lnet/minecraft/nbt/NbtIo;OPEN_OPTIONS:[Ljava/nio/file/OpenOption;
      intermediary field_47513 Lnet/minecraft/class_2507;field_47513:[Ljava/nio/file/OpenOption;
      official a Lvf;a:[Ljava/nio/file/OpenOption;
  • Constructor Details

    • NbtIo

      public NbtIo()
  • Method Details

    • readCompressed

      public static NbtCompound readCompressed(Path path, NbtSizeTracker tagSizeTracker) throws IOException
      Reads an NBT compound from Gzip-compressed file at path.
      Returns:
      the NBT compound from the file
      Throws:
      IOException - if the IO operation fails or if the root NBT element is not a compound
      NbtSizeValidationException - if the NBT is too deep
      See Also:
      Mappings:
      Namespace Name Mixin selector
      named readCompressed Lnet/minecraft/nbt/NbtIo;readCompressed(Ljava/nio/file/Path;Lnet/minecraft/nbt/NbtSizeTracker;)Lnet/minecraft/nbt/NbtCompound;
      intermediary method_30613 Lnet/minecraft/class_2507;method_30613(Ljava/nio/file/Path;Lnet/minecraft/class_2505;)Lnet/minecraft/class_2487;
      official a Lvf;a(Ljava/nio/file/Path;Lvb;)Lus;
    • decompress

      private static DataInputStream decompress(InputStream stream) throws IOException
      Returns a new input stream that decompresses the input stream.
      Returns:
      a new input stream that decompresses the input stream
      Throws:
      IOException
      Mappings:
      Namespace Name Mixin selector
      named decompress Lnet/minecraft/nbt/NbtIo;decompress(Ljava/io/InputStream;)Ljava/io/DataInputStream;
      intermediary method_40059 Lnet/minecraft/class_2507;method_40059(Ljava/io/InputStream;)Ljava/io/DataInputStream;
      official a Lvf;a(Ljava/io/InputStream;)Ljava/io/DataInputStream;
    • compress

      private static DataOutputStream compress(OutputStream stream) throws IOException
      Returns a new output stream that compresses the input stream.
      Returns:
      a new output stream that compresses the input stream
      Throws:
      IOException
      Mappings:
      Namespace Name Mixin selector
      named compress Lnet/minecraft/nbt/NbtIo;compress(Ljava/io/OutputStream;)Ljava/io/DataOutputStream;
      intermediary method_54906 Lnet/minecraft/class_2507;method_54906(Ljava/io/OutputStream;)Ljava/io/DataOutputStream;
      official a Lvf;a(Ljava/io/OutputStream;)Ljava/io/DataOutputStream;
    • readCompressed

      public static NbtCompound readCompressed(InputStream stream, NbtSizeTracker tagSizeTracker) throws IOException
      Reads an NBT compound from Gzip-compressed stream.
      Returns:
      the NBT compound from the stream
      Throws:
      IOException - if the IO operation fails or if the root NBT element is not a compound
      NbtSizeValidationException - if the NBT is too deep
      See Also:
      Mappings:
      Namespace Name Mixin selector
      named readCompressed Lnet/minecraft/nbt/NbtIo;readCompressed(Ljava/io/InputStream;Lnet/minecraft/nbt/NbtSizeTracker;)Lnet/minecraft/nbt/NbtCompound;
      intermediary method_10629 Lnet/minecraft/class_2507;method_10629(Ljava/io/InputStream;Lnet/minecraft/class_2505;)Lnet/minecraft/class_2487;
      official a Lvf;a(Ljava/io/InputStream;Lvb;)Lus;
    • scanCompressed

      public static void scanCompressed(Path path, NbtScanner scanner, NbtSizeTracker tracker) throws IOException
      Scans the compressed NBT file using scanner.
      Throws:
      IOException - if the IO operation fails
      NbtSizeValidationException - if the tracker's validation fails
      See Also:
      API Note:
      This method does not return the scan result; the user is expected to call the appropriate method of the NbtScanner subclasses, such as NbtCollector.getRoot().
      Mappings:
      Namespace Name Mixin selector
      named scanCompressed Lnet/minecraft/nbt/NbtIo;scanCompressed(Ljava/nio/file/Path;Lnet/minecraft/nbt/scanner/NbtScanner;Lnet/minecraft/nbt/NbtSizeTracker;)V
      intermediary method_40057 Lnet/minecraft/class_2507;method_40057(Ljava/nio/file/Path;Lnet/minecraft/class_6836;Lnet/minecraft/class_2505;)V
      official a Lvf;a(Ljava/nio/file/Path;Lvm;Lvb;)V
    • scanCompressed

      public static void scanCompressed(InputStream stream, NbtScanner scanner, NbtSizeTracker tracker) throws IOException
      Scans the compressed NBT stream using scanner.
      Throws:
      IOException - if the IO operation fails
      NbtSizeValidationException - if the tracker's validation fails
      See Also:
      API Note:
      This method does not return the scan result; the user is expected to call the appropriate method of the NbtScanner subclasses, such as NbtCollector.getRoot().
      Mappings:
      Namespace Name Mixin selector
      named scanCompressed Lnet/minecraft/nbt/NbtIo;scanCompressed(Ljava/io/InputStream;Lnet/minecraft/nbt/scanner/NbtScanner;Lnet/minecraft/nbt/NbtSizeTracker;)V
      intermediary method_40058 Lnet/minecraft/class_2507;method_40058(Ljava/io/InputStream;Lnet/minecraft/class_6836;Lnet/minecraft/class_2505;)V
      official a Lvf;a(Ljava/io/InputStream;Lvm;Lvb;)V
    • writeCompressed

      public static void writeCompressed(NbtCompound nbt, Path path) throws IOException
      Writes the Gzip-compressed nbt to the file at path.
      Throws:
      IOException - if the IO operation fails
      See Also:
      Mappings:
      Namespace Name Mixin selector
      named writeCompressed Lnet/minecraft/nbt/NbtIo;writeCompressed(Lnet/minecraft/nbt/NbtCompound;Ljava/nio/file/Path;)V
      intermediary method_30614 Lnet/minecraft/class_2507;method_30614(Lnet/minecraft/class_2487;Ljava/nio/file/Path;)V
      official a Lvf;a(Lus;Ljava/nio/file/Path;)V
    • writeCompressed

      public static void writeCompressed(NbtCompound nbt, OutputStream stream) throws IOException
      Writes the Gzip-compressed nbt to stream.
      Throws:
      IOException - if the IO operation fails
      See Also:
      Mappings:
      Namespace Name Mixin selector
      named writeCompressed Lnet/minecraft/nbt/NbtIo;writeCompressed(Lnet/minecraft/nbt/NbtCompound;Ljava/io/OutputStream;)V
      intermediary method_10634 Lnet/minecraft/class_2507;method_10634(Lnet/minecraft/class_2487;Ljava/io/OutputStream;)V
      official a Lvf;a(Lus;Ljava/io/OutputStream;)V
    • write

      public static void write(NbtCompound nbt, Path path) throws IOException
      Writes the nbt to the file at path.
      Throws:
      IOException - if the IO operation fails
      See Also:
      Mappings:
      Namespace Name Mixin selector
      named write Lnet/minecraft/nbt/NbtIo;write(Lnet/minecraft/nbt/NbtCompound;Ljava/nio/file/Path;)V
      intermediary method_10630 Lnet/minecraft/class_2507;method_10630(Lnet/minecraft/class_2487;Ljava/nio/file/Path;)V
      official b Lvf;b(Lus;Ljava/nio/file/Path;)V
    • read

      @Nullable public static @Nullable NbtCompound read(Path path) throws IOException
      Reads an NBT compound from the file atpath.
      Returns:
      the NBT compound from the file, or null if the file does not exist
      Throws:
      IOException - if the IO operation fails or if the root NBT element is not a compound
      NbtSizeValidationException - if the NBT is too deep
      Mappings:
      Namespace Name Mixin selector
      named read Lnet/minecraft/nbt/NbtIo;read(Ljava/nio/file/Path;)Lnet/minecraft/nbt/NbtCompound;
      intermediary method_10633 Lnet/minecraft/class_2507;method_10633(Ljava/nio/file/Path;)Lnet/minecraft/class_2487;
      official a Lvf;a(Ljava/nio/file/Path;)Lus;
    • readCompound

      public static NbtCompound readCompound(DataInput input) throws IOException
      Reads an NBT compound from input.
      Returns:
      the NBT compound from the input
      Throws:
      IOException - if the IO operation fails or if the root NBT element is not a compound
      NbtSizeValidationException - if the NBT is too deep
      Mappings:
      Namespace Name Mixin selector
      named readCompound Lnet/minecraft/nbt/NbtIo;readCompound(Ljava/io/DataInput;)Lnet/minecraft/nbt/NbtCompound;
      intermediary method_10627 Lnet/minecraft/class_2507;method_10627(Ljava/io/DataInput;)Lnet/minecraft/class_2487;
      official a Lvf;a(Ljava/io/DataInput;)Lus;
    • readCompound

      public static NbtCompound readCompound(DataInput input, NbtSizeTracker tracker) throws IOException
      Reads an NBT compound from input.
      Returns:
      the NBT compound from the input
      Throws:
      IOException - if the IO operation fails or if the root NBT element is not a compound
      NbtSizeValidationException - if the tracker's validation fails
      Mappings:
      Namespace Name Mixin selector
      named readCompound Lnet/minecraft/nbt/NbtIo;readCompound(Ljava/io/DataInput;Lnet/minecraft/nbt/NbtSizeTracker;)Lnet/minecraft/nbt/NbtCompound;
      intermediary method_10625 Lnet/minecraft/class_2507;method_10625(Ljava/io/DataInput;Lnet/minecraft/class_2505;)Lnet/minecraft/class_2487;
      official a Lvf;a(Ljava/io/DataInput;Lvb;)Lus;
    • writeCompound

      public static void writeCompound(NbtCompound nbt, DataOutput output) throws IOException
      Writes the nbt to output.
      Throws:
      IOException - if the IO operation fails
      See Also:
      Mappings:
      Namespace Name Mixin selector
      named writeCompound Lnet/minecraft/nbt/NbtIo;writeCompound(Lnet/minecraft/nbt/NbtCompound;Ljava/io/DataOutput;)V
      intermediary method_10628 Lnet/minecraft/class_2507;method_10628(Lnet/minecraft/class_2487;Ljava/io/DataOutput;)V
      official a Lvf;a(Lus;Ljava/io/DataOutput;)V
    • scan

      public static void scan(DataInput input, NbtScanner scanner, NbtSizeTracker tracker) throws IOException
      Scans the NBT input using scanner.
      Throws:
      IOException - if the IO operation fails
      NbtSizeValidationException - if the tracker's validation fails
      API Note:
      This method does not return the scan result; the user is expected to call the appropriate method of the NbtScanner subclasses, such as NbtCollector.getRoot().
      Mappings:
      Namespace Name Mixin selector
      named scan Lnet/minecraft/nbt/NbtIo;scan(Ljava/io/DataInput;Lnet/minecraft/nbt/scanner/NbtScanner;Lnet/minecraft/nbt/NbtSizeTracker;)V
      intermediary method_39855 Lnet/minecraft/class_2507;method_39855(Ljava/io/DataInput;Lnet/minecraft/class_6836;Lnet/minecraft/class_2505;)V
      official a Lvf;a(Ljava/io/DataInput;Lvm;Lvb;)V
    • read

      public static NbtElement read(DataInput input, NbtSizeTracker tracker) throws IOException
      Reads an NBT element from input. Unlike readCompound(DataInput, NbtSizeTracker), the element does not have to be a compound.
      Returns:
      the NBT element from the input
      Throws:
      IOException - if the IO operation fails
      NbtSizeValidationException - if the tracker's validation fails
      Mappings:
      Namespace Name Mixin selector
      named read Lnet/minecraft/nbt/NbtIo;read(Ljava/io/DataInput;Lnet/minecraft/nbt/NbtSizeTracker;)Lnet/minecraft/nbt/NbtElement;
      intermediary method_52894 Lnet/minecraft/class_2507;method_52894(Ljava/io/DataInput;Lnet/minecraft/class_2505;)Lnet/minecraft/class_2520;
      official b Lvf;b(Ljava/io/DataInput;Lvb;)Lvp;
    • writeForPacket

      public static void writeForPacket(NbtElement nbt, DataOutput output) throws IOException
      Writes the nbt to output. The output is the byte indicating the element type, followed by the NBT data.
      Throws:
      IOException - if the IO operation fails
      See Also:
      API Note:
      In vanilla, this is used exclusively in networking.
      Mappings:
      Namespace Name Mixin selector
      named writeForPacket Lnet/minecraft/nbt/NbtIo;writeForPacket(Lnet/minecraft/nbt/NbtElement;Ljava/io/DataOutput;)V
      intermediary method_52893 Lnet/minecraft/class_2507;method_52893(Lnet/minecraft/class_2520;Ljava/io/DataOutput;)V
      official a Lvf;a(Lvp;Ljava/io/DataOutput;)V
    • writeUnsafe

      public static void writeUnsafe(NbtElement nbt, DataOutput output) throws IOException
      Writes the nbt to output. The output is the byte indicating the element type, followed by an empty string and the NBT data.

      When writing an invalid string, this method will throw an error, unlike other methods.

      Throws:
      IOException - if the IO operation fails
      See Also:
      Mappings:
      Namespace Name Mixin selector
      named writeUnsafe Lnet/minecraft/nbt/NbtIo;writeUnsafe(Lnet/minecraft/nbt/NbtElement;Ljava/io/DataOutput;)V
      intermediary method_10631 Lnet/minecraft/class_2507;method_10631(Lnet/minecraft/class_2520;Ljava/io/DataOutput;)V
      official b Lvf;b(Lvp;Ljava/io/DataOutput;)V
    • write

      public static void write(NbtElement nbt, DataOutput output) throws IOException
      Writes the nbt to output. The output is the byte indicating the element type, followed by an empty string and the NBT data.

      When writing an invalid string, this method will write an empty string instead of crashing.

      Throws:
      IOException - if the IO operation fails
      See Also:
      Mappings:
      Namespace Name Mixin selector
      named write Lnet/minecraft/nbt/NbtIo;write(Lnet/minecraft/nbt/NbtElement;Ljava/io/DataOutput;)V
      intermediary method_55324 Lnet/minecraft/class_2507;method_55324(Lnet/minecraft/class_2520;Ljava/io/DataOutput;)V
      official c Lvf;c(Lvp;Ljava/io/DataOutput;)V
    • readElement

      private static NbtElement readElement(DataInput input, NbtSizeTracker tracker) throws IOException
      Throws:
      IOException
      Mappings:
      Namespace Name Mixin selector
      named readElement Lnet/minecraft/nbt/NbtIo;readElement(Ljava/io/DataInput;Lnet/minecraft/nbt/NbtSizeTracker;)Lnet/minecraft/nbt/NbtElement;
      intermediary method_10626 Lnet/minecraft/class_2507;method_10626(Ljava/io/DataInput;Lnet/minecraft/class_2505;)Lnet/minecraft/class_2520;
      official c Lvf;c(Ljava/io/DataInput;Lvb;)Lvp;
    • readElement

      private static NbtElement readElement(DataInput input, NbtSizeTracker tracker, byte typeId)
      Mappings:
      Namespace Name Mixin selector
      named readElement Lnet/minecraft/nbt/NbtIo;readElement(Ljava/io/DataInput;Lnet/minecraft/nbt/NbtSizeTracker;B)Lnet/minecraft/nbt/NbtElement;
      intermediary method_52892 Lnet/minecraft/class_2507;method_52892(Ljava/io/DataInput;Lnet/minecraft/class_2505;B)Lnet/minecraft/class_2520;
      official a Lvf;a(Ljava/io/DataInput;Lvb;B)Lvp;