comparison app/src/main/java/ch/ethz/ssh2/channel/ChannelOutputStream.java @ 438:d29cce60f393

migrate from Eclipse to Android Studio
author Carl Byington <carl@five-ten-sg.com>
date Thu, 03 Dec 2015 11:23:55 -0800
parents src/ch/ethz/ssh2/channel/ChannelOutputStream.java@071eccdff8ea
children
comparison
equal deleted inserted replaced
437:208b31032318 438:d29cce60f393
1 /*
2 * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 * Please refer to the LICENSE.txt for licensing details.
4 */
5 package ch.ethz.ssh2.channel;
6
7 import java.io.IOException;
8 import java.io.OutputStream;
9
10 /**
11 * ChannelOutputStream.
12 *
13 * @author Christian Plattner
14 * @version 2.50, 03/15/10
15 */
16 public final class ChannelOutputStream extends OutputStream {
17 Channel c;
18
19 boolean isClosed = false;
20
21 ChannelOutputStream(Channel c) {
22 this.c = c;
23 }
24
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 }
31
32 @Override
33 public void close() throws IOException {
34 if (isClosed == false) {
35 isClosed = true;
36 c.cm.sendEOF(c);
37 }
38 }
39
40 @Override
41 public void flush() throws IOException {
42 if (isClosed)
43 throw new IOException("This OutputStream is closed.");
44
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.");
52
53 if (b == null)
54 throw new NullPointerException();
55
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;
61
62 c.cm.sendData(c, b, off, len);
63 }
64
65 @Override
66 public void write(byte[] b) throws IOException {
67 write(b, 0, b.length);
68 }
69 }