00001 using System;
00002 using System.IO;
00003 using Tamir.SharpSsh.java.io;
00004
00005 namespace Tamir.SharpSsh.jsch
00006 {
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 public class IO
00037 {
00038 internal JStream ins;
00039 internal JStream outs;
00040 internal JStream outs_ext;
00041
00042 private bool in_dontclose=false;
00043 private bool out_dontclose=false;
00044 private bool outs_ext_dontclose=false;
00045
00046 public void setOutputStream(Stream outs)
00047 {
00048 if(outs!=null)
00049 {
00050 this.outs= new JStream(outs);
00051 }
00052 else
00053 {
00054 this.outs=null;
00055 }
00056 }
00057 public void setOutputStream(Stream outs, bool dontclose)
00058 {
00059 this.out_dontclose=dontclose;
00060 setOutputStream(outs);
00061 }
00062 public void setExtOutputStream(Stream outs)
00063 {
00064 if(outs!=null)
00065 {
00066 this.outs_ext=new JStream(outs);
00067 }
00068 else
00069 {
00070 this.outs_ext=null;
00071 }
00072 }
00073 public void setExtOutputStream(Stream outs, bool dontclose)
00074 {
00075 this.outs_ext_dontclose=dontclose;
00076 setExtOutputStream(outs);
00077 }
00078 public void setInputStream(Stream ins)
00079 {
00080
00081 if(ins!=null)
00082 {
00083 if(ins.GetType() == Type.GetType("System.IO.__ConsoleStream"))
00084 {
00085 ins = new Tamir.Streams.ProtectedConsoleStream(ins);
00086 }
00087 else if(ins.GetType() == Type.GetType("System.IO.FileStream"))
00088 {
00089 ins = new Tamir.Streams.ProtectedConsoleStream(ins);
00090 }
00091 this.ins=new JStream(ins);
00092 }
00093 else
00094 {
00095 this.ins=null;
00096 }
00097 }
00098 public void setInputStream(Stream ins, bool dontclose)
00099 {
00100 this.in_dontclose=dontclose;
00101 setInputStream(ins);
00102 }
00103
00104 public void put(Packet p)
00105 {
00106 outs.Write(p.buffer.buffer, 0, p.buffer.index);
00107 outs.Flush();
00108 }
00109 internal void put(byte[] array, int begin, int length)
00110 {
00111 outs.Write(array, begin, length);
00112 outs.Flush();
00113 }
00114 internal void put_ext(byte[] array, int begin, int length)
00115 {
00116 outs_ext.Write(array, begin, length);
00117 outs_ext.Flush();
00118 }
00119
00120 internal int getByte()
00121 {
00122 int res = ins.ReadByte()&0xff;
00123 return res;
00124 }
00125
00126 internal void getByte(byte[] array)
00127 {
00128 getByte(array, 0, array.Length);
00129 }
00130
00131 internal void getByte(byte[] array, int begin, int length)
00132 {
00133 do
00134 {
00135 int completed = ins.Read(array, begin, length);
00136 if(completed<=0)
00137 {
00138 throw new IOException("End of IO Stream Read");
00139 }
00140 begin+=completed;
00141 length-=completed;
00142 }
00143 while (length>0);
00144 }
00145
00146 public void close()
00147 {
00148 try
00149 {
00150 if(ins!=null && !in_dontclose) ins.Close();
00151 ins=null;
00152 }
00153 catch(Exception ee){}
00154 try
00155 {
00156 if(outs!=null && !out_dontclose) outs.Close();
00157 outs=null;
00158 }
00159 catch(Exception ee){}
00160 try
00161 {
00162 if(outs_ext!=null && !outs_ext_dontclose) outs_ext.Close();
00163 outs_ext=null;
00164 }
00165 catch(Exception ee){}
00166 }
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 }
00182
00183 }