Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 69216 invoked from network); 26 Nov 2007 14:50:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 26 Nov 2007 14:50:01 -0000 Received: (qmail 98671 invoked by uid 500); 26 Nov 2007 14:49:48 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 98600 invoked by uid 500); 26 Nov 2007 14:49:47 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 98591 invoked by uid 99); 26 Nov 2007 14:49:47 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Nov 2007 06:49:47 -0800 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of nicks.trivedi@gmail.com designates 209.85.146.181 as permitted sender) Received: from [209.85.146.181] (HELO wa-out-1112.google.com) (209.85.146.181) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Nov 2007 14:49:48 +0000 Received: by wa-out-1112.google.com with SMTP id k34so806450wah for ; Mon, 26 Nov 2007 06:49:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; bh=cgSHEeiI3T5ITvLpSGfs/CCW3clV4YL34KM2BcZcEKc=; b=Fc2Jqz4h5uw8mi70j4bAyGKUevlpuPoaAmZQEDP2icN0pOWM7d9XFmpBMsZh6ECL0hPjobyO28IofcrgGa6bNDF4YSAJ6+ScrfBrXBQLovj524635dhxw/ff8RnwxmE/Hq/0GTt6CD64Un+VkcfuFNpXwQzhJxZ/1/Lvv0Q0OTc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=received:message-id:date:from:to:subject:mime-version:content-type; b=EyhNYrX6xo+L5iBRwL1vy0hkphZ7/9p6perhZmykdrpKYFT5IJ2p8pYP0REAH1IJ1HGTrESt2GNPI/v5k32l9RP4fNWFEBvK8njj3pmHx1MNgORCzEZY77YHPtS8GzXth9OalGCu6StHDFR33X93HaMbMUwh0ZcfLR8Kwf5X8AQ= Received: by 10.114.124.1 with SMTP id w1mr889241wac.1196088567058; Mon, 26 Nov 2007 06:49:27 -0800 (PST) Received: by 10.115.19.9 with HTTP; Mon, 26 Nov 2007 06:49:27 -0800 (PST) Message-ID: <50f68dd20711260649t295961eco464a254fef58c6ef@mail.gmail.com> Date: Mon, 26 Nov 2007 20:19:27 +0530 From: "Nikunj Trivedi" To: dev@commons.apache.org Subject: [PATCH][commons-io] Added method for getting InputStream from ByteArrayOutputStream & IOUtils avoiding unnecessary array allocation and copy MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_7988_10899161.1196088567057" X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_7988_10899161.1196088567057 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi All, I have created a Patch having two methods and test cases for both, as explained below. Any Comments ? 1) New Method: ByteArrayOutputStream.toInputStream ByteArrayOutputStream exposes its byte buffers by toByteArray(), which creates a fresh buffer and copy existing data to it. A new method toInputStream() available in patch returns the current contents of baos, as an InputStream, avoiding unnecessary allocation and copying. 2) New Method: IOUtils.toFullyBufferedInputStream There are situations where the InputStream source is available and it has to be passed to different modules for processing. It is needed to fetch the full contents of the InputStream in internal buffer(IOUtils.toByteArray() ), convert this buffer to ByteArrayInputStream and use that stream instead. But this is wasteful since toByteArray() requires one fresh allocation and copy operation. BufferedInputStream may not be used since 1) We want FULL buffer, 2) We dont know the size in advance. New method copies InputStream to ByteArrayOutputStream and returns baos.toInputStream(), avoiding unnecessary memory allocation and copy. Testcases are available in respective classes. Regards Nikunj Trivedi ------=_Part_7988_10899161.1196088567057--