this answer can be a bit late, but an alternative is to replace ByteArrayBuffer with ByteArrayOutputStream and use an array of bytes as follows:
Example of code with ByteArraybuffer:
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
FileOutputStream fos = new FileOutputStream(file);
fos.write(buffer.toByteArray());
Now, using with ByteArrayOutputStream:
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
//We create an array of bytes
byte[] data = new byte[50];
int current = 0;
while((current = bis.read(data,0,data.length)) != -1){
buffer.write(data,0,current);
}
FileOutputStream fos = new FileOutputStream(file);
fos.write(buffer.toByteArray());
fos.close();
Well, I hope this be useful.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…