diff options
author | syeyoung <42869671+cyoung06@users.noreply.github.com> | 2020-12-09 00:00:14 +0900 |
---|---|---|
committer | syeyoung <42869671+cyoung06@users.noreply.github.com> | 2020-12-09 00:00:14 +0900 |
commit | 956e6ed51382aaac19ae5a7a8b4c664ae630e587 (patch) | |
tree | 1a171a0f7ef4fc745eaed02995af4fccc88acdbb /src | |
parent | afa8d0e7f3b7988540294d65f71ebe47ed9b474c (diff) | |
download | Skyblock-Dungeons-Guide-956e6ed51382aaac19ae5a7a8b4c664ae630e587.tar.gz Skyblock-Dungeons-Guide-956e6ed51382aaac19ae5a7a8b4c664ae630e587.tar.bz2 Skyblock-Dungeons-Guide-956e6ed51382aaac19ae5a7a8b4c664ae630e587.zip |
fix classloader
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/NetworkClassLoader.java | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/NetworkClassLoader.java b/src/main/java/kr/syeyoung/dungeonsguide/NetworkClassLoader.java index f8f80611..db8312eb 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/NetworkClassLoader.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/NetworkClassLoader.java @@ -1,8 +1,11 @@ package kr.syeyoung.dungeonsguide; +import com.google.common.io.Files; + import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; +import javax.xml.bind.DatatypeConverter; import java.io.*; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; @@ -43,26 +46,30 @@ public class NetworkClassLoader extends ClassLoader { private byte[] loadClassFromFile(String fileName) throws BadPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException, IllegalBlockSizeException, NoSuchPaddingException, InvalidKeyException { InputStream inputStream = authenticator.getInputStream(fileName.replace('.', '/')+ ".class"); - long length = 0; - { - for (int i = 4; i >= 0; i--) { - length |= (inputStream.read() & 0xFF) << i * 8; - } - } - while (inputStream.available() < length); + + byte[] bytes = new byte[4]; + inputStream.read(bytes); + int length = ((bytes[0] & 0xFF) << 24) | + ((bytes[1] & 0xFF) << 16) | + ((bytes[2] & 0xFF) << 8 ) | + ((bytes[3] & 0xFF)); + + System.out.println("Expecting "+length); ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); - int nextValue = 0; + int totalLen = 0; try { - byte[] buffer = new byte[1024]; - while ( (inputStream.read(buffer)) != -1 ) { - byteStream.write(buffer); + byte[] buffer = new byte[128]; + int read = 0; + while ( (read = inputStream.read(buffer)) != -1 ) { + totalLen += read; + byteStream.write(buffer, 0, read); + if (totalLen >= length) break;; } } catch (Exception ignored) {} byte[] byte1 = byteStream.toByteArray(); byte[] byte2 = new byte[(int) length]; System.arraycopy(byte1, 0, byte2, 0, byte2.length); - return byte2; } } |