Use buffered streams when managing NBT files

This commit is contained in:
Chicken-Bones committed 2014-10-01 20:01:10 +10:00
1 parent 8d1619589d
commit f2180dfab5
7 files changed
+51 -47

No files matched your search

+25 -2
View File
@@ -13,6 +13,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.server.MinecraftServer;
@@ -24,9 +25,9 @@ import net.minecraft.world.WorldServer;
import net.minecraft.world.WorldSettings.GameType;
import net.minecraftforge.oredict.OreDictionary;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.*;
import java.util.*;
import java.util.zip.ZipException;
public class NEIServerUtils
{
@@ -377,4 +378,26 @@ public class NEIServerUtils
stackTraces.add(stackTrace);
}
}
public static NBTTagCompound readNBT(File file) throws IOException {
if(!file.exists()) return null;
FileInputStream in = new FileInputStream(file);
NBTTagCompound tag;
try {
tag = CompressedStreamTools.readCompressed(in);
} catch(ZipException e) {
if(e.getMessage().equals("Not in GZIP format"))
tag = CompressedStreamTools.read(file);
else
throw e;
}
in.close();
return tag;
}
public static void writeNBT(NBTTagCompound tag, File file) throws IOException {
FileOutputStream out = new FileOutputStream(file);
CompressedStreamTools.writeCompressed(tag, out);
out.close();
}
}