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