From a2b2de94f90050b0f4d5e3d97657556159e95fb2 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sat, 24 Jun 2023 14:15:59 +0700 Subject: [PATCH] make the limit UNLIMITED --- gradle.properties | 7 ++++--- .../chipmunk/chipmunkmod/song/MidiConverter.java | 2 +- .../chipmunk/chipmunkmod/song/SongLoaderThread.java | 4 ++-- .../chipmunk/chipmunkmod/util/DownloadUtilities.java | 12 ++++-------- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/gradle.properties b/gradle.properties index a39caaf..6b01b90 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,8 +4,8 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop - minecraft_version=1.20 - yarn_mappings=1.20+build.1 + minecraft_version=1.20.1 + yarn_mappings=1.20.1+build.2 loader_version=0.14.21 # Mod Properties @@ -14,5 +14,6 @@ org.gradle.parallel=true archives_base_name = chipmunkmod # Dependencies - fabric_version=0.83.0+1.20 + fabric_version=0.83.1+1.20.1 + diff --git a/src/main/java/land/chipmunk/chipmunkmod/song/MidiConverter.java b/src/main/java/land/chipmunk/chipmunkmod/song/MidiConverter.java index abe34dc..053a31f 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/song/MidiConverter.java +++ b/src/main/java/land/chipmunk/chipmunkmod/song/MidiConverter.java @@ -19,7 +19,7 @@ public class MidiConverter { public static final int NOTE_OFF = 0x80; public static Song getSongFromUrl(URL url) throws IOException, InvalidMidiDataException, URISyntaxException, NoSuchAlgorithmException, KeyManagementException { - Sequence sequence = MidiSystem.getSequence(DownloadUtilities.DownloadToInputStream(url, 5*1024*1024)); + Sequence sequence = MidiSystem.getSequence(DownloadUtilities.DownloadToInputStream(url)); return getSong(sequence, Paths.get(url.toURI().getPath()).getFileName().toString()); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/song/SongLoaderThread.java b/src/main/java/land/chipmunk/chipmunkmod/song/SongLoaderThread.java index dc4c891..b02323f 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/song/SongLoaderThread.java +++ b/src/main/java/land/chipmunk/chipmunkmod/song/SongLoaderThread.java @@ -17,7 +17,7 @@ public class SongLoaderThread extends Thread { public SongLoaderException exception; public Song song; - private boolean isUrl = false; + private boolean isUrl; public SongLoaderThread (URL location) throws SongLoaderException { isUrl = true; @@ -34,7 +34,7 @@ public class SongLoaderThread extends Thread { String name; try { if (isUrl) { - bytes = DownloadUtilities.DownloadToByteArray(songUrl, 10*1024*1024); + bytes = DownloadUtilities.DownloadToByteArray(songUrl); name = Paths.get(songUrl.toURI().getPath()).getFileName().toString(); } else { bytes = Files.readAllBytes(songPath.toPath()); diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/DownloadUtilities.java b/src/main/java/land/chipmunk/chipmunkmod/util/DownloadUtilities.java index 1ae54fc..e1f5ffa 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/util/DownloadUtilities.java +++ b/src/main/java/land/chipmunk/chipmunkmod/util/DownloadUtilities.java @@ -28,7 +28,7 @@ public class DownloadUtilities { } } - public static byte[] DownloadToByteArray(URL url, int maxSize) throws IOException, KeyManagementException, NoSuchAlgorithmException { + public static byte[] DownloadToByteArray(URL url) throws IOException, KeyManagementException, NoSuchAlgorithmException { SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(new KeyManager[0], new TrustManager[] {new DefaultTrustManager()}, new SecureRandom()); SSLContext.setDefault(ctx); @@ -41,13 +41,9 @@ public class DownloadUtilities { ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int n; - int tot = 0; while ((n = downloadStream.read(buf)) > 0) { byteArrayStream.write(buf, 0, n); - tot += n; - if (tot > maxSize) { - throw new IOException("File is too large"); - } + if (Thread.interrupted()) { return null; } @@ -57,7 +53,7 @@ public class DownloadUtilities { // Closing a ByteArrayInputStream has no effect, so I do not close it. } - public static InputStream DownloadToInputStream(URL url, int maxSize) throws KeyManagementException, NoSuchAlgorithmException, IOException { - return new ByteArrayInputStream(DownloadToByteArray(url, maxSize)); + public static InputStream DownloadToInputStream(URL url) throws KeyManagementException, NoSuchAlgorithmException, IOException { + return new ByteArrayInputStream(DownloadToByteArray(url)); } }