Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Beginning Java 2
|
BOOK: Beginning Java 2
This is the forum to discuss the Wrox book Beginning Java 2, SDK 1.4 Edition by Ivor Horton; ISBN: 9780764543654
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Java 2 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 21st, 2008, 01:01 AM
Authorized User
 
Join Date: Jun 2003
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to erobb Send a message via Yahoo to erobb
Default Buffers, InputStream & ByteArrayOutputStream

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Java View Buffers dave2005b J2EE 0 September 25th, 2005 10:34 AM
Javascript && keeps turnig into && ayrton Pro VB.NET 2002/2003 3 June 27th, 2005 03:34 PM
Using font created by createFont(int, InputStream) smshinde Java GUI 0 March 13th, 2005 01:58 PM
Linux & KDE & C++ & QT & MYSQL & Kdevelop Munnnki Linux 0 January 2nd, 2005 05:41 PM
InputStream and OutputStream in javascript?? bikash Javascript 3 July 25th, 2003 05:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.