You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Jukka Zitting (JIRA)" <ji...@apache.org> on 2009/01/26 16:37:59 UTC

[jira] Created: (IO-192) Tagged input and output streams

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
            Priority: Minor


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.


[jira] Resolved: (IO-192) Tagged input and output streams

Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/IO-192?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jukka Zitting resolved IO-192.
------------------------------

       Resolution: Fixed
    Fix Version/s: 1.5
         Assignee: Jukka Zitting

I committed a much improved version of the code in revision 741562.

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


[jira] Commented: (IO-192) Tagged input and output streams

Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/IO-192?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12673461#action_12673461 ] 

Niall Pemberton commented on IO-192:
------------------------------------

Sorry didn't answer your point about identity hashcode - perhaps you're right, but if thats a no-go then rather than Object - the tag should be Serializable.

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


[jira] Updated: (IO-192) Tagged input and output streams

Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
     [ 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.


[jira] Commented: (IO-192) Tagged input and output streams

Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/IO-192?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12673460#action_12673460 ] 

Niall Pemberton commented on IO-192:
------------------------------------

I have changed the exception handling methods to not return anything and committed them - see IO-195

I still don't think having those instance methods on the tagged streams is a good idea - heres a couple of simple use cases demonstrating my point about polluting/casting:

{code}
        ....
        TaggedInputStream taggedInput   = new TaggedInputStream(input);
        TaggedOutputStream taggedOutput = new TaggedOutputStream(output);
        bar(taggedInput, taggedOutput);
        ....
    
    public void bar(TaggedInputStream input, TaggedOutputStream output) {
        try {
            input.read();
        } catch (IOException e) {
            if (input.isCauseOf(e)) {
                ....
            }
            if (output.isCauseOf(e)) {
                ....
            }
        }
    }
{code}

{code}
        ....
        InputStream taggedInput = new TaggedInputStream(input);
        OutputStream taggedOutput = new TaggedOutputStream(output);
        bar(taggedInput, taggedOutput);
        ....
    
    public void bar(InputStream input, OutputStream output) {
        try {
            input.read();
        } catch (IOException e) {
            if (input instanceof TaggedInputStream &&
                ((TaggedInputStream)input).isCauseOf(e)) {
                ....
            }
            if (output instanceof TaggedOutputStream &&
                ((TaggedOutputStream)output).isCauseOf(e)) {
                ....
            }
        }
    }
{code}

IO like other commons components provides building blocks for people to reuse - so currently this is just about your requirement for tagging streams. My thinking is that if someone else wants to tag IO exceptions in other scenarios then its better to provide something that isn't tied to these tagged stream implementations.

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


[jira] Commented: (IO-192) Tagged input and output streams

Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/IO-192?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12672616#action_12672616 ] 

Jukka Zitting commented on IO-192:
----------------------------------

I like how you're extending the functionality to the Reader and Writer classes.

{quote}
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.
{quote}

Good idea.

My only issue is with the return value in the handleException() method of ProxyInputStream and ProxyReader. For example the skip() method should never return -1 but there is no way (apart from parsing the stack trace) for handleException() to know which method invoked it and what return value would be appropriate. I'd rather have the handleException() method return nothing, and just add fixed "return -1" or "return 0" statements where needed. A subclass that needs to modify the return value based on a thrown exception should override the specific method with custom processing.

{quote}
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.
{quote}

Good point, though I'm not so sure about using the identity hash for this. For most (all?) JVMs it will be unique to the tag object (at least as long as the object lives), but there's no guarantee that this actually is the case. Perhaps the tagged proxy classes should have a "private final Object tag = new Object();" tag object for this purpose. This would make the related IOUtils methods more complex, but see below for more on that.

{quote}
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.
{quote}

I don't see a use case where you'd need to use casts or pollute APIs with these classes.

{quote}
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.
{quote}

I would rather put such static generic methods directly on the TaggedIOException class. This would make it easier to reuse just that class.

In any case I would keep the current isCauseOf() and throwIfCauseOf() methods on the tagged stream classes, as IMHO the instance method call is clearer than a static IOUtils (or TaggedIOException) method call.


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


[jira] Resolved: (IO-192) Tagged input and output streams

Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/IO-192?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jukka Zitting resolved IO-192.
------------------------------

       Resolution: Fixed
    Fix Version/s:     (was: 1.5)
                   2.0

As suggested and discussed, I added static check methods to the TaggedIOException class and made the tags Serializable in revision 803310.

Each tagged stream uses a random UUID as an exception tag that is guaranteed (in all practical cases) to remain unique to the originating stream even if the exception is serialized and passed to another JVM.

Resolving as fixed for Commons IO 2.0. I updated the @since tags in the source to refer to IO 2.0 as it seems like we're not planning a 1.5 release anymore.

> 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: 2.0
>
>         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.


[jira] Issue Comment Edited: (IO-192) Tagged input and output streams

Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/IO-192?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12673492#action_12673492 ] 

jukkaz edited comment on IO-192 at 2/14/09 2:06 AM:
-----------------------------------------------------------

My point about the static IOUtils methods is that IMHO using the tagged stream features across method calls is bad form. Consider the following alternative to the bar() method:

{code}
public void bar(InputStream input, OutputStream output) {
    TaggedInputStream taggedInput = new TaggedInputStream(input);
    TaggedOutputStream taggedOutput = new TaggedOutputStream(output);
    try {
        processStreams(taggedInput, taggedOutput);
    } catch (IOException e) {
        if (taggedInput.isCauseOf(e)) {
            ....
        }
        if (taggedOutput.isCauseOf(e)) {
            ....
        }
    }
}
{code}

There is no need for a caller to know that bar() needs the tagged stream functionality. That can (and should) be encapsulated within bar(). Thus I think it's better if we *don't* provide the static IOUtils methods, as that'll make it harder for people to write bad APIs that silently assume extra functionality on stream instances.



      was (Author: jukkaz):
    My point about the static IOUtils methods is that IMHO using the tagged stream features across method calls is bad form. Consider the following alternative to the bar() method:

{code}
public void bar(InputStream input, OutputStream output) {
    TaggedInputStream taggedInput = new TaggedInputStream(input);
    TaggedInputStream taggedOutput = new TaggedInputStream(output);
    try {
        processStreams(taggedInput, taggedOutput);
    } catch (IOException e) {
        if (taggedInput.isCauseOf(e)) {
            ....
        }
        if (taggedOutput.isCauseOf(e)) {
            ....
        }
    }
}
{code}

There is no need for a caller to know that bar() needs the tagged stream functionality. That can (and should) be encapsulated within bar(). Thus I think it's better if we *don't* provide the static IOUtils methods, as that'll make it harder for people to write bad APIs that silently assume extra functionality on stream instances.


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


[jira] Updated: (IO-192) Tagged input and output streams

Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/IO-192?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jukka Zitting updated IO-192:
-----------------------------

    Attachment: IO-192.patch

This came up on the Tika mailing list, so I'm attaching the current state of the patch I have. It still needs tests and more javadocs, but the basic functionality should already be in place.

> 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
>            Priority: Minor
>         Attachments: 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.


[jira] Reopened: (IO-192) Tagged input and output streams

Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/IO-192?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Niall Pemberton reopened IO-192:
--------------------------------


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


[jira] Commented: (IO-192) Tagged input and output streams

Posted by "Jukka Zitting (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/IO-192?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12673492#action_12673492 ] 

Jukka Zitting commented on IO-192:
----------------------------------

My point about the static IOUtils methods is that IMHO using the tagged stream features across method calls is bad form. Consider the following alternative to the bar() method:

{code}
public void bar(InputStream input, OutputStream output) {
    TaggedInputStream taggedInput = new TaggedInputStream(input);
    TaggedInputStream taggedOutput = new TaggedInputStream(output);
    try {
        processStreams(taggedInput, taggedOutput);
    } catch (IOException e) {
        if (taggedInput.isCauseOf(e)) {
            ....
        }
        if (taggedOutput.isCauseOf(e)) {
            ....
        }
    }
}
{code}

There is no need for a caller to know that bar() needs the tagged stream functionality. That can (and should) be encapsulated within bar(). Thus I think it's better if we *don't* provide the static IOUtils methods, as that'll make it harder for people to write bad APIs that silently assume extra functionality on stream instances.



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