make faster buffer loader

This commit is contained in:
REAndroid 2023-01-07 09:06:39 -05:00
parent 9940e3371c
commit e3097de134

View File

@ -327,22 +327,17 @@ public class BlockReader extends InputStream {
return result; return result;
} }
private static byte[] loadBuffer(InputStream in) throws IOException { private static byte[] loadBuffer(InputStream in) throws IOException {
byte[] result=new byte[0]; ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buff=new byte[40960]; byte[] buff=new byte[40960];
int len; int len;
while((len=in.read(buff))>0){ 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(); in.close();
} }
return result; outputStream.close();
} return outputStream.toByteArray();
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;
} }
public static HeaderBlock readHeaderBlock(File file) throws IOException{ public static HeaderBlock readHeaderBlock(File file) throws IOException{
InputStream inputStream=new FileInputStream(file); InputStream inputStream=new FileInputStream(file);