Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@www.apache.org Received: (qmail 41924 invoked from network); 1 Oct 2003 08:19:43 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 1 Oct 2003 08:19:43 -0000 Received: (qmail 1453 invoked by uid 500); 1 Oct 2003 08:18:57 -0000 Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 1428 invoked by uid 500); 1 Oct 2003 08:18:57 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 1415 invoked from network); 1 Oct 2003 08:18:56 -0000 Received: from unknown (HELO aflon1msw01.aforbes.co.uk) (195.173.42.98) by daedalus.apache.org with SMTP; 1 Oct 2003 08:18:56 -0000 Received: from ex_london.europe.alexanderforbes.net (unverified) by aflon1msw01.aforbes.co.uk (Content Technologies SMTPRS 4.2.10) with ESMTP id for ; Wed, 1 Oct 2003 09:19:09 +0100 Received: by EX_LONDON with Internet Mail Service (5.5.2653.19) id <4BHXJ8RK>; Wed, 1 Oct 2003 09:18:23 +0100 Message-ID: <2BF18D53A42A1C43852D257C6BD3ACCD0544D5@afpet1exch1.pet.dc-link.co.uk> From: Walker Chris To: 'Tomcat Users List' Subject: RE: Tomcat sucks at receiving large messages Date: Wed, 1 Oct 2003 09:21:06 +0100 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Hi, I should have thought that as a general principle it's not a good idea to try to store the response in a byte array. I recently worked on a piece of code that did just that (worse, actually, it then copied the array into a String). Sooner or later a really big upload will blow up the application. Reading and writing a byte at a time (with appropriate buffering) requires a bit more ingenuity, especially when you're searching for things like boundary strings in the response, but it's the only way to remove any constraint on upload size. Chris Walker -----Original Message----- From: Shapira, Yoav [mailto:Yoav.Shapira@mpi.com] Sent: 30 September 2003 19:30 To: Tomcat Users List Subject: RE: Tomcat sucks at receiving large messages Howdy, >public void service(HttpServletRequest req, HttpServletResponse res) { > BufferedReader reader = req.getReader(); > try { > char [] charArr = new char[req.getContentLength()]; > reader.read(charArr); > String str = new String(charArr); > > try { > File f = new File("servlet.out"); > PrintWriter out = new PrintWriter(new FileWriter(f)); > out.print(str); > out.flush(); > out.close(); > } catch(IOException err { System.err.println(err.toString()); } > > } catch(IOException err) { System.err.println(err.toString()); } >} What happens if you ditch the req.getContentLength() approach (there are times when it will be -1 anyways), and do something like: BufferedReader reader = req.getReader(); StringBuffer contents = new StringBuffer(); String line = null; while((line = reader.readLine()) != null) { contents.append(line); } System.out.println(contents); (Later we'll worry about the writing -- first make sure you're reading the entire contents). Yoav Shapira This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-user-help@jakarta.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-user-help@jakarta.apache.org