Source code: com/act365/net/tcp/TCPJOutputStream.java
1 /*
2 * JSocket Wrench
3 *
4 * Copyright (C) act365.com October 2003
5 *
6 * Web site: http://www.act365.com/wrench
7 * E-mail: developers@act365.com
8 *
9 * The JSocket Wrench library adds support for low-level Internet protocols
10 * to the Java programming language.
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 2 of the License, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
20 * Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
27 package com.act365.net.tcp ;
28
29 import java.io.*;
30
31 /**
32 * Writes to a TCPJ socket.
33 */
34
35 public class TCPJOutputStream extends OutputStream {
36
37 TCPJSocketImpl socket ;
38
39 /**
40 * Creates an output stream to write to the given socket.
41 */
42
43 public TCPJOutputStream( TCPJSocketImpl socket ){
44 this.socket = socket ;
45 }
46
47 /**
48 * Writes a single byte.
49 */
50
51 public void write( int oneByte ) throws IOException {
52
53 byte buffer[] = { (byte) oneByte };
54
55 socket.write( buffer , 0 , 1 );
56 }
57
58 /**
59 * Writes an entire buffer.
60 */
61
62 public void write( byte[] buffer ) throws IOException {
63
64 socket.write( buffer , 0 , buffer.length );
65 }
66
67 /**
68 * Writes a partial buffer.
69 */
70
71 public void write( byte[] buffer , int offset , int count ) throws IOException {
72
73 socket.write( buffer , offset , count );
74 }
75
76 /**
77 * Closes the output stream.
78 */
79
80 public void close() throws IOException {
81
82 socket.close();
83 }
84 }
85