I have a WebService that saves the photo to a server folder that was sent by the Android application through the following code:
...
int read = 0;
byte[] bytes = new byte[1024];
OutputStream out = new FileOutputStream(new File( caminhodestinofotos + uploadedFileName ));
while (( read = uploadedInputStream.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
out.flush();
out.close();
...
So far so good, but we decided to save this photo in the database.
To this end, I thought about turning the InputStream that gets the WebService function into a byte array.
I added the following line to the beginning of the function:
byte[] arrbytes = sun.misc.IOUtils.readFully(uploadedInputStream, -1, true);
It turns out that after executing this line the LOOP that reads from the file added to the bytes array does not happen.
The line read = uploadedInputStream.read(bytes)) != -1
returns -1 as if the InputStream is at the end of the file and a sequential read can not occur again.
How should I proceed? Resetting and placing the read pointer at the beginning of the file again, or what would be another way to use this same InputStream to save to file and save to the database?
Thank you.