00001 //using System; 00002 //using System.IO; 00003 // 00004 //namespace Tamir.SharpSsh.jsch 00005 //{ 00006 // public class InputStreamGet : java.io.InputStream 00007 // { 00008 // bool closed=false; 00009 // int rest_length=0; 00010 // byte[] _data=new byte[1]; 00011 // ChannelSftp sftp; 00012 // byte[] handle; 00013 // long[] _offset; 00014 // int[]_server_version; 00015 // SftpProgressMonitor monitor; 00016 // 00017 // public InputStreamGet( 00018 // ChannelSftp sftp, 00019 // byte[] handle, 00020 // long[] _offset, 00021 // int[] _server_version, 00022 // SftpProgressMonitor monitor) 00023 // { 00024 // this.sftp=sftp; 00025 // this.handle=handle; 00026 // this._offset=_offset; 00027 // this._server_version=_server_version; 00028 // this.monitor=monitor; 00029 // } 00030 // 00031 // public override int ReadByte() 00032 // { 00033 // int i=read(_data, 0, 1); 00034 // if (i==-1) { return -1; } 00035 // else 00036 // { 00037 // return _data[0]&0xff; 00038 // } 00039 // } 00040 // public override int read(byte[] d) 00041 // { 00042 // return Read(d, 0, d.Length); 00043 // } 00044 // public override int Read(byte[] d, int s, int len) 00045 // { 00046 // if(d==null){throw new NullReferenceException();} 00047 // if(s<0 || len <0 || s+len>d.Length) 00048 // { 00049 // throw new ArgumentOutOfRangeException(); 00050 // } 00051 // if(len==0){ return 0; } 00052 // 00053 // if(rest_length>0) 00054 // { 00055 // int foo=rest_length; 00056 // if(foo>len) foo=len; 00057 // int i=sftp.io.ins.read(d, s, foo); 00058 // if(i<0) 00059 // { 00060 // throw new IOException("error"); 00061 // } 00062 // rest_length-=i; 00063 // return i; 00064 // } 00065 // 00066 // if(sftp.buf.buffer.length-13<len) 00067 // { 00068 // len=sftp.buf.buffer.length-13; 00069 // } 00070 // if(sftp.server_version==0 && len>1024) 00071 // { 00072 // len=1024; 00073 // } 00074 // 00075 // try{sftp.sendREAD(handle, offset, len);} 00076 // catch(Exception e){ throw new IOException("error"); } 00077 // 00078 // sftp.buf.rewind(); 00079 // int i=io.ins.read(buf.buffer, 0, 13); // 4 + 1 + 4 + 4 00080 // if(i!=13) 00081 // { 00082 // throw new IOException("error"); 00083 // } 00084 // 00085 // rest_length=sftp.buf.getInt(); 00086 // int type=sftp.buf.getByte(); 00087 // rest_length--; 00088 // sftp.buf.getInt(); 00089 // rest_length-=4; 00090 // if(type!=sftp.SSH_FXP_STATUS && type!=SSH_FXP_DATA) 00091 // { 00092 // throw new IOException("error"); 00093 // } 00094 // if(type==sftp.SSH_FXP_STATUS) 00095 // { 00096 // i=buf.getInt(); 00097 // rest_length-=4; 00098 // sftp.io.ins.read(sftp.buf.buffer, 13, rest_length); 00099 // rest_length=0; 00100 // if(i==SSH_FX_EOF) 00101 // { 00102 // close(); 00103 // return -1; 00104 // } 00105 // //throwStatusError(buf, i); 00106 // throw new IOException("error"); 00107 // } 00108 // 00109 // i=buf.getInt(); 00110 // rest_length-=4; 00111 // offset+=rest_length; 00112 // int foo=i; 00113 // if(foo>0) 00114 // { 00115 // int bar=rest_length; 00116 // if(bar>len) 00117 // { 00118 // bar=len; 00119 // } 00120 // i=io.ins.read(d, s, bar); 00121 // if(i<0) 00122 // { 00123 // return -1; 00124 // } 00125 // rest_length-=i; 00126 // 00127 // if(monitor!=null) 00128 // { 00129 // if(!monitor.count(i)) 00130 // { 00131 // return -1; 00132 // } 00133 // } 00134 // return i; 00135 // } 00136 // return 0; // ?? 00137 // } 00138 // public override void Close() 00139 // { 00140 // if(closed)return; 00141 // closed=true; 00142 // /* 00143 // while(rest_length>0){ 00144 // int foo=rest_length; 00145 // if(foo>buf.buffer.length){ 00146 // foo=buf.buffer.length; 00147 // } 00148 // io.in.read(buf.buffer, 0, foo); 00149 // rest_length-=foo; 00150 // } 00151 // */ 00152 // if(monitor!=null)monitor.end(); 00153 // try{sftp._sendCLOSE(handle);} 00154 // catch(Exception e){throw new IOException("error");} 00155 // } 00156 // } 00157 //}
1.5.9