1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
|
--- a/net/minecraft/nbt/NbtIo.java
+++ b/net/minecraft/nbt/NbtIo.java
@@ -1,3 +1,4 @@
+// mc-dev import
package net.minecraft.nbt;
import java.io.BufferedOutputStream;
@@ -10,6 +11,7 @@
import java.io.OutputStream;
import java.io.UTFDataFormatException;
import java.nio.file.Files;
+import java.nio.file.LinkOption;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
@@ -23,87 +25,270 @@
import net.minecraft.util.FastBufferedInputStream;
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 path, NbtAccounter nbtAccounter) throws IOException {
- CompoundTag var3;
- try (InputStream inputStream = Files.newInputStream(path)) {
- var3 = readCompressed(inputStream, nbtAccounter);
+ private static final OpenOption[] SYNC_OUTPUT_OPTIONS = new OpenOption[]{StandardOpenOption.SYNC, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING};
+
+ public NbtIo() {}
+
+ public static CompoundTag readCompressed(Path path, NbtAccounter nbtreadlimiter) throws IOException {
+ InputStream inputstream = Files.newInputStream(path);
+
+ CompoundTag nbttagcompound;
+
+ try {
+ nbttagcompound = readCompressed(inputstream, nbtreadlimiter);
+ } catch (Throwable throwable) {
+ if (inputstream != null) {
+ try {
+ inputstream.close();
+ } catch (Throwable throwable1) {
+ throwable.addSuppressed(throwable1);
+ }
+ }
+
+ throw throwable;
}
- return var3;
+ if (inputstream != null) {
+ inputstream.close();
+ }
+
+ return nbttagcompound;
}
private static DataInputStream createDecompressorStream(InputStream zippedStream) throws IOException {
return new DataInputStream(new FastBufferedInputStream(new GZIPInputStream(zippedStream)));
}
- private static DataOutputStream createCompressorStream(OutputStream outputStream) throws IOException {
- return new DataOutputStream(new BufferedOutputStream(new GZIPOutputStream(outputStream)));
+ private static DataOutputStream createCompressorStream(OutputStream outputstream) throws IOException {
+ return new DataOutputStream(new BufferedOutputStream(new GZIPOutputStream(outputstream)));
}
- public static CompoundTag readCompressed(InputStream inputStream, NbtAccounter nbtAccounter) throws IOException {
- CompoundTag var3;
- try (DataInputStream dataInputStream = createDecompressorStream(inputStream)) {
- var3 = read(dataInputStream, nbtAccounter);
+ public static CompoundTag readCompressed(InputStream inputstream, NbtAccounter nbtreadlimiter) throws IOException {
+ DataInputStream datainputstream = createDecompressorStream(inputstream);
+
+ CompoundTag nbttagcompound;
+
+ try {
+ nbttagcompound = read(datainputstream, nbtreadlimiter);
+ } catch (Throwable throwable) {
+ if (datainputstream != null) {
+ try {
+ datainputstream.close();
+ } catch (Throwable throwable1) {
+ throwable.addSuppressed(throwable1);
+ }
+ }
+
+ throw throwable;
}
- return var3;
+ if (datainputstream != null) {
+ datainputstream.close();
+ }
+
+ return nbttagcompound;
}
- public static void parseCompressed(Path path, StreamTagVisitor streamTagVisitor, NbtAccounter nbtAccounter) throws IOException {
- try (InputStream inputStream = Files.newInputStream(path)) {
- parseCompressed(inputStream, streamTagVisitor, nbtAccounter);
+ public static void parseCompressed(Path path, StreamTagVisitor streamtagvisitor, NbtAccounter nbtreadlimiter) throws IOException {
+ InputStream inputstream = Files.newInputStream(path);
+
+ try {
+ parseCompressed(inputstream, streamtagvisitor, nbtreadlimiter);
+ } catch (Throwable throwable) {
+ if (inputstream != null) {
+ try {
+ inputstream.close();
+ } catch (Throwable throwable1) {
+ throwable.addSuppressed(throwable1);
+ }
+ }
+
+ throw throwable;
}
+
+ if (inputstream != null) {
+ inputstream.close();
+ }
+
}
- public static void parseCompressed(InputStream inputStream, StreamTagVisitor streamTagVisitor, NbtAccounter nbtAccounter) throws IOException {
- try (DataInputStream dataInputStream = createDecompressorStream(inputStream)) {
- parse(dataInputStream, streamTagVisitor, nbtAccounter);
+ public static void parseCompressed(InputStream inputstream, StreamTagVisitor streamtagvisitor, NbtAccounter nbtreadlimiter) throws IOException {
+ DataInputStream datainputstream = createDecompressorStream(inputstream);
+
+ try {
+ parse(datainputstream, streamtagvisitor, nbtreadlimiter);
+ } catch (Throwable throwable) {
+ if (datainputstream != null) {
+ try {
+ datainputstream.close();
+ } catch (Throwable throwable1) {
+ throwable.addSuppressed(throwable1);
+ }
+ }
+
+ throw throwable;
}
+
+ if (datainputstream != null) {
+ datainputstream.close();
+ }
+
}
- public static void writeCompressed(CompoundTag compoundTag, Path path) throws IOException {
- try (
- OutputStream outputStream = Files.newOutputStream(path, SYNC_OUTPUT_OPTIONS);
- OutputStream outputStream1 = new BufferedOutputStream(outputStream);
- ) {
- writeCompressed(compoundTag, outputStream1);
+ public static void writeCompressed(CompoundTag nbttagcompound, Path path) throws IOException {
+ OutputStream outputstream = Files.newOutputStream(path, NbtIo.SYNC_OUTPUT_OPTIONS);
+
+ try {
+ BufferedOutputStream bufferedoutputstream = new BufferedOutputStream(outputstream);
+
+ try {
+ writeCompressed(nbttagcompound, (OutputStream) bufferedoutputstream);
+ } catch (Throwable throwable) {
+ try {
+ bufferedoutputstream.close();
+ } catch (Throwable throwable1) {
+ throwable.addSuppressed(throwable1);
+ }
+
+ throw throwable;
+ }
+
+ bufferedoutputstream.close();
+ } catch (Throwable throwable2) {
+ if (outputstream != null) {
+ try {
+ outputstream.close();
+ } catch (Throwable throwable3) {
+ throwable2.addSuppressed(throwable3);
+ }
+ }
+
+ throw throwable2;
}
+
+ if (outputstream != null) {
+ outputstream.close();
+ }
+
}
public static void writeCompressed(CompoundTag compoundTag, OutputStream outputStream) throws IOException {
- try (DataOutputStream dataOutputStream = createCompressorStream(outputStream)) {
- write(compoundTag, dataOutputStream);
+ DataOutputStream dataoutputstream = createCompressorStream(outputStream);
+
+ try {
+ write(compoundTag, (DataOutput) dataoutputstream);
+ } catch (Throwable throwable) {
+ if (dataoutputstream != null) {
+ try {
+ dataoutputstream.close();
+ } catch (Throwable throwable1) {
+ throwable.addSuppressed(throwable1);
+ }
+ }
+
+ throw throwable;
}
+
+ if (dataoutputstream != null) {
+ dataoutputstream.close();
+ }
+
}
- public static void write(CompoundTag compoundTag, Path path) throws IOException {
- try (
- OutputStream outputStream = Files.newOutputStream(path, SYNC_OUTPUT_OPTIONS);
- OutputStream outputStream1 = new BufferedOutputStream(outputStream);
- DataOutputStream dataOutputStream = new DataOutputStream(outputStream1);
- ) {
- write(compoundTag, dataOutputStream);
+ public static void write(CompoundTag nbttagcompound, Path path) throws IOException {
+ OutputStream outputstream = Files.newOutputStream(path, NbtIo.SYNC_OUTPUT_OPTIONS);
+
+ try {
+ BufferedOutputStream bufferedoutputstream = new BufferedOutputStream(outputstream);
+
+ try {
+ DataOutputStream dataoutputstream = new DataOutputStream(bufferedoutputstream);
+
+ try {
+ write(nbttagcompound, (DataOutput) dataoutputstream);
+ } catch (Throwable throwable) {
+ try {
+ dataoutputstream.close();
+ } catch (Throwable throwable1) {
+ throwable.addSuppressed(throwable1);
+ }
+
+ throw throwable;
+ }
+
+ dataoutputstream.close();
+ } catch (Throwable throwable2) {
+ try {
+ bufferedoutputstream.close();
+ } catch (Throwable throwable3) {
+ throwable2.addSuppressed(throwable3);
+ }
+
+ throw throwable2;
+ }
+
+ bufferedoutputstream.close();
+ } catch (Throwable throwable4) {
+ if (outputstream != null) {
+ try {
+ outputstream.close();
+ } catch (Throwable throwable5) {
+ throwable4.addSuppressed(throwable5);
+ }
+ }
+
+ throw throwable4;
}
+
+ if (outputstream != null) {
+ outputstream.close();
+ }
+
}
@Nullable
public static CompoundTag read(Path path) throws IOException {
- if (!Files.exists(path)) {
+ if (!Files.exists(path, new LinkOption[0])) {
return null;
} else {
- CompoundTag var3;
- try (
- InputStream inputStream = Files.newInputStream(path);
- DataInputStream dataInputStream = new DataInputStream(inputStream);
- ) {
- var3 = read(dataInputStream, NbtAccounter.unlimitedHeap());
+ InputStream inputstream = Files.newInputStream(path);
+
+ CompoundTag nbttagcompound;
+
+ try {
+ DataInputStream datainputstream = new DataInputStream(inputstream);
+
+ try {
+ nbttagcompound = read(datainputstream, NbtAccounter.unlimitedHeap());
+ } catch (Throwable throwable) {
+ try {
+ datainputstream.close();
+ } catch (Throwable throwable1) {
+ throwable.addSuppressed(throwable1);
+ }
+
+ throw throwable;
+ }
+
+ datainputstream.close();
+ } catch (Throwable throwable2) {
+ if (inputstream != null) {
+ try {
+ inputstream.close();
+ } catch (Throwable throwable3) {
+ throwable2.addSuppressed(throwable3);
+ }
+ }
+
+ throw throwable2;
}
- return var3;
+ if (inputstream != null) {
+ inputstream.close();
+ }
+
+ return nbttagcompound;
}
}
@@ -112,9 +297,10 @@
}
public static CompoundTag read(DataInput input, NbtAccounter accounter) throws IOException {
- Tag unnamedTag = readUnnamedTag(input, accounter);
- if (unnamedTag instanceof CompoundTag) {
- return (CompoundTag)unnamedTag;
+ Tag nbtbase = readUnnamedTag(input, accounter);
+
+ if (nbtbase instanceof CompoundTag) {
+ return (CompoundTag) nbtbase;
} else {
throw new IOException("Root tag must be a named compound tag");
}
@@ -124,37 +310,41 @@
writeUnnamedTagWithFallback(compoundTag, output);
}
- public static void parse(DataInput dataInput, StreamTagVisitor streamTagVisitor, NbtAccounter nbtAccounter) throws IOException {
- TagType<?> type = TagTypes.getType(dataInput.readByte());
- if (type == EndTag.TYPE) {
- if (streamTagVisitor.visitRootEntry(EndTag.TYPE) == StreamTagVisitor.ValueResult.CONTINUE) {
- streamTagVisitor.visitEnd();
+ public static void parse(DataInput datainput, StreamTagVisitor streamtagvisitor, NbtAccounter nbtreadlimiter) throws IOException {
+ TagType<?> nbttagtype = TagTypes.getType(datainput.readByte());
+
+ if (nbttagtype == EndTag.TYPE) {
+ if (streamtagvisitor.visitRootEntry(EndTag.TYPE) == StreamTagVisitor.b.CONTINUE) {
+ streamtagvisitor.visitEnd();
}
+
} else {
- switch (streamTagVisitor.visitRootEntry(type)) {
+ switch (streamtagvisitor.visitRootEntry(nbttagtype)) {
case HALT:
default:
break;
case BREAK:
- StringTag.skipString(dataInput);
- type.skip(dataInput, nbtAccounter);
+ StringTag.skipString(datainput);
+ nbttagtype.skip(datainput, nbtreadlimiter);
break;
case CONTINUE:
- StringTag.skipString(dataInput);
- type.parse(dataInput, streamTagVisitor, nbtAccounter);
+ StringTag.skipString(datainput);
+ nbttagtype.parse(datainput, streamtagvisitor, nbtreadlimiter);
}
+
}
}
- public static Tag readAnyTag(DataInput dataInput, NbtAccounter nbtAccounter) throws IOException {
- byte _byte = dataInput.readByte();
- return (Tag)(_byte == 0 ? EndTag.INSTANCE : readTagSafe(dataInput, nbtAccounter, _byte));
+ public static Tag readAnyTag(DataInput datainput, NbtAccounter nbtreadlimiter) throws IOException {
+ byte b0 = datainput.readByte();
+
+ return (Tag) (b0 == 0 ? EndTag.INSTANCE : readTagSafe(datainput, nbtreadlimiter, b0));
}
- public static void writeAnyTag(Tag tag, DataOutput dataOutput) throws IOException {
- dataOutput.writeByte(tag.getId());
- if (tag.getId() != 0) {
- tag.write(dataOutput);
+ public static void writeAnyTag(Tag nbtbase, DataOutput dataoutput) throws IOException {
+ dataoutput.writeByte(nbtbase.getId());
+ if (nbtbase.getId() != 0) {
+ nbtbase.write(dataoutput);
}
}
@@ -166,44 +356,48 @@
}
}
- public static void writeUnnamedTagWithFallback(Tag tag, DataOutput dataOutput) throws IOException {
- writeUnnamedTag(tag, new NbtIo.StringFallbackDataOutput(dataOutput));
+ public static void writeUnnamedTagWithFallback(Tag nbtbase, DataOutput dataoutput) throws IOException {
+ writeUnnamedTag(nbtbase, new NbtIo.a(dataoutput));
}
- private static Tag readUnnamedTag(DataInput dataInput, NbtAccounter nbtAccounter) throws IOException {
- byte _byte = dataInput.readByte();
- if (_byte == 0) {
+ private static Tag readUnnamedTag(DataInput datainput, NbtAccounter nbtreadlimiter) throws IOException {
+ byte b0 = datainput.readByte();
+
+ if (b0 == 0) {
return EndTag.INSTANCE;
} else {
- StringTag.skipString(dataInput);
- return readTagSafe(dataInput, nbtAccounter, _byte);
+ StringTag.skipString(datainput);
+ return readTagSafe(datainput, nbtreadlimiter, b0);
}
}
- private static Tag readTagSafe(DataInput dataInput, NbtAccounter nbtAccounter, byte b) {
+ private static Tag readTagSafe(DataInput datainput, NbtAccounter nbtreadlimiter, byte b0) {
try {
- return TagTypes.getType(b).load(dataInput, nbtAccounter);
- } catch (IOException var6) {
- CrashReport crashReport = CrashReport.forThrowable(var6, "Loading NBT data");
- CrashReportCategory crashReportCategory = crashReport.addCategory("NBT Tag");
- crashReportCategory.setDetail("Tag type", b);
- throw new ReportedNbtException(crashReport);
+ return TagTypes.getType(b0).load(datainput, nbtreadlimiter);
+ } catch (IOException ioexception) {
+ CrashReport crashreport = CrashReport.forThrowable(ioexception, "Loading NBT data");
+ CrashReportCategory crashreportsystemdetails = crashreport.addCategory("NBT Tag");
+
+ crashreportsystemdetails.setDetail("Tag type", (Object) b0);
+ throw new ReportedNbtException(crashreport);
}
}
- public static class StringFallbackDataOutput extends DelegateDataOutput {
- public StringFallbackDataOutput(DataOutput dataOutput) {
- super(dataOutput);
+ public static class a extends DelegateDataOutput {
+
+ public a(DataOutput dataoutput) {
+ super(dataoutput);
}
@Override
- public void writeUTF(String string) throws IOException {
+ public void writeUTF(String s) throws IOException {
try {
- super.writeUTF(string);
- } catch (UTFDataFormatException var3) {
- Util.logAndPauseIfInIde("Failed to write NBT String", var3);
+ super.writeUTF(s);
+ } catch (UTFDataFormatException utfdataformatexception) {
+ Util.logAndPauseIfInIde("Failed to write NBT String", utfdataformatexception);
super.writeUTF("");
}
+
}
}
}
|