[ https://issues.apache.org/jira/browse/IO-152?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12556413#action_12556413 ]
Jukka Zitting commented on IO-152: ---------------------------------- The method is essentially the opposite of writeTo, and I wanted to reflect that in the method name. Where writeTo _writes to_ a given OutputStream, readFrom _reads from_ a given InputStream. The alternative is of course to think of the method as an alternative to the various write() methods, in which case naming it write(InputStream) makes sense. However, I think there's one detail that makes the proposed readFrom() different from the normal write() methods. The write() methods inherited from OutputStream are declared to throw IOExceptions if the method fails to _write_ to the stream (of course ByteArrayOutputStream doesn't declare the exceptions). The readFrom() method on the other hand can throw IOExceptions, but only if the method fails to _read_ from the given stream. It's a small difference, but IMHO worth using different method names. I also thought about writeFrom, but that doesn't sound right and IMHO works with neither write() nor writeTo(). Anyway, I'm not too tied to the name, so I'm fine with renaming the method if the above didn't convince you. :-) > Add ByteArrayOutputStream.readFrom(InputStream) > ----------------------------------------------- > > Key: IO-152 > URL: https://issues.apache.org/jira/browse/IO-152 > Project: Commons IO > Issue Type: New Feature > Components: Streams/Writers > Reporter: Jukka Zitting > Priority: Minor > Fix For: 1.4 > > Attachments: IO-152.patch > > > It would be useful to have a ByteArrayOutputStream.readFrom(InputStream) > method to mirror the existing writeTo(OutputStream) method. A call like > baos.readFrom(in) would be semantically the same as IOUtils.copy(in, baos), > but would avoid an extra in-memory copy of the stream contents, as it could > read bytes from the input stream directly into the internal > ByteArrayOutputStream buffers. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.