commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton (JIRA)" <j...@apache.org>
Subject [jira] Updated: (IO-192) Tagged input and output streams
Date Sun, 08 Feb 2009 02:36:59 GMT

     [ https://issues.apache.org/jira/browse/IO-192?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Niall Pemberton updated IO-192:
-------------------------------

    Attachment: IO-192-tagged-stream-changes.patch

Hi Jukka,

I like the concept but have some comments/suggestions on the implementation of this.

1) Its a useful feature to be able to handle exceptions - not just in this use-case for tagging,
but generally so IMO it would be good to move the exception handling into the Proxy stream
implementations. We could provide a protected handleException(IOException) method that by
default just re-throws the exception to keep compatibility, but a allows people to override
for their own custom exception handling.

2) Exceptions are Serializable and many stream implementations are not so I have some concern
about holding a reference to the stream in the TaggedIOException. Also this could cause references
to the stream being held longer than previously by the application and prevent/delay garbage
collection. An alternative could be to store the identity hash code of the tag object instead.

3) The current solution requires users to reference the concrete tagged stream implementations.
While this is OK in your simple example within a single method its not good practice generally
and will either encourage people to pollute their API with these tagged streams or require
additional casting. I suggest we move the code for handling these streams into IOUtils - which
also makes it more generic and available to re-use for other tagging requirements, not just
by the throwing stream.

{code}
InputStream input = ...;
OutputStream output = ...;
OutputStream proxy = new TaggedOutputStream(output);
try {
    IOUtils.copy(input, proxy);
} catch (IOException e) {
    if (IOUtils.isTaggedBy(e, proxy)) {
        ...
    }
}
{code}

I am attaching a patch with my suggestions

> Tagged input and output streams
> -------------------------------
>
>                 Key: IO-192
>                 URL: https://issues.apache.org/jira/browse/IO-192
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Streams/Writers
>            Reporter: Jukka Zitting
>            Assignee: Jukka Zitting
>            Priority: Minor
>             Fix For: 1.5
>
>         Attachments: IO-192-tagged-stream-changes.patch, IO-192.patch
>
>
> I'd like to introduce two new proxy streams, TaggedInputStream and TaggedOutputStream,
that tag all exceptions thrown by the proxied streams. The goal is to make it easier to detect
the source of an IOException when you're dealing with multiple different streams. For example:
> {code}
> InputStream input = ...;
> OutputStream output = ...;
> TaggedOutputStream proxy = new TaggedOutputStream(output);
> try {
>     IOUtils.copy(input, proxy);
> } catch (IOException e) {
>     if (proxy.isTagged(e)) {
>         // Could not write to the output stream
>         // Perhaps we can handle that error somehow (retry, cancel?)
>         e.initCause(); // gives the original exception from the proxied stream
>     } else {
>         // Could not read from the input stream, nothing we can do
>         throw e;
>     }
> }
> {code}
> I'm working on a patch to implement such a feature.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message