mirror of https://github.com/ViaVersion/ViaNBT.git
Fix resource leaks
(cherry picked from commit 537221a0cad28cc0df49a9d90a15e241b297d37f)
This commit is contained in:
parent
d80ab5b7bd
commit
04c0131935
2
pom.xml
2
pom.xml
|
@ -5,7 +5,7 @@
|
|||
|
||||
<groupId>com.viaversion</groupId>
|
||||
<artifactId>opennbt</artifactId>
|
||||
<version>2.1.1</version>
|
||||
<version>2.1.2-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>OpenNBT</name>
|
||||
|
|
|
@ -70,16 +70,20 @@ public class NBTIO {
|
|||
*/
|
||||
public static CompoundTag readFile(File file, boolean compressed, boolean littleEndian) throws IOException {
|
||||
InputStream in = new FileInputStream(file);
|
||||
if(compressed) {
|
||||
in = new GZIPInputStream(in);
|
||||
}
|
||||
try {
|
||||
if (compressed) {
|
||||
in = new GZIPInputStream(in);
|
||||
}
|
||||
|
||||
CompoundTag tag = readTag(in, littleEndian);
|
||||
if(!(tag instanceof CompoundTag)) {
|
||||
throw new IOException("Root tag is not a CompoundTag!");
|
||||
}
|
||||
CompoundTag tag = readTag(in, littleEndian);
|
||||
if (!(tag instanceof CompoundTag)) {
|
||||
throw new IOException("Root tag is not a CompoundTag!");
|
||||
}
|
||||
|
||||
return tag;
|
||||
return tag;
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -136,12 +140,15 @@ public class NBTIO {
|
|||
}
|
||||
|
||||
OutputStream out = new FileOutputStream(file);
|
||||
if(compressed) {
|
||||
out = new GZIPOutputStream(out);
|
||||
}
|
||||
try {
|
||||
if (compressed) {
|
||||
out = new GZIPOutputStream(out);
|
||||
}
|
||||
|
||||
writeTag(out, tag, littleEndian);
|
||||
out.close();
|
||||
writeTag(out, tag, littleEndian);
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue