You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Claus Ibsen (JIRA)" <ji...@apache.org> on 2012/05/01 08:53:44 UTC
[jira] [Created] (CAMEL-5235) Make sure to close file input stream
when converting file to string to avoid locking file on windows
Claus Ibsen created CAMEL-5235:
----------------------------------
Summary: Make sure to close file input stream when converting file to string to avoid locking file on windows
Key: CAMEL-5235
URL: https://issues.apache.org/jira/browse/CAMEL-5235
Project: Camel
Issue Type: Bug
Components: camel-core
Affects Versions: 2.9.2
Reporter: Claus Ibsen
Assignee: Claus Ibsen
Fix For: 2.9.3, 2.10.0
See nabble
http://camel.465427.n5.nabble.com/File-Processor-Not-deleting-the-files-tp5670301.html
Need to explicit close the file input/output streams to avoid the files to be locked on windows.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Issue Comment Edited] (CAMEL-5235) Make sure to close file
input stream when converting file to string to avoid locking file on
windows
Posted by "Babak Vahdat (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/CAMEL-5235?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13266421#comment-13266421 ]
Babak Vahdat edited comment on CAMEL-5235 at 5/2/12 8:09 AM:
-------------------------------------------------------------
While trying to find some resources on the web describing what my *poor* english is talking about, I came along many of them but the best one was given through that *already dissappered real vendor* itself:
{quote}
Similarly, when closing chained streams, you only need to close the outermost stream class because the close() call is automatically trickled through all the chained classes; in the example above, you would simply call the close() method on the GZIPOutputStream class.
{quote}
When you look at the example there the inner most OutputStream is also a FileOutputStream, however there's no need of an explicit close call on that:
http://java.sun.com/developer/technicalArticles/Streams/ProgIOStreams/
There are plenty of other APIs having similar semantics (call-chaining) like when you close a JDBC Statement:
{quote}
Note:When a Statement object is closed, its current ResultSet object, if one exists, is also closed.
{quote}
http://docs.oracle.com/javase/6/docs/api/java/sql/Statement.html#close()
So why I still ask for your approval to get rid of those two obsolete static member classes.
was (Author: bvahdat):
While trying to find some resources on the web describing what my *poor* english is talking about, I came along many of them but the best one was given through that *already dissappered real vendor* itself:
{quote}
Similarly, when closing chained streams, you only need to close the outermost stream class because the close() call is automatically trickled through all the chained classes; in the example above, you would simply call the close() method on the GZIPOutputStream class.
{quote}
When you look at the example there the inner most OutputStream is also a FileOutputStream, however there's no need of an explicit close call on that:
http://java.sun.com/developer/technicalArticles/Streams/ProgIOStreams/
So why I still ask for your approval to get rid of those two obsolete static member classes.
> Make sure to close file input stream when converting file to string to avoid locking file on windows
> ----------------------------------------------------------------------------------------------------
>
> Key: CAMEL-5235
> URL: https://issues.apache.org/jira/browse/CAMEL-5235
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Affects Versions: 2.9.2
> Reporter: Claus Ibsen
> Assignee: Claus Ibsen
> Fix For: 2.9.3, 2.10.0
>
>
> See nabble
> http://camel.465427.n5.nabble.com/File-Processor-Not-deleting-the-files-tp5670301.html
> Need to explicit close the file input/output streams to avoid the files to be locked on windows.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (CAMEL-5235) Make sure to close file input
stream when converting file to string to avoid locking file on windows
Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/CAMEL-5235?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13265727#comment-13265727 ]
Claus Ibsen commented on CAMEL-5235:
------------------------------------
You are welcome to do some investigations and see if we can do as you suggests, but we need to make sure the file streams gets closed, to avoid locking issues with windows.
> Make sure to close file input stream when converting file to string to avoid locking file on windows
> ----------------------------------------------------------------------------------------------------
>
> Key: CAMEL-5235
> URL: https://issues.apache.org/jira/browse/CAMEL-5235
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Affects Versions: 2.9.2
> Reporter: Claus Ibsen
> Assignee: Claus Ibsen
> Fix For: 2.9.3, 2.10.0
>
>
> See nabble
> http://camel.465427.n5.nabble.com/File-Processor-Not-deleting-the-files-tp5670301.html
> Need to explicit close the file input/output streams to avoid the files to be locked on windows.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Resolved] (CAMEL-5235) Make sure to close file input stream
when converting file to string to avoid locking file on windows
Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/CAMEL-5235?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Claus Ibsen resolved CAMEL-5235.
--------------------------------
Resolution: Fixed
> Make sure to close file input stream when converting file to string to avoid locking file on windows
> ----------------------------------------------------------------------------------------------------
>
> Key: CAMEL-5235
> URL: https://issues.apache.org/jira/browse/CAMEL-5235
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Affects Versions: 2.9.2
> Reporter: Claus Ibsen
> Assignee: Claus Ibsen
> Fix For: 2.9.3, 2.10.0
>
>
> See nabble
> http://camel.465427.n5.nabble.com/File-Processor-Not-deleting-the-files-tp5670301.html
> Need to explicit close the file input/output streams to avoid the files to be locked on windows.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (CAMEL-5235) Make sure to close file input
stream when converting file to string to avoid locking file on windows
Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/CAMEL-5235?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13266440#comment-13266440 ]
Claus Ibsen commented on CAMEL-5235:
------------------------------------
Yes they can possible be removed, just make sure the FileInputStream gets closed, as otherwise it can lock file handles on Windows.
> Make sure to close file input stream when converting file to string to avoid locking file on windows
> ----------------------------------------------------------------------------------------------------
>
> Key: CAMEL-5235
> URL: https://issues.apache.org/jira/browse/CAMEL-5235
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Affects Versions: 2.9.2
> Reporter: Claus Ibsen
> Assignee: Claus Ibsen
> Fix For: 2.9.3, 2.10.0
>
>
> See nabble
> http://camel.465427.n5.nabble.com/File-Processor-Not-deleting-the-files-tp5670301.html
> Need to explicit close the file input/output streams to avoid the files to be locked on windows.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (CAMEL-5235) Make sure to close file input
stream when converting file to string to avoid locking file on windows
Posted by "Babak Vahdat (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/CAMEL-5235?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13265736#comment-13265736 ]
Babak Vahdat commented on CAMEL-5235:
-------------------------------------
{quote}
Maybe but dont you still have the the issue that the File input/output streams do not get closed when the InputStreamWriter/OutputStreamWriter gets closed.
{quote}
No as that's done for "free" through the close() method magic, that's the call-chaining of the close() call by the underlying input/output streams. As an example when we look at BufferedReader.close() method we see that the close() call get's chained and the underlying stream (hopefully) does properly chain the call again and again, until the OS native stream gets properly closed. *But* that's the user's responsibility to
do that:
{code}
BufferedReader myReader = CamelContext.getTypeConverter().convertTo(BufferedReader.class, ...);
…
…
myReader.close(); // user should close the stream properly after the usage
{code}
The main "problem" is that we can't control if the user do *properly* close the Reader, Writer, In and Outputstream after the usage. And if they don't, then they will run into trouble and think something in Camel could be the reason for that.
> Make sure to close file input stream when converting file to string to avoid locking file on windows
> ----------------------------------------------------------------------------------------------------
>
> Key: CAMEL-5235
> URL: https://issues.apache.org/jira/browse/CAMEL-5235
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Affects Versions: 2.9.2
> Reporter: Claus Ibsen
> Assignee: Claus Ibsen
> Fix For: 2.9.3, 2.10.0
>
>
> See nabble
> http://camel.465427.n5.nabble.com/File-Processor-Not-deleting-the-files-tp5670301.html
> Need to explicit close the file input/output streams to avoid the files to be locked on windows.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (CAMEL-5235) Make sure to close file input
stream when converting file to string to avoid locking file on windows
Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/CAMEL-5235?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13265845#comment-13265845 ]
Claus Ibsen commented on CAMEL-5235:
------------------------------------
Yeah if the user gets a reader/stream etc then he may need to close it after use.
But in this use-case it was converting to String or byte[] etc directly. And for that Camel must make sure to close the stream internally.
> Make sure to close file input stream when converting file to string to avoid locking file on windows
> ----------------------------------------------------------------------------------------------------
>
> Key: CAMEL-5235
> URL: https://issues.apache.org/jira/browse/CAMEL-5235
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Affects Versions: 2.9.2
> Reporter: Claus Ibsen
> Assignee: Claus Ibsen
> Fix For: 2.9.3, 2.10.0
>
>
> See nabble
> http://camel.465427.n5.nabble.com/File-Processor-Not-deleting-the-files-tp5670301.html
> Need to explicit close the file input/output streams to avoid the files to be locked on windows.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (CAMEL-5235) Make sure to close file input
stream when converting file to string to avoid locking file on windows
Posted by "Babak Vahdat (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/CAMEL-5235?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13265720#comment-13265720 ]
Babak Vahdat commented on CAMEL-5235:
-------------------------------------
Claus, one stupid question of mine:
Why don't we simply remove these two static member classes EncodingFileReader as well as EncodingFileWriter and just make use of JDK's own InputStreamReader & OutputStreamWriter directly? To my understanding these two classes provide no added value other than trouble. And the JDK's own bridges (byte streams to character streams) are already *encoding aware* anyway!
So the two usage methods would simply become:
{code}
public static BufferedReader toReader(File file, String charset) throws IOException {
FileInputStream in = new FileInputStream(file);
return IOHelper.buffered(new InputStreamReader(in, charset));
}
{code}
{code}
public static BufferedWriter toWriter(File file, boolean append, String charset) throws IOException {
FileOutputStream os = new FileOutputStream(file, append);
return IOHelper.buffered(new OutputStreamWriter(os, charset));
}
{code}
They were both introduced by CAMEL-2056.
> Make sure to close file input stream when converting file to string to avoid locking file on windows
> ----------------------------------------------------------------------------------------------------
>
> Key: CAMEL-5235
> URL: https://issues.apache.org/jira/browse/CAMEL-5235
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Affects Versions: 2.9.2
> Reporter: Claus Ibsen
> Assignee: Claus Ibsen
> Fix For: 2.9.3, 2.10.0
>
>
> See nabble
> http://camel.465427.n5.nabble.com/File-Processor-Not-deleting-the-files-tp5670301.html
> Need to explicit close the file input/output streams to avoid the files to be locked on windows.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (CAMEL-5235) Make sure to close file input
stream when converting file to string to avoid locking file on windows
Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/CAMEL-5235?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13265725#comment-13265725 ]
Claus Ibsen commented on CAMEL-5235:
------------------------------------
Maybe but dont you still have the the issue that the File input/output streams do not get closed when the InputStreamWriter/OutputStreamWriter gets closed.
With the current code we explicit close those now.
> Make sure to close file input stream when converting file to string to avoid locking file on windows
> ----------------------------------------------------------------------------------------------------
>
> Key: CAMEL-5235
> URL: https://issues.apache.org/jira/browse/CAMEL-5235
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Affects Versions: 2.9.2
> Reporter: Claus Ibsen
> Assignee: Claus Ibsen
> Fix For: 2.9.3, 2.10.0
>
>
> See nabble
> http://camel.465427.n5.nabble.com/File-Processor-Not-deleting-the-files-tp5670301.html
> Need to explicit close the file input/output streams to avoid the files to be locked on windows.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (CAMEL-5235) Make sure to close file input
stream when converting file to string to avoid locking file on windows
Posted by "Babak Vahdat (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/CAMEL-5235?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13266421#comment-13266421 ]
Babak Vahdat commented on CAMEL-5235:
-------------------------------------
While trying to find some resources on the web describing what my *poor* english is talking about, I came along many of them but the best one was given through that *already dissappered real vendor* itself:
{quote}
Similarly, when closing chained streams, you only need to close the outermost stream class because the close() call is automatically trickled through all the chained classes; in the example above, you would simply call the close() method on the GZIPOutputStream class.
{quote}
When you look at the example there the inner most OutputStream is also a FileOutputStream, however there's no need of an explicit close call on that:
http://java.sun.com/developer/technicalArticles/Streams/ProgIOStreams/
So why I still ask for your approval to get rid of those two obsolete static member classes.
> Make sure to close file input stream when converting file to string to avoid locking file on windows
> ----------------------------------------------------------------------------------------------------
>
> Key: CAMEL-5235
> URL: https://issues.apache.org/jira/browse/CAMEL-5235
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Affects Versions: 2.9.2
> Reporter: Claus Ibsen
> Assignee: Claus Ibsen
> Fix For: 2.9.3, 2.10.0
>
>
> See nabble
> http://camel.465427.n5.nabble.com/File-Processor-Not-deleting-the-files-tp5670301.html
> Need to explicit close the file input/output streams to avoid the files to be locked on windows.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira