Mercurial > 510Connectbot
annotate src/ch/ethz/ssh2/channel/ChannelOutputStream.java @ 431:a0bff4b39512
Added tag stable-1.9.0-9 for changeset 47de9ffed872
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 26 Dec 2014 10:35:50 -0800 |
parents | 071eccdff8ea |
children |
rev | line source |
---|---|
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
1 /* |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
2 * Copyright (c) 2006-2011 Christian Plattner. All rights reserved. |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
3 * Please refer to the LICENSE.txt for licensing details. |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
4 */ |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
5 package ch.ethz.ssh2.channel; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
6 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
7 import java.io.IOException; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
8 import java.io.OutputStream; |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
9 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
10 /** |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
11 * ChannelOutputStream. |
307 | 12 * |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
13 * @author Christian Plattner |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
14 * @version 2.50, 03/15/10 |
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
15 */ |
307 | 16 public final class ChannelOutputStream extends OutputStream { |
17 Channel c; | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
18 |
307 | 19 boolean isClosed = false; |
20 | |
21 ChannelOutputStream(Channel c) { | |
22 this.c = c; | |
23 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
24 |
307 | 25 @Override |
26 public void write(int b) throws IOException { | |
27 byte[] buff = new byte[1]; | |
28 buff[0] = (byte) b; | |
29 write(buff, 0, 1); | |
30 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
31 |
307 | 32 @Override |
33 public void close() throws IOException { | |
34 if (isClosed == false) { | |
35 isClosed = true; | |
36 c.cm.sendEOF(c); | |
37 } | |
38 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
39 |
307 | 40 @Override |
41 public void flush() throws IOException { | |
42 if (isClosed) | |
43 throw new IOException("This OutputStream is closed."); | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
44 |
307 | 45 /* This is a no-op, since this stream is unbuffered */ |
46 } | |
47 | |
48 @Override | |
49 public void write(byte[] b, int off, int len) throws IOException { | |
50 if (isClosed) | |
51 throw new IOException("This OutputStream is closed."); | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
52 |
307 | 53 if (b == null) |
54 throw new NullPointerException(); | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
55 |
307 | 56 if ((off < 0) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0) || (off > b.length)) |
57 throw new IndexOutOfBoundsException(); | |
58 | |
59 if (len == 0) | |
60 return; | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
61 |
307 | 62 c.cm.sendData(c, b, off, len); |
63 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
64 |
307 | 65 @Override |
66 public void write(byte[] b) throws IOException { | |
67 write(b, 0, b.length); | |
68 } | |
273
91a31873c42a
start conversion from trilead to ganymed
Carl Byington <carl@five-ten-sg.com>
parents:
diff
changeset
|
69 } |