From e3097de1346342a4930a4315ae9976b4a66d0d5b Mon Sep 17 00:00:00 2001 From: REAndroid Date: Sat, 7 Jan 2023 09:06:39 -0500 Subject: [PATCH] make faster buffer loader --- .../com/reandroid/lib/arsc/io/BlockReader.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/reandroid/lib/arsc/io/BlockReader.java b/src/main/java/com/reandroid/lib/arsc/io/BlockReader.java index 9970a79..2e1bb74 100755 --- a/src/main/java/com/reandroid/lib/arsc/io/BlockReader.java +++ b/src/main/java/com/reandroid/lib/arsc/io/BlockReader.java @@ -327,22 +327,17 @@ public class BlockReader extends InputStream { return result; } private static byte[] loadBuffer(InputStream in) throws IOException { - byte[] result=new byte[0]; + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); byte[] buff=new byte[40960]; int len; while((len=in.read(buff))>0){ - result=add(result, buff, len); + outputStream.write(buff, 0, len); } - if(!(in instanceof ZipInputStream)){ + if(in instanceof FileInputStream){ in.close(); } - return result; - } - private static byte[] add(byte[] arr1, byte[] arr2, int len){ - byte[] result=new byte[arr1.length + len]; - System.arraycopy(arr1, 0, result, 0, arr1.length); - System.arraycopy(arr2, 0, result, arr1.length, len); - return result; + outputStream.close(); + return outputStream.toByteArray(); } public static HeaderBlock readHeaderBlock(File file) throws IOException{ InputStream inputStream=new FileInputStream(file);