From 0d527e282fd831fffb9539991054a65bb9b3fb2e Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 6 Sep 2011 02:56:47 -0700 Subject: [PATCH] Latest WIP --- src/com/gmail/nossr50/spout/SpoutStuff.java | 39 +++++++++++---------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/com/gmail/nossr50/spout/SpoutStuff.java b/src/com/gmail/nossr50/spout/SpoutStuff.java index 903f14068..10399c453 100644 --- a/src/com/gmail/nossr50/spout/SpoutStuff.java +++ b/src/com/gmail/nossr50/spout/SpoutStuff.java @@ -6,6 +6,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.jar.JarEntry; @@ -54,25 +55,25 @@ public class SpoutStuff public static void writeFile(String theFileName, String theFilePath) { - try { - File currentFile = new File("plugins/mcMMO/Resources/"+theFilePath+theFileName); - //System.out.println(theFileName); - @SuppressWarnings("static-access") - JarFile jar = new JarFile(plugin.mcmmo); - JarEntry entry = jar.getJarEntry("resources/"+theFileName); - InputStream is = jar.getInputStream(entry); - byte[] buf = new byte[(int)entry.getSize()]; - is.read(buf, 0, buf.length); - FileOutputStream os = new FileOutputStream(currentFile); - os.write(buf); - os.close(); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + try { + File currentFile = new File("plugins/mcMMO/Resources/"+theFilePath+theFileName); + @SuppressWarnings("static-access") + JarFile jar = new JarFile(plugin.mcmmo); + JarEntry entry = jar.getJarEntry("resources/"+theFileName); + InputStream is = jar.getInputStream(entry); + byte[] buf = new byte[2048]; + int nbRead; + OutputStream os = new BufferedOutputStream(new FileOutputStream(currentFile)); + while((nbRead = is.read(buf)) != -1) { + os.write(buf, 0, nbRead); + } + os.flush(); + os.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } } public static void extractFiles()