Im a web dev using commons-fileupload-1.0.jar
My project requires that I dont write the file to the hard drive. I must however be able to carry the file to multiple web pages so I put the item in a hashmap.
I found that item.get() corrupted some files when putting it in the Map, specifically PDF's & word doc's with certain international encoding so I started using
InputStream stream = item.getInputStream();
And put that in the HashMap. When I want to retrieve the object I use the code below.
//get the file back out of the hashmap
InputStream stream = (InputStream)formDataHM.get(key);
int bufferSize = stream.available();
byte[] buffer = new byte[bufferSize];
ByteArrayOutputStream baos = new ByteArrayOutputStream(bufferSize);
int bytesread = 0;
while(true){
bytesread = stream.read(buffer);
if (bytesread == -1)
break;
baos.write(buffer,0,bytesread);
}
content = baos.toByteArray();
Its seems to work fine with no issues but I am wondering what performance hit I am taking by doing this. I am new to java so I even have questions about setting the bufferSize. I see some people set it for the size of the file while others set it for 1024 or 8 thousand something.
I was asking the question on sun's forum and someone recommended a 4000 range.
Any input would be appreciated.
Regards,
Earl
www.jhdesigninc.com