1 /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
3 Copyright (c) 2002-2010 ymnk, JCraft,Inc. All rights reserved.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in
13 the documentation and/or other materials provided with the distribution.
15 3. The names of the authors may not be used to endorse or promote products
16 derived from this software without specific prior written permission.
18 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
19 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
21 INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
22 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 package com.jcraft.jsch;
39 private boolean in_dontclose=false;
40 private boolean out_dontclose=false;
41 private boolean out_ext_dontclose=false;
43 void setOutputStream(OutputStream out){ this.out=out; }
44 void setOutputStream(OutputStream out, boolean dontclose){
45 this.out_dontclose=dontclose;
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);
53 void setInputStream(InputStream in){ this.in=in; }
54 void setInputStream(InputStream in, boolean dontclose){
55 this.in_dontclose=dontclose;
59 public void put(Packet p) throws IOException, java.net.SocketException {
60 out.write(p.buffer.buffer, 0, p.buffer.index);
63 void put(byte[] array, int begin, int length) throws IOException {
64 out.write(array, begin, length);
67 void put_ext(byte[] array, int begin, int length) throws IOException {
68 out_ext.write(array, begin, length);
72 int getByte() throws IOException {
76 void getByte(byte[] array) throws IOException {
77 getByte(array, 0, array.length);
80 void getByte(byte[] array, int begin, int length) throws IOException {
82 int completed = in.read(array, begin, length);
84 throw new IOException("End of IO Stream Read");
94 if(out!=null && !out_dontclose) out.close();
102 if(in!=null && !in_dontclose) in.close();
105 catch(Exception ee){}
110 if(out_ext!=null && !out_ext_dontclose) out_ext.close();
113 catch(Exception ee){}
117 public void finalize() throws Throwable{
119 if(in!=null) in.close();
121 catch(Exception ee){}
123 if(out!=null) out.close();
125 catch(Exception ee){}
127 if(out_ext!=null) out_ext.close();
129 catch(Exception ee){}