NbtIo.java

net.minecraft.nbt.NbtIo

信息

  • 全限定名:net.minecraft.nbt.NbtIo
  • 类型:public class
  • 包:net.minecraft.nbt
  • 源码路径:src/main/java/net/minecraft/nbt/NbtIo.java
  • 起始行号:L26
  • 职责:

    TODO

字段/常量

  • SYNC_OUTPUT_OPTIONS
    • 类型: OpenOption[]
    • 修饰符: private static final
    • 源码定位: L27
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.nbt.NbtIo.StringFallbackDataOutput
    • 类型: class
    • 修饰符: public static
    • 源码定位: L201
    • 说明:

      TODO

构造器

方法

下面的方法块按源码顺序生成。

public static CompoundTag readCompressed(Path file, NbtAccounter accounter) @ L31

  • 方法名:readCompressed
  • 源码定位:L31
  • 返回类型:CompoundTag
  • 修饰符:public static

参数:

  • file: Path
  • accounter: NbtAccounter

说明:

TODO

private static DataInputStream createDecompressorStream(InputStream in) @ L43

  • 方法名:createDecompressorStream
  • 源码定位:L43
  • 返回类型:DataInputStream
  • 修饰符:private static

参数:

  • in: InputStream

说明:

TODO

private static DataOutputStream createCompressorStream(OutputStream out) @ L47

  • 方法名:createCompressorStream
  • 源码定位:L47
  • 返回类型:DataOutputStream
  • 修饰符:private static

参数:

  • out: OutputStream

说明:

TODO

public static CompoundTag readCompressed(InputStream in, NbtAccounter accounter) @ L51

  • 方法名:readCompressed
  • 源码定位:L51
  • 返回类型:CompoundTag
  • 修饰符:public static

参数:

  • in: InputStream
  • accounter: NbtAccounter

说明:

TODO

public static void parseCompressed(Path file, StreamTagVisitor output, NbtAccounter accounter) @ L60

  • 方法名:parseCompressed
  • 源码定位:L60
  • 返回类型:void
  • 修饰符:public static

参数:

  • file: Path
  • output: StreamTagVisitor
  • accounter: NbtAccounter

说明:

TODO

public static void parseCompressed(InputStream in, StreamTagVisitor output, NbtAccounter accounter) @ L69

  • 方法名:parseCompressed
  • 源码定位:L69
  • 返回类型:void
  • 修饰符:public static

参数:

  • in: InputStream
  • output: StreamTagVisitor
  • accounter: NbtAccounter

说明:

TODO

public static void writeCompressed(CompoundTag tag, Path file) @ L75

  • 方法名:writeCompressed
  • 源码定位:L75
  • 返回类型:void
  • 修饰符:public static

参数:

  • tag: CompoundTag
  • file: Path

说明:

TODO

public static void writeCompressed(CompoundTag tag, OutputStream out) @ L84

  • 方法名:writeCompressed
  • 源码定位:L84
  • 返回类型:void
  • 修饰符:public static

参数:

  • tag: CompoundTag
  • out: OutputStream

说明:

TODO

public static void write(CompoundTag tag, Path file) @ L90

  • 方法名:write
  • 源码定位:L90
  • 返回类型:void
  • 修饰符:public static

参数:

  • tag: CompoundTag
  • file: Path

说明:

TODO

public static CompoundTag read(Path file) @ L100

  • 方法名:read
  • 源码定位:L100
  • 返回类型:CompoundTag
  • 修饰符:public static

参数:

  • file: Path

说明:

TODO

public static CompoundTag read(DataInput input) @ L116

  • 方法名:read
  • 源码定位:L116
  • 返回类型:CompoundTag
  • 修饰符:public static

参数:

  • input: DataInput

说明:

TODO

public static CompoundTag read(DataInput input, NbtAccounter accounter) @ L120

  • 方法名:read
  • 源码定位:L120
  • 返回类型:CompoundTag
  • 修饰符:public static

参数:

  • input: DataInput
  • accounter: NbtAccounter

说明:

TODO

public static void write(CompoundTag tag, DataOutput output) @ L129

  • 方法名:write
  • 源码定位:L129
  • 返回类型:void
  • 修饰符:public static

参数:

  • tag: CompoundTag
  • output: DataOutput

说明:

TODO

public static void parse(DataInput input, StreamTagVisitor output, NbtAccounter accounter) @ L133

  • 方法名:parse
  • 源码定位:L133
  • 返回类型:void
  • 修饰符:public static

参数:

  • input: DataInput
  • output: StreamTagVisitor
  • accounter: NbtAccounter

说明:

TODO

public static Tag readAnyTag(DataInput input, NbtAccounter accounter) @ L155

  • 方法名:readAnyTag
  • 源码定位:L155
  • 返回类型:Tag
  • 修饰符:public static

参数:

  • input: DataInput
  • accounter: NbtAccounter

说明:

TODO

public static void writeAnyTag(Tag tag, DataOutput output) @ L160

  • 方法名:writeAnyTag
  • 源码定位:L160
  • 返回类型:void
  • 修饰符:public static

参数:

  • tag: Tag
  • output: DataOutput

说明:

TODO

public static void writeUnnamedTag(Tag tag, DataOutput output) @ L167

  • 方法名:writeUnnamedTag
  • 源码定位:L167
  • 返回类型:void
  • 修饰符:public static

参数:

  • tag: Tag
  • output: DataOutput

说明:

TODO

public static void writeUnnamedTagWithFallback(Tag tag, DataOutput output) @ L175

  • 方法名:writeUnnamedTagWithFallback
  • 源码定位:L175
  • 返回类型:void
  • 修饰符:public static

参数:

  • tag: Tag
  • output: DataOutput

说明:

TODO

public static Tag readUnnamedTag(DataInput input, NbtAccounter accounter) @ L179

  • 方法名:readUnnamedTag
  • 源码定位:L179
  • 返回类型:Tag
  • 修饰符:public static

参数:

  • input: DataInput
  • accounter: NbtAccounter

说明:

TODO

private static Tag readTagSafe(DataInput input, NbtAccounter accounter, byte type) @ L190

  • 方法名:readTagSafe
  • 源码定位:L190
  • 返回类型:Tag
  • 修饰符:private static

参数:

  • input: DataInput
  • accounter: NbtAccounter
  • type: byte

说明:

TODO

代码

public class NbtIo {
    private static final OpenOption[] SYNC_OUTPUT_OPTIONS = new OpenOption[]{
        StandardOpenOption.SYNC, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING
    };
 
    public static CompoundTag readCompressed(Path file, NbtAccounter accounter) throws IOException {
        CompoundTag var4;
        try (
            InputStream rawInput = Files.newInputStream(file);
            InputStream input = new FastBufferedInputStream(rawInput);
        ) {
            var4 = readCompressed(input, accounter);
        }
 
        return var4;
    }
 
    private static DataInputStream createDecompressorStream(InputStream in) throws IOException {
        return new DataInputStream(new FastBufferedInputStream(new GZIPInputStream(in)));
    }
 
    private static DataOutputStream createCompressorStream(OutputStream out) throws IOException {
        return new DataOutputStream(new BufferedOutputStream(new GZIPOutputStream(out)));
    }
 
    public static CompoundTag readCompressed(InputStream in, NbtAccounter accounter) throws IOException {
        CompoundTag var3;
        try (DataInputStream dis = createDecompressorStream(in)) {
            var3 = read(dis, accounter);
        }
 
        return var3;
    }
 
    public static void parseCompressed(Path file, StreamTagVisitor output, NbtAccounter accounter) throws IOException {
        try (
            InputStream rawInput = Files.newInputStream(file);
            InputStream input = new FastBufferedInputStream(rawInput);
        ) {
            parseCompressed(input, output, accounter);
        }
    }
 
    public static void parseCompressed(InputStream in, StreamTagVisitor output, NbtAccounter accounter) throws IOException {
        try (DataInputStream dis = createDecompressorStream(in)) {
            parse(dis, output, accounter);
        }
    }
 
    public static void writeCompressed(CompoundTag tag, Path file) throws IOException {
        try (
            OutputStream out = Files.newOutputStream(file, SYNC_OUTPUT_OPTIONS);
            OutputStream bufferedOut = new BufferedOutputStream(out);
        ) {
            writeCompressed(tag, bufferedOut);
        }
    }
 
    public static void writeCompressed(CompoundTag tag, OutputStream out) throws IOException {
        try (DataOutputStream dos = createCompressorStream(out)) {
            write(tag, dos);
        }
    }
 
    public static void write(CompoundTag tag, Path file) throws IOException {
        try (
            OutputStream out = Files.newOutputStream(file, SYNC_OUTPUT_OPTIONS);
            OutputStream bufferedOut = new BufferedOutputStream(out);
            DataOutputStream dos = new DataOutputStream(bufferedOut);
        ) {
            write(tag, dos);
        }
    }
 
    public static @Nullable CompoundTag read(Path file) throws IOException {
        if (!Files.exists(file)) {
            return null;
        } else {
            CompoundTag var3;
            try (
                InputStream in = Files.newInputStream(file);
                DataInputStream dis = new DataInputStream(in);
            ) {
                var3 = read(dis, NbtAccounter.unlimitedHeap());
            }
 
            return var3;
        }
    }
 
    public static CompoundTag read(DataInput input) throws IOException {
        return read(input, NbtAccounter.unlimitedHeap());
    }
 
    public static CompoundTag read(DataInput input, NbtAccounter accounter) throws IOException {
        Tag tag = readUnnamedTag(input, accounter);
        if (tag instanceof CompoundTag) {
            return (CompoundTag)tag;
        } else {
            throw new IOException("Root tag must be a named compound tag");
        }
    }
 
    public static void write(CompoundTag tag, DataOutput output) throws IOException {
        writeUnnamedTagWithFallback(tag, output);
    }
 
    public static void parse(DataInput input, StreamTagVisitor output, NbtAccounter accounter) throws IOException {
        TagType<?> type = TagTypes.getType(input.readByte());
        if (type == EndTag.TYPE) {
            if (output.visitRootEntry(EndTag.TYPE) == StreamTagVisitor.ValueResult.CONTINUE) {
                output.visitEnd();
            }
        } else {
            switch (output.visitRootEntry(type)) {
                case HALT:
                default:
                    break;
                case BREAK:
                    StringTag.skipString(input);
                    type.skip(input, accounter);
                    break;
                case CONTINUE:
                    StringTag.skipString(input);
                    type.parse(input, output, accounter);
            }
        }
    }
 
    public static Tag readAnyTag(DataInput input, NbtAccounter accounter) throws IOException {
        byte type = input.readByte();
        return (Tag)(type == 0 ? EndTag.INSTANCE : readTagSafe(input, accounter, type));
    }
 
    public static void writeAnyTag(Tag tag, DataOutput output) throws IOException {
        output.writeByte(tag.getId());
        if (tag.getId() != 0) {
            tag.write(output);
        }
    }
 
    public static void writeUnnamedTag(Tag tag, DataOutput output) throws IOException {
        output.writeByte(tag.getId());
        if (tag.getId() != 0) {
            output.writeUTF("");
            tag.write(output);
        }
    }
 
    public static void writeUnnamedTagWithFallback(Tag tag, DataOutput output) throws IOException {
        writeUnnamedTag(tag, new NbtIo.StringFallbackDataOutput(output));
    }
 
    @VisibleForTesting
    public static Tag readUnnamedTag(DataInput input, NbtAccounter accounter) throws IOException {
        byte type = input.readByte();
        if (type == 0) {
            return EndTag.INSTANCE;
        } else {
            StringTag.skipString(input);
            return readTagSafe(input, accounter, type);
        }
    }
 
    private static Tag readTagSafe(DataInput input, NbtAccounter accounter, byte type) {
        try {
            return TagTypes.getType(type).load(input, accounter);
        } catch (IOException var6) {
            CrashReport report = CrashReport.forThrowable(var6, "Loading NBT data");
            CrashReportCategory category = report.addCategory("NBT Tag");
            category.setDetail("Tag type", type);
            throw new ReportedNbtException(report);
        }
    }
 
    public static class StringFallbackDataOutput extends DelegateDataOutput {
        public StringFallbackDataOutput(DataOutput parent) {
            super(parent);
        }
 
        @Override
        public void writeUTF(String s) throws IOException {
            try {
                super.writeUTF(s);
            } catch (UTFDataFormatException var3) {
                Util.logAndPauseIfInIde("Failed to write NBT String", var3);
                super.writeUTF("");
            }
        }
    }
}

引用的其他类

  • CrashReport

    • 引用位置: 方法调用
    • 关联成员: CrashReport.forThrowable()
  • CompoundTag

    • 引用位置: 参数/返回值
  • NbtAccounter

    • 引用位置: 参数/方法调用
    • 关联成员: NbtAccounter.unlimitedHeap()
  • ReportedNbtException

    • 引用位置: 构造调用
    • 关联成员: ReportedNbtException()
  • StreamTagVisitor

    • 引用位置: 参数
  • StringTag

    • 引用位置: 方法调用
    • 关联成员: StringTag.skipString()
  • Tag

    • 引用位置: 参数/返回值
  • TagTypes

    • 引用位置: 方法调用
    • 关联成员: TagTypes.getType()
  • FastBufferedInputStream

    • 引用位置: 构造调用
    • 关联成员: FastBufferedInputStream()
  • Util

    • 引用位置: 方法调用
    • 关联成员: Util.logAndPauseIfInIde()