Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/act365/net/GeneralSocketOutputStream.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 ;
28  
29  import java.io.*;
30  
31  /**
32   * <code>GeneralSocketOutputStream</code> writes to a TCP socket. 
33   * The class should be used in conjunction with <code>GeneralSocketImpl</code>.
34   * @see GeneralSocketImpl
35   */
36  
37  public class GeneralSocketOutputStream extends OutputStream {
38  
39    int socketDescriptor ;
40  
41    /**
42     * Creates an output stream to write to the TCP socket with the given descriptor.
43     * @param socketDescriptor socket file descriptor
44     */
45  
46    public GeneralSocketOutputStream( int socketDescriptor ){
47      this.socketDescriptor = socketDescriptor ;
48    }
49  
50    /**
51     * Writes a single character to the TCP stream.
52     */
53    
54    public void write( int oneByte ) throws IOException {
55  
56      byte buffer[] = { (byte) oneByte };
57  
58      _send( socketDescriptor , buffer , 0 , 1 );
59    }
60  
61    /**
62     * Writes a string of characters into the TCP stream from a buffer.
63     * @param buffer the buffer the characters are to be read from
64     */
65    
66    public void write( byte[] buffer ) throws IOException {
67      
68      int sent = _send( socketDescriptor , buffer , 0 , buffer.length );
69    }
70  
71    /**
72     * Writes a string of characters into the TCP stream from a given
73     * location in a buffer.
74     * @param buffer the buffer the characters are to be read from
75     * @param offset the array location from where the input is to be read
76     * @param count the number of characters to be read
77     */
78    
79    public void write( byte[] buffer , int offset , int count ) throws IOException {
80    
81      _send( socketDescriptor , buffer , offset , count );
82    }
83  
84    static native int _send( int socketDescriptor , byte[] buffer , int offset , int count );
85  
86    /**
87     * Closes the output stream.
88     */
89    
90    public void close() throws IOException {
91  
92      int ret = _close( socketDescriptor );
93    }
94  
95    static native int _close( int socketDescriptor );
96  }
97