My
JSP page POST's an image to a
servlet and I would like this servlet to write the image to the file system. I get the input stream from the request, read the stream and write the bytes to a file using FileOutputStream.
Now I need to convert this data back to binary format, otherwise the image cannot be displayed when I open the file. I'm using Apache Commons Codec, which I am not familiar with, and there is a method that seems to help
It accepts a byte array containing Base64 encoding and returns a byte array with binary data.
My existing code is
How would I use this API in my current code? As I'm using a fixed buffer size, I don't really want to read everything into the buffer, decode the array and then write the file from the buffer. I thought about having a second byte array to decode bytes each time the buffer is filled, but I'm getting an ArrayIndexOutOfBoundsException.
Is there a better way to do this?