Magisk/app/src/main/java/com/topjohnwu/signing/ByteArrayStream.java

31 lines
833 B
Java
Raw Normal View History

2019-01-30 09:10:12 +01:00
package com.topjohnwu.signing;
2017-12-04 08:16:41 +01:00
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class ByteArrayStream extends ByteArrayOutputStream {
2017-12-04 08:16:41 +01:00
public synchronized void readFrom(InputStream is) {
readFrom(is, Integer.MAX_VALUE);
}
2017-12-04 08:16:41 +01:00
public synchronized void readFrom(InputStream is, int len) {
int read;
byte buffer[] = new byte[4096];
try {
while ((read = is.read(buffer, 0, Math.min(len, buffer.length))) > 0) {
2017-12-04 08:16:41 +01:00
write(buffer, 0, read);
len -= read;
}
} catch (IOException e) {
e.printStackTrace();
}
}
2017-12-04 08:16:41 +01:00
public ByteArrayInputStream getInputStream() {
return new ByteArrayInputStream(buf, 0, count);
}
}