commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nikunj Trivedi" <nicks.triv...@gmail.com>
Subject Re: [PATCH][commons-io] Added method for getting InputStream from ByteArrayOutputStream & IOUtils avoiding unnecessary array allocation and copy
Date Mon, 26 Nov 2007 14:51:16 GMT
Patch Attached.

On Nov 26, 2007 8:19 PM, Nikunj Trivedi <nicks.trivedi@gmail.com> wrote:

> 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
>

Mime
View raw message