Aegis/app/src/main/java/me/impy/aegis/util/ByteInputStream.java

28 lines
757 B
Java
Raw Normal View History

package me.impy.aegis.util;
2017-12-03 21:42:12 +01:00
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
2017-12-03 21:42:12 +01:00
public class ByteInputStream extends ByteArrayInputStream {
private ByteInputStream(byte[] buf) {
2017-12-03 21:42:12 +01:00
super(buf);
}
public static ByteInputStream create(InputStream fileStream) throws IOException {
int read;
byte[] buf = new byte[4096];
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
while ((read = fileStream.read(buf, 0, buf.length)) != -1) {
outStream.write(buf, 0, read);
}
return new ByteInputStream(outStream.toByteArray());
}
2017-12-03 21:42:12 +01:00
public byte[] getBytes() {
return this.buf;
}
}