Skip to content

Commit b904775

Browse files
committed
a little prettify CompressedStreamTools
1 parent f063bf9 commit b904775

1 file changed

Lines changed: 57 additions & 42 deletions

File tree

patches/minecraft/net/minecraft/nbt/CompressedStreamTools.java.patch

Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,58 @@
11
--- before/net/minecraft/nbt/CompressedStreamTools.java
22
+++ after/net/minecraft/nbt/CompressedStreamTools.java
3-
@@ -18,8 +18,6 @@
3+
@@ -18,43 +18,20 @@
44
import net.minecraft.crash.CrashReport;
55
import net.minecraft.crash.CrashReportCategory;
66
import net.minecraft.util.ReportedException;
77
-import net.minecraftforge.fml.relauncher.Side;
88
-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+
}
934

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);
1344
}
45+
- finally
46+
- {
47+
- dataoutputstream.close();
48+
- }
1449
}
1550

1651
- @SideOnly(Side.CLIENT)
1752
public static void safeWrite(NBTTagCompound compound, File fileIn) throws IOException
1853
{
1954
File file1 = new File(fileIn.getAbsolutePath() + "_tmp");
20-
@@ -81,47 +78,6 @@
55+
@@ -81,49 +58,7 @@
2156
}
2257
}
2358

@@ -62,18 +97,21 @@
6297
- }
6398
- }
6499
-
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 {
67103
return read(inputStream, NBTSizeTracker.INFINITE);
68-
@@ -160,6 +116,7 @@
104+
}
105+
106+
@@ -160,6 +95,7 @@
69107
private static NBTBase read(DataInput input, int depth, NBTSizeTracker accounter) throws IOException
70108
{
71109
byte b0 = input.readByte();
72110
+ accounter.read(8); // Forge: Count everything!
73111

74112
if (b0 == 0)
75113
{
76-
@@ -167,7 +124,8 @@
114+
@@ -167,7 +103,8 @@
77115
}
78116
else
79117
{
@@ -83,53 +121,30 @@
83121
NBTBase nbtbase = NBTBase.create(b0);
84122

85123
try
86-
@@ -179,9 +137,48 @@
124+
@@ -179,8 +116,25 @@
87125
{
88126
CrashReport crashreport = CrashReport.makeCrashReport(ioexception, "Loading NBT data");
89127
CrashReportCategory crashreportcategory = crashreport.makeCategory("NBT Tag");
90128
- crashreportcategory.addCrashSection("Tag type", b0);
91129
+ crashreportcategory.addCrashSection("Tag type", Byte.valueOf(b0));
92130
throw new ReportedException(crashreport);
93-
}
131+
+ }
94132
+ }
95133
+ }
96134
+
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))) {
103137
+ write(compound, dataoutputstream);
104138
+ }
105-
+ finally
106-
+ {
107-
+ dataoutputstream.close();
108-
+ }
109139
+ }
110140
+
111141
+ @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()) {
116144
+ 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+
}
133149
}
134150
}
135-
}

0 commit comments

Comments
 (0)