IO.java
Go to the documentation of this file.00001
00002
00003
00004
00005
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 package com.jcraft.jsch;
00031
00032 import java.io.*;
00033
00043 public class IO{
00044 InputStream in;
00045 OutputStream out;
00046 OutputStream out_ext;
00047
00048 private boolean in_dontclose=false;
00049 private boolean out_dontclose=false;
00050 private boolean out_ext_dontclose=false;
00051
00052 void setOutputStream(OutputStream out){ this.out=out; }
00053 void setOutputStream(OutputStream out, boolean dontclose){
00054 this.out_dontclose=dontclose;
00055 setOutputStream(out);
00056 }
00057 void setExtOutputStream(OutputStream out){ this.out_ext=out; }
00058 void setExtOutputStream(OutputStream out, boolean dontclose){
00059 this.out_ext_dontclose=dontclose;
00060 setExtOutputStream(out);
00061 }
00062 void setInputStream(InputStream in){ this.in=in; }
00063 void setInputStream(InputStream in, boolean dontclose){
00064 this.in_dontclose=dontclose;
00065 setInputStream(in);
00066 }
00067
00068 public void put(Packet p) throws IOException, java.net.SocketException {
00069 out.write(p.buffer.buffer, 0, p.buffer.index);
00070 out.flush();
00071 }
00072 void put(byte[] array, int begin, int length) throws IOException {
00073 out.write(array, begin, length);
00074 out.flush();
00075 }
00076 void put_ext(byte[] array, int begin, int length) throws IOException {
00077 out_ext.write(array, begin, length);
00078 out_ext.flush();
00079 }
00080
00081 int getByte() throws IOException {
00082 return in.read();
00083 }
00084
00085 void getByte(byte[] array) throws IOException {
00086 getByte(array, 0, array.length);
00087 }
00088
00089 void getByte(byte[] array, int begin, int length) throws IOException {
00090 do{
00091 int completed = in.read(array, begin, length);
00092 if(completed<0){
00093 throw new IOException("End of IO Stream Read");
00094 }
00095 begin+=completed;
00096 length-=completed;
00097 }
00098 while (length>0);
00099 }
00100
00101 void out_close(){
00102 try{
00103 if(out!=null && !out_dontclose) out.close();
00104 out=null;
00105 }
00106 catch(Exception ee){}
00107 }
00108
00109 public void close(){
00110 try{
00111 if(in!=null && !in_dontclose) in.close();
00112 in=null;
00113 }
00114 catch(Exception ee){}
00115
00116 out_close();
00117
00118 try{
00119 if(out_ext!=null && !out_ext_dontclose) out_ext.close();
00120 out_ext=null;
00121 }
00122 catch(Exception ee){}
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 }