2017-12-03 21:35:15 +01:00
|
|
|
package me.impy.aegis.util;
|
|
|
|
|
2017-12-03 21:42:12 +01:00
|
|
|
import java.io.ByteArrayInputStream;
|
2018-05-10 18:42:47 +02:00
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
2017-12-03 21:35:15 +01:00
|
|
|
|
2017-12-03 21:42:12 +01:00
|
|
|
public class ByteInputStream extends ByteArrayInputStream {
|
2018-05-10 18:42:47 +02:00
|
|
|
private ByteInputStream(byte[] buf) {
|
2017-12-03 21:42:12 +01:00
|
|
|
super(buf);
|
|
|
|
}
|
|
|
|
|
2018-05-10 18:42:47 +02:00
|
|
|
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;
|
|
|
|
}
|
2017-12-03 21:35:15 +01:00
|
|
|
}
|