commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dr. Christian Möller (JIRA) <j...@apache.org>
Subject [jira] Commented: (VFS-111) Closed OutputStream from FileContent does not throw IOException if further written to
Date Thu, 15 Feb 2007 13:53:05 GMT

    [ https://issues.apache.org/jira/browse/VFS-111?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12473379
] 

Dr. Christian Möller commented on VFS-111:
------------------------------------------

OK, I've done some debugging to see what happens when calling write() on the OutputStream
given by FileContent.getOutputStream(). Two steps further you reach java.io.BufferedOutputStream.write(byte[],
int, int) - it seems that the OutputStream delivered by FileContent (in this case an instance
of org.apache.commons.vfs.provider.DefaultFileContent$FileContentOutputStream) is a buffered
one.
Now, java.io.BufferedOutputStream shows the same behaviour I've mentioned to be erroneous:
Closing it and writing further data to it won't throw an IOException (unless his internal
buffer is filled up).
But why does this buffered decorator does not throw the expected IOException? Because it is
a simple buffer and there is no possibility to ask the underlying stream for its state: No
"isClosed()" method on java.io.OutputStream! So the only alternative would be to record the
closed state within the buffered decorator a second time (the first time it is recorded by
the underlying stream); this doesn't seem to be very elegant, does it?

Referring to VFS there are two options I think:
a) Stay as it is, or
b) Deliver an unbuffered stream via FileContent.getOutputStream() instead of a buffered one.

What do you think?

Christian


> Closed OutputStream from FileContent does not throw IOException if further written to
> -------------------------------------------------------------------------------------
>
>                 Key: VFS-111
>                 URL: https://issues.apache.org/jira/browse/VFS-111
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 1.0 Final
>         Environment: Windows XP, Java(TM) 2 Runtime Environment, Standard Edition (build
1.5.0_10-b03)
>            Reporter: Dr. Christian Möller
>
> I've a question regarding the behaviour of OutputStreams received from
> org.apache.commons.vfs.FileContent.getOutputStream(): If I call close()
> on them and further write some bytes to the stream, these writes take
> place silently without throwing an IOException (as it is done by "usual"
> Java streams like java.io.FileOutputStream); the data written after close()
> has been called does not appear in the target file, neither.
> As an example:
> byte[] SOME_BYTES = new byte[]{70, 71, 72};
> FileObject tmpFile = VFS.getManager().resolveFile("tmp:test.txt");
> OutputStream os = tmpFile.getContent().getOutputStream();
> os.write(SOME_BYTES);
> os.close();
> os.write(SOME_BYTES); // Neither IOE is thrown nor bytes are written

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message