[JSch-users] problem with ChannelSftp.get() -> InputStream.read()
Status: Alpha
Brought to you by:
ymnk
From: Joe B. <jbu...@gm...> - 2005-10-03 15:16:00
|
I believe there may be an issue with the implementation of the InputStream returned from ChannelSftp.get(). When reading the stream byte by byte, the end-of-file condition is never set. The Java spec states that -1 should be returned if the end of the stream is reached. http://java.sun.com/j2se/1.5.0/docs/api/java/io/InputStream.html#read() It looks like the bitwise AND will truncate the negative value before retur= ning: // ChannelSftp.java ~line 803 in jsch-0.1.22-rc12 public int read() throws java.io.IOException{ read(_data, 0, 1); return _data[0]&0xff; } I've modified the code to return -1 when reached and it seems to work prope= rly: // return -1 explicitly when reached public int read() throws java.io.IOException{ int i =3D read(_data, 0, 1); if (i =3D=3D -1) { return -1; } else { return _data[0]&0xff; } } I believe the other read(*) methods work properly. Joe |