1 2 29 30 package com.jcraft.jsch; 31 32 import java.io.*; 33 34 public class IO{ 35 InputStream in; 36 OutputStream out; 37 OutputStream out_ext; 38 39 private boolean in_dontclose=false; 40 private boolean out_dontclose=false; 41 private boolean out_ext_dontclose=false; 42 43 void setOutputStream(OutputStream out){ this.out=out; } 44 void setOutputStream(OutputStream out, boolean dontclose){ 45 this.out_dontclose=dontclose; 46 setOutputStream(out); 47 } 48 void setExtOutputStream(OutputStream out){ this.out_ext=out; } 49 void setExtOutputStream(OutputStream out, boolean dontclose){ 50 this.out_ext_dontclose=dontclose; 51 setExtOutputStream(out); 52 } 53 void setInputStream(InputStream in){ this.in=in; } 54 void setInputStream(InputStream in, boolean dontclose){ 55 this.in_dontclose=dontclose; 56 setInputStream(in); 57 } 58 59 public void put(Packet p) throws IOException, java.net.SocketException { 60 out.write(p.buffer.buffer, 0, p.buffer.index); 61 out.flush(); 62 } 63 void put(byte[] array, int begin, int length) throws IOException { 64 out.write(array, begin, length); 65 out.flush(); 66 } 67 void put_ext(byte[] array, int begin, int length) throws IOException { 68 out_ext.write(array, begin, length); 69 out_ext.flush(); 70 } 71 72 int getByte() throws IOException { 73 return in.read(); 74 } 75 76 void getByte(byte[] array) throws IOException { 77 getByte(array, 0, array.length); 78 } 79 80 void getByte(byte[] array, int begin, int length) throws IOException { 81 do{ 82 int completed = in.read(array, begin, length); 83 if(completed<0){ 84 throw new IOException("End of IO Stream Read"); 85 } 86 begin+=completed; 87 length-=completed; 88 } 89 while (length>0); 90 } 91 92 public void close(){ 93 try{ 94 if(in!=null && !in_dontclose) in.close(); 95 in=null; 96 } 97 catch(Exception ee){} 98 try{ 99 if(out!=null && !out_dontclose) out.close(); 100 out=null; 101 } 102 catch(Exception ee){} 103 try{ 104 if(out_ext!=null && !out_ext_dontclose) out_ext.close(); 105 out_ext=null; 106 } 107 catch(Exception ee){} 108 } 109 110 126 } 127 | Popular Tags |