|
1 | 1 | --- before/net/minecraft/nbt/CompressedStreamTools.java |
2 | 2 | +++ after/net/minecraft/nbt/CompressedStreamTools.java |
3 | | -@@ -18,8 +18,6 @@ |
| 3 | +@@ -18,43 +18,20 @@ |
4 | 4 | import net.minecraft.crash.CrashReport; |
5 | 5 | import net.minecraft.crash.CrashReportCategory; |
6 | 6 | import net.minecraft.util.ReportedException; |
7 | 7 | -import net.minecraftforge.fml.relauncher.Side; |
8 | 8 | -import net.minecraftforge.fml.relauncher.SideOnly; |
| 9 | +- |
| 10 | +-public class CompressedStreamTools |
| 11 | +-{ |
| 12 | +- public static NBTTagCompound readCompressed(InputStream is) throws IOException |
| 13 | +- { |
| 14 | +- DataInputStream datainputstream = new DataInputStream(new BufferedInputStream(new GZIPInputStream(is))); |
| 15 | +- NBTTagCompound nbttagcompound; |
| 16 | +- |
| 17 | +- try |
| 18 | +- { |
| 19 | +- nbttagcompound = read(datainputstream, NBTSizeTracker.INFINITE); |
| 20 | +- } |
| 21 | +- finally |
| 22 | +- { |
| 23 | +- datainputstream.close(); |
| 24 | +- } |
| 25 | +- |
| 26 | +- return nbttagcompound; |
| 27 | ++ |
| 28 | ++public class CompressedStreamTools { |
| 29 | ++ public static NBTTagCompound readCompressed(InputStream is) throws IOException { |
| 30 | ++ try(DataInputStream datainputstream = new DataInputStream(new BufferedInputStream(new GZIPInputStream(is)))) { |
| 31 | ++ return read(datainputstream, NBTSizeTracker.INFINITE); |
| 32 | ++ } |
| 33 | + } |
9 | 34 |
|
10 | | - public class CompressedStreamTools |
11 | | - { |
12 | | -@@ -54,7 +52,6 @@ |
| 35 | +- public static void writeCompressed(NBTTagCompound compound, OutputStream outputStream) throws IOException |
| 36 | +- { |
| 37 | +- DataOutputStream dataoutputstream = new DataOutputStream(new BufferedOutputStream(new GZIPOutputStream(outputStream))); |
| 38 | +- |
| 39 | +- try |
| 40 | +- { |
| 41 | ++ public static void writeCompressed(NBTTagCompound compound, OutputStream outputStream) throws IOException { |
| 42 | ++ try (DataOutputStream dataoutputstream = new DataOutputStream(new BufferedOutputStream(new GZIPOutputStream(outputStream)))) { |
| 43 | + write(compound, dataoutputstream); |
13 | 44 | } |
| 45 | +- finally |
| 46 | +- { |
| 47 | +- dataoutputstream.close(); |
| 48 | +- } |
14 | 49 | } |
15 | 50 |
|
16 | 51 | - @SideOnly(Side.CLIENT) |
17 | 52 | public static void safeWrite(NBTTagCompound compound, File fileIn) throws IOException |
18 | 53 | { |
19 | 54 | File file1 = new File(fileIn.getAbsolutePath() + "_tmp"); |
20 | | -@@ -81,47 +78,6 @@ |
| 55 | +@@ -81,49 +58,7 @@ |
21 | 56 | } |
22 | 57 | } |
23 | 58 |
|
|
62 | 97 | - } |
63 | 98 | - } |
64 | 99 | - |
65 | | - public static NBTTagCompound read(DataInputStream inputStream) throws IOException |
66 | | - { |
| 100 | +- public static NBTTagCompound read(DataInputStream inputStream) throws IOException |
| 101 | +- { |
| 102 | ++ public static NBTTagCompound read(DataInputStream inputStream) throws IOException { |
67 | 103 | return read(inputStream, NBTSizeTracker.INFINITE); |
68 | | -@@ -160,6 +116,7 @@ |
| 104 | + } |
| 105 | + |
| 106 | +@@ -160,6 +95,7 @@ |
69 | 107 | private static NBTBase read(DataInput input, int depth, NBTSizeTracker accounter) throws IOException |
70 | 108 | { |
71 | 109 | byte b0 = input.readByte(); |
72 | 110 | + accounter.read(8); // Forge: Count everything! |
73 | 111 |
|
74 | 112 | if (b0 == 0) |
75 | 113 | { |
76 | | -@@ -167,7 +124,8 @@ |
| 114 | +@@ -167,7 +103,8 @@ |
77 | 115 | } |
78 | 116 | else |
79 | 117 | { |
|
83 | 121 | NBTBase nbtbase = NBTBase.create(b0); |
84 | 122 |
|
85 | 123 | try |
86 | | -@@ -179,9 +137,48 @@ |
| 124 | +@@ -179,8 +116,25 @@ |
87 | 125 | { |
88 | 126 | CrashReport crashreport = CrashReport.makeCrashReport(ioexception, "Loading NBT data"); |
89 | 127 | CrashReportCategory crashreportcategory = crashreport.makeCategory("NBT Tag"); |
90 | 128 | - crashreportcategory.addCrashSection("Tag type", b0); |
91 | 129 | + crashreportcategory.addCrashSection("Tag type", Byte.valueOf(b0)); |
92 | 130 | throw new ReportedException(crashreport); |
93 | | - } |
| 131 | ++ } |
94 | 132 | + } |
95 | 133 | + } |
96 | 134 | + |
97 | | -+ public static void write(NBTTagCompound compound, File fileIn) throws IOException |
98 | | -+ { |
99 | | -+ DataOutputStream dataoutputstream = new DataOutputStream(new FileOutputStream(fileIn)); |
100 | | -+ |
101 | | -+ try |
102 | | -+ { |
| 135 | ++ public static void write(NBTTagCompound compound, File fileIn) throws IOException { |
| 136 | ++ try (DataOutputStream dataoutputstream = new DataOutputStream(new FileOutputStream(fileIn))) { |
103 | 137 | + write(compound, dataoutputstream); |
104 | 138 | + } |
105 | | -+ finally |
106 | | -+ { |
107 | | -+ dataoutputstream.close(); |
108 | | -+ } |
109 | 139 | + } |
110 | 140 | + |
111 | 141 | + @Nullable |
112 | | -+ public static NBTTagCompound read(File fileIn) throws IOException |
113 | | -+ { |
114 | | -+ if (!fileIn.exists()) |
115 | | -+ { |
| 142 | ++ public static NBTTagCompound read(File fileIn) throws IOException { |
| 143 | ++ if (!fileIn.exists()) { |
116 | 144 | + return null; |
117 | | -+ } |
118 | | -+ else |
119 | | -+ { |
120 | | -+ DataInputStream datainputstream = new DataInputStream(new FileInputStream(fileIn)); |
121 | | -+ NBTTagCompound nbttagcompound; |
122 | | -+ |
123 | | -+ try |
124 | | -+ { |
125 | | -+ nbttagcompound = read(datainputstream, NBTSizeTracker.INFINITE); |
126 | | -+ } |
127 | | -+ finally |
128 | | -+ { |
129 | | -+ datainputstream.close(); |
130 | | -+ } |
131 | | -+ |
132 | | -+ return nbttagcompound; |
| 145 | ++ } else { |
| 146 | ++ try(DataInputStream datainputstream = new DataInputStream(new FileInputStream(fileIn))) { |
| 147 | ++ return read(datainputstream, NBTSizeTracker.INFINITE); |
| 148 | + } |
133 | 149 | } |
134 | 150 | } |
135 | | - } |
|
0 commit comments