Package net.minecraft.nbt
Class NbtIo
java.lang.Object
net.minecraft.nbt.NbtIo
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 official taintermediary net/minecraft/class_2507named net/minecraft/nbt/NbtIo
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static DataOutputStreamcompress(OutputStream stream) Returns a new output stream that compresses the inputstream.private static DataInputStreamdecompress(InputStream stream) Returns a new input stream that decompresses the inputstream.static NbtElementread(DataInput input, NbtSizeTracker tracker) Reads an NBT element frominput.static @Nullable NbtCompoundReads an NBT compound from the file atpath.static NbtCompoundreadCompound(DataInput input) Reads an NBT compound frominput.static NbtCompoundreadCompound(DataInput input, NbtSizeTracker tracker) Reads an NBT compound frominput.static NbtCompoundreadCompressed(InputStream stream, NbtSizeTracker tagSizeTracker) Reads an NBT compound from Gzip-compressedstream.static NbtCompoundreadCompressed(Path path, NbtSizeTracker tagSizeTracker) Reads an NBT compound from Gzip-compressed file atpath.private static NbtElementreadElement(DataInput input, NbtSizeTracker tracker) private static NbtElementreadElement(DataInput input, NbtSizeTracker tracker, byte typeId) static voidscan(DataInput input, NbtScanner scanner, NbtSizeTracker tracker) Scans the NBT input usingscanner.static voidscanCompressed(InputStream stream, NbtScanner scanner, NbtSizeTracker tracker) Scans the compressed NBT stream usingscanner.static voidscanCompressed(Path path, NbtScanner scanner, NbtSizeTracker tracker) Scans the compressed NBT file usingscanner.static voidwrite(NbtCompound nbt, Path path) Writes thenbtto the file atpath.static voidwrite(NbtElement nbt, DataOutput output) Writes thenbttooutput.static voidwriteCompound(NbtCompound nbt, DataOutput output) Writes thenbttooutput.static voidwriteCompressed(NbtCompound nbt, OutputStream stream) Writes the Gzip-compressednbttostream.static voidwriteCompressed(NbtCompound nbt, Path path) Writes the Gzip-compressednbtto the file atpath.static voidwriteForPacket(NbtElement nbt, DataOutput output) Writes thenbttooutput.static voidwriteUnsafe(NbtElement nbt, DataOutput output) Writes thenbttooutput.
-
Field Details
-
OPEN_OPTIONS
- Mappings:
Namespace Name Mixin selector official aLta;a:[Ljava/nio/file/OpenOption;intermediary field_47513Lnet/minecraft/class_2507;field_47513:[Ljava/nio/file/OpenOption;named OPEN_OPTIONSLnet/minecraft/nbt/NbtIo;OPEN_OPTIONS:[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 atpath.- Returns:
- the NBT compound from the file
- Throws:
IOException- if the IO operation fails or if the root NBT element is not a compoundNbtSizeValidationException- if the NBT is too deep- See Also:
- Mappings:
Namespace Name Mixin selector official aLta;a(Ljava/nio/file/Path;Lsw;)Lsn;intermediary method_30613Lnet/minecraft/class_2507;method_30613(Ljava/nio/file/Path;Lnet/minecraft/class_2505;)Lnet/minecraft/class_2487;named readCompressedLnet/minecraft/nbt/NbtIo;readCompressed(Ljava/nio/file/Path;Lnet/minecraft/nbt/NbtSizeTracker;)Lnet/minecraft/nbt/NbtCompound;
-
decompress
Returns a new input stream that decompresses the inputstream.- Returns:
- a new input stream that decompresses the input
stream - Throws:
IOException- Mappings:
Namespace Name Mixin selector official aLta;a(Ljava/io/InputStream;)Ljava/io/DataInputStream;intermediary method_40059Lnet/minecraft/class_2507;method_40059(Ljava/io/InputStream;)Ljava/io/DataInputStream;named decompressLnet/minecraft/nbt/NbtIo;decompress(Ljava/io/InputStream;)Ljava/io/DataInputStream;
-
compress
Returns a new output stream that compresses the inputstream.- Returns:
- a new output stream that compresses the input
stream - Throws:
IOException- Mappings:
Namespace Name Mixin selector official aLta;a(Ljava/io/OutputStream;)Ljava/io/DataOutputStream;intermediary method_54906Lnet/minecraft/class_2507;method_54906(Ljava/io/OutputStream;)Ljava/io/DataOutputStream;named compressLnet/minecraft/nbt/NbtIo;compress(Ljava/io/OutputStream;)Ljava/io/DataOutputStream;
-
readCompressed
public static NbtCompound readCompressed(InputStream stream, NbtSizeTracker tagSizeTracker) throws IOException Reads an NBT compound from Gzip-compressedstream.- Returns:
- the NBT compound from the stream
- Throws:
IOException- if the IO operation fails or if the root NBT element is not a compoundNbtSizeValidationException- if the NBT is too deep- See Also:
- Mappings:
Namespace Name Mixin selector official aLta;a(Ljava/io/InputStream;Lsw;)Lsn;intermediary method_10629Lnet/minecraft/class_2507;method_10629(Ljava/io/InputStream;Lnet/minecraft/class_2505;)Lnet/minecraft/class_2487;named readCompressedLnet/minecraft/nbt/NbtIo;readCompressed(Ljava/io/InputStream;Lnet/minecraft/nbt/NbtSizeTracker;)Lnet/minecraft/nbt/NbtCompound;
-
scanCompressed
public static void scanCompressed(Path path, NbtScanner scanner, NbtSizeTracker tracker) throws IOException Scans the compressed NBT file usingscanner.- Throws:
IOException- if the IO operation failsNbtSizeValidationException- if thetracker'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
NbtScannersubclasses, such asNbtCollector.getRoot(). - Mappings:
Namespace Name Mixin selector official aLta;a(Ljava/nio/file/Path;Lth;Lsw;)Vintermediary method_40057Lnet/minecraft/class_2507;method_40057(Ljava/nio/file/Path;Lnet/minecraft/class_6836;Lnet/minecraft/class_2505;)Vnamed scanCompressedLnet/minecraft/nbt/NbtIo;scanCompressed(Ljava/nio/file/Path;Lnet/minecraft/nbt/scanner/NbtScanner;Lnet/minecraft/nbt/NbtSizeTracker;)V
-
scanCompressed
public static void scanCompressed(InputStream stream, NbtScanner scanner, NbtSizeTracker tracker) throws IOException Scans the compressed NBT stream usingscanner.- Throws:
IOException- if the IO operation failsNbtSizeValidationException- if thetracker'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
NbtScannersubclasses, such asNbtCollector.getRoot(). - Mappings:
Namespace Name Mixin selector official aLta;a(Ljava/io/InputStream;Lth;Lsw;)Vintermediary method_40058Lnet/minecraft/class_2507;method_40058(Ljava/io/InputStream;Lnet/minecraft/class_6836;Lnet/minecraft/class_2505;)Vnamed scanCompressedLnet/minecraft/nbt/NbtIo;scanCompressed(Ljava/io/InputStream;Lnet/minecraft/nbt/scanner/NbtScanner;Lnet/minecraft/nbt/NbtSizeTracker;)V
-
writeCompressed
Writes the Gzip-compressednbtto the file atpath.- Throws:
IOException- if the IO operation fails- See Also:
- Mappings:
Namespace Name Mixin selector official aLta;a(Lsn;Ljava/nio/file/Path;)Vintermediary method_30614Lnet/minecraft/class_2507;method_30614(Lnet/minecraft/class_2487;Ljava/nio/file/Path;)Vnamed writeCompressedLnet/minecraft/nbt/NbtIo;writeCompressed(Lnet/minecraft/nbt/NbtCompound;Ljava/nio/file/Path;)V
-
writeCompressed
Writes the Gzip-compressednbttostream.- Throws:
IOException- if the IO operation fails- See Also:
- Mappings:
Namespace Name Mixin selector official aLta;a(Lsn;Ljava/io/OutputStream;)Vintermediary method_10634Lnet/minecraft/class_2507;method_10634(Lnet/minecraft/class_2487;Ljava/io/OutputStream;)Vnamed writeCompressedLnet/minecraft/nbt/NbtIo;writeCompressed(Lnet/minecraft/nbt/NbtCompound;Ljava/io/OutputStream;)V
-
write
Writes thenbtto the file atpath.- Throws:
IOException- if the IO operation fails- See Also:
- Mappings:
Namespace Name Mixin selector official bLta;b(Lsn;Ljava/nio/file/Path;)Vintermediary method_10630Lnet/minecraft/class_2507;method_10630(Lnet/minecraft/class_2487;Ljava/nio/file/Path;)Vnamed writeLnet/minecraft/nbt/NbtIo;write(Lnet/minecraft/nbt/NbtCompound;Ljava/nio/file/Path;)V
-
read
Reads an NBT compound from the file atpath.- Returns:
- the NBT compound from the file, or
nullif the file does not exist - Throws:
IOException- if the IO operation fails or if the root NBT element is not a compoundNbtSizeValidationException- if the NBT is too deep- Mappings:
Namespace Name Mixin selector official aLta;a(Ljava/nio/file/Path;)Lsn;intermediary method_10633Lnet/minecraft/class_2507;method_10633(Ljava/nio/file/Path;)Lnet/minecraft/class_2487;named readLnet/minecraft/nbt/NbtIo;read(Ljava/nio/file/Path;)Lnet/minecraft/nbt/NbtCompound;
-
readCompound
Reads an NBT compound frominput.- Returns:
- the NBT compound from the input
- Throws:
IOException- if the IO operation fails or if the root NBT element is not a compoundNbtSizeValidationException- if the NBT is too deep- Mappings:
Namespace Name Mixin selector official aLta;a(Ljava/io/DataInput;)Lsn;intermediary method_10627Lnet/minecraft/class_2507;method_10627(Ljava/io/DataInput;)Lnet/minecraft/class_2487;named readCompoundLnet/minecraft/nbt/NbtIo;readCompound(Ljava/io/DataInput;)Lnet/minecraft/nbt/NbtCompound;
-
readCompound
Reads an NBT compound frominput.- Returns:
- the NBT compound from the input
- Throws:
IOException- if the IO operation fails or if the root NBT element is not a compoundNbtSizeValidationException- if thetracker's validation fails- Mappings:
Namespace Name Mixin selector official aLta;a(Ljava/io/DataInput;Lsw;)Lsn;intermediary method_10625Lnet/minecraft/class_2507;method_10625(Ljava/io/DataInput;Lnet/minecraft/class_2505;)Lnet/minecraft/class_2487;named readCompoundLnet/minecraft/nbt/NbtIo;readCompound(Ljava/io/DataInput;Lnet/minecraft/nbt/NbtSizeTracker;)Lnet/minecraft/nbt/NbtCompound;
-
writeCompound
Writes thenbttooutput.- Throws:
IOException- if the IO operation fails- See Also:
- Mappings:
Namespace Name Mixin selector official aLta;a(Lsn;Ljava/io/DataOutput;)Vintermediary method_10628Lnet/minecraft/class_2507;method_10628(Lnet/minecraft/class_2487;Ljava/io/DataOutput;)Vnamed writeCompoundLnet/minecraft/nbt/NbtIo;writeCompound(Lnet/minecraft/nbt/NbtCompound;Ljava/io/DataOutput;)V
-
scan
public static void scan(DataInput input, NbtScanner scanner, NbtSizeTracker tracker) throws IOException Scans the NBT input usingscanner.- Throws:
IOException- if the IO operation failsNbtSizeValidationException- if thetracker's validation fails- API Note:
- This method does not return the scan result; the user is expected
to call the appropriate method of the
NbtScannersubclasses, such asNbtCollector.getRoot(). - Mappings:
Namespace Name Mixin selector official aLta;a(Ljava/io/DataInput;Lth;Lsw;)Vintermediary method_39855Lnet/minecraft/class_2507;method_39855(Ljava/io/DataInput;Lnet/minecraft/class_6836;Lnet/minecraft/class_2505;)Vnamed scanLnet/minecraft/nbt/NbtIo;scan(Ljava/io/DataInput;Lnet/minecraft/nbt/scanner/NbtScanner;Lnet/minecraft/nbt/NbtSizeTracker;)V
-
read
Reads an NBT element frominput. UnlikereadCompound(DataInput, NbtSizeTracker), the element does not have to be a compound.- Returns:
- the NBT element from the input
- Throws:
IOException- if the IO operation failsNbtSizeValidationException- if thetracker's validation fails- Mappings:
Namespace Name Mixin selector official bLta;b(Ljava/io/DataInput;Lsw;)Ltk;intermediary method_52894Lnet/minecraft/class_2507;method_52894(Ljava/io/DataInput;Lnet/minecraft/class_2505;)Lnet/minecraft/class_2520;named readLnet/minecraft/nbt/NbtIo;read(Ljava/io/DataInput;Lnet/minecraft/nbt/NbtSizeTracker;)Lnet/minecraft/nbt/NbtElement;
-
writeForPacket
Writes thenbttooutput. 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 official aLta;a(Ltk;Ljava/io/DataOutput;)Vintermediary method_52893Lnet/minecraft/class_2507;method_52893(Lnet/minecraft/class_2520;Ljava/io/DataOutput;)Vnamed writeForPacketLnet/minecraft/nbt/NbtIo;writeForPacket(Lnet/minecraft/nbt/NbtElement;Ljava/io/DataOutput;)V
-
writeUnsafe
Writes thenbttooutput. 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 official bLta;b(Ltk;Ljava/io/DataOutput;)Vintermediary method_10631Lnet/minecraft/class_2507;method_10631(Lnet/minecraft/class_2520;Ljava/io/DataOutput;)Vnamed writeUnsafeLnet/minecraft/nbt/NbtIo;writeUnsafe(Lnet/minecraft/nbt/NbtElement;Ljava/io/DataOutput;)V
-
write
Writes thenbttooutput. 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 official cLta;c(Ltk;Ljava/io/DataOutput;)Vintermediary method_55324Lnet/minecraft/class_2507;method_55324(Lnet/minecraft/class_2520;Ljava/io/DataOutput;)Vnamed writeLnet/minecraft/nbt/NbtIo;write(Lnet/minecraft/nbt/NbtElement;Ljava/io/DataOutput;)V
-
readElement
- Throws:
IOException- Mappings:
Namespace Name Mixin selector official cLta;c(Ljava/io/DataInput;Lsw;)Ltk;intermediary method_10626Lnet/minecraft/class_2507;method_10626(Ljava/io/DataInput;Lnet/minecraft/class_2505;)Lnet/minecraft/class_2520;named readElementLnet/minecraft/nbt/NbtIo;readElement(Ljava/io/DataInput;Lnet/minecraft/nbt/NbtSizeTracker;)Lnet/minecraft/nbt/NbtElement;
-
readElement
- Mappings:
Namespace Name Mixin selector official aLta;a(Ljava/io/DataInput;Lsw;B)Ltk;intermediary method_52892Lnet/minecraft/class_2507;method_52892(Ljava/io/DataInput;Lnet/minecraft/class_2505;B)Lnet/minecraft/class_2520;named readElementLnet/minecraft/nbt/NbtIo;readElement(Ljava/io/DataInput;Lnet/minecraft/nbt/NbtSizeTracker;B)Lnet/minecraft/nbt/NbtElement;
-