3

I am using VFS 2.0 for implementing SFTP for my application. I have a single Thread which actually picks up the file and do SFTP. 98% of the time it works. But I have observed there are few cases where SFTP is getting failed with below exception..

Caused by: org.apache.commons.vfs2.FileSystemException: Could not close the output stream for file "sftp://*******************/Test.csv".
    [null,null]at org.apache.commons.vfs2.provider.DefaultFileContent$FileContentOutputStream.close(DefaultFileContent.java:694)
    [null,null]at org.apache.commons.vfs2.FileUtil.copyContent(FileUtil.java:118)
    [null,null]at org.apache.commons.vfs2.provider.AbstractFileObject.copyFrom(AbstractFileObject.java:1053)
    [null,null]... 3 more
Caused by: java.io.IOException: inputstream is closed
    [null,null]at com.jcraft.jsch.ChannelSftp.fill(ChannelSftp.java:2884)
    [null,null]at com.jcraft.jsch.ChannelSftp.header(ChannelSftp.java:2908)
    [null,null]at com.jcraft.jsch.ChannelSftp.checkStatus(ChannelSftp.java:2446)
    [null,null]at com.jcraft.jsch.ChannelSftp._sendCLOSE(ChannelSftp.java:2465)
    [null,null]at com.jcraft.jsch.ChannelSftp.access$400(ChannelSftp.java:36)
    [null,null]at com.jcraft.jsch.ChannelSftp$1.close(ChannelSftp.java:854)
    [null,null]at java.io.FilterOutputStream.close(FilterOutputStream.java:143)
    [null,null]at org.apache.commons.vfs2.util.MonitorOutputStream.close(MonitorOutputStream.java:56)
    [null,null]at java.io.FilterOutputStream.close(FilterOutputStream.java:143)
    [null,null]at org.apache.commons.vfs2.util.MonitorOutputStream.close(MonitorOutputStream.java:56)
    [null,null]at org.apache.commons.vfs2.provider.DefaultFileContent$FileContentOutputStream.close(DefaultFileContent.java:690)
    [null,null]... 5 more

Please suggest what could be the possible reason for the above exception.

Arajit
  • 133
  • 3
  • 15
  • 1
    Some of the classes that handle InputStream in java automatically closes it after it finishes the process, so it is possible that your code or the library you are using is passing the InputStream to one of that handlers. The classes that do that implements the interface `java.lang.AutoCloseable` you should check your code or the library. – Jorge Campos Sep 02 '15 at 23:06
  • 1
    Please note I have observed that, For all the cases when exception is getting thrown after 20 seconds of starting SFTP of the file. – Arajit Sep 02 '15 at 23:19
  • Jorge Campos - It seems java.lang.AutoCloseable is available only from Java 1.7. But our application is using java 1.6 – Arajit Sep 02 '15 at 23:22
  • Is it possible that a thread start before other finishes? Because if it is the case and any class use the InputStream as static they are sharing the same instance which can be causing the erratic behavior. Just a guess though – Jorge Campos Sep 02 '15 at 23:25
  • Actually we have coded in a such a way that there will only on Thread running. It will pickup the file do the SFTP. Multiple Thread is not getting created here. – Arajit Sep 03 '15 at 00:08

0 Answers0