From 7b0745c336bcb16acf9e5679bbce6079db7b2191 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 26 Feb 2013 01:07:14 -0500 Subject: [PATCH] Change readFully to actually read a bunch of bytes at once now. Thanks to nallar and aartbluestoke for the suggestion to revisit this.. --- .../fml/relauncher/RelaunchClassLoader.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/fml/common/cpw/mods/fml/relauncher/RelaunchClassLoader.java b/fml/common/cpw/mods/fml/relauncher/RelaunchClassLoader.java index f2b48bd64..fe0d481db 100644 --- a/fml/common/cpw/mods/fml/relauncher/RelaunchClassLoader.java +++ b/fml/common/cpw/mods/fml/relauncher/RelaunchClassLoader.java @@ -42,6 +42,8 @@ public class RelaunchClassLoader extends URLClassLoader private static Manifest EMPTY = new Manifest(); + private ThreadLocal loadBuffer = new ThreadLocal(); + private static final String[] RESERVED = {"CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"}; private static final boolean DEBUG_CLASSLOADING = Boolean.parseBoolean(System.getProperty("fml.debugClassLoading", "false")); @@ -247,18 +249,32 @@ public class RelaunchClassLoader extends URLClassLoader { try { - ByteArrayOutputStream bos = new ByteArrayOutputStream(stream.available()); - int r; - while ((r = stream.read()) != -1) + byte[] buf = loadBuffer.get(); + if (buf == null) { - bos.write(r); + loadBuffer.set(new byte[1 << 12]); + buf = loadBuffer.get(); } - return bos.toByteArray(); + int r, totalLength = 0; + while ((r = stream.read(buf, totalLength, buf.length - totalLength)) != -1) + { + totalLength += r; + if (totalLength >= buf.length - 1) + { + byte[] oldbuf = buf; + buf = new byte[ oldbuf.length + (1 << 12 )]; + System.arraycopy(oldbuf, 0, buf, 0, oldbuf.length); + } + } + + byte[] result = new byte[totalLength]; + System.arraycopy(buf, 0, result, 0, totalLength); + return result; } catch (Throwable t) { - FMLLog.log(Level.WARNING, t, "Problem loading class"); + FMLRelaunchLog.log(Level.WARNING, t, "Problem loading class"); return new byte[0]; } }