Skip to content

Commit

Permalink
Close streams (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
cijaaimee authored Sep 28, 2020
1 parent 0196209 commit 37fb6a2
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,24 @@ public static CraftSlimeWorld readFromDirectory(File worldDir) throws InvalidWor
private static CompoundTag loadMap(File mapFile) throws IOException {
String fileName = mapFile.getName();
int mapId = Integer.parseInt(fileName.substring(4, fileName.length() - 4));
CompoundTag tag;

try (NBTInputStream nbtStream = new NBTInputStream(new FileInputStream(mapFile),
NBTInputStream.GZIP_COMPRESSION, ByteOrder.BIG_ENDIAN)) {
tag = nbtStream.readTag().getAsCompoundTag().get().getAsCompoundTag("data").get();
}

NBTInputStream nbtStream = new NBTInputStream(new FileInputStream(mapFile), NBTInputStream.GZIP_COMPRESSION, ByteOrder.BIG_ENDIAN);
CompoundTag tag = nbtStream.readTag().getAsCompoundTag().get().getAsCompoundTag("data").get();
tag.getValue().put("id", new IntTag("id", mapId));

return tag;
}

private static LevelData readLevelData(File file) throws IOException, InvalidWorldException {
NBTInputStream nbtStream = new NBTInputStream(new FileInputStream(file));
Optional<CompoundTag> tag = nbtStream.readTag().getAsCompoundTag();
Optional<CompoundTag> tag;

try (NBTInputStream nbtStream = new NBTInputStream(new FileInputStream(file))) {
tag = nbtStream.readTag().getAsCompoundTag();
}

if (tag.isPresent()) {
Optional<CompoundTag> dataTag = tag.get().getAsCompoundTag("Data");
Expand Down

0 comments on commit 37fb6a2

Please sign in to comment.