How should a large file be handled in java when you need to run the bytes through a variety of methods?
The way I was doing it before is like this:
private byte[] inputStreamToByteArray(InputStream inputStream) {
BufferedInputStream bis = BufferedInputStream(inputStream);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[8192];
int nRead;
while((nRead = bis.read(buffer)) != -1) {
baos.write(buffer, 0, nRead);
}
return baos.toByteArray();
}
I get a java out of memory error doing it this way because my byte array gets too large.
So I tried stringing together streams, but I'm not sure if that is the proper way to do it because I don't understand enough about streams.
Should large files be handled using chunks from a byte array or by passing around inputstreams?