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

Quick Search    Search Deep

Source code: com/act365/net/tcp/TCPJInputStream.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   * <code>TCPJInputStream</code> reads data from a TCPJ socket.
33   */
34  
35  public class TCPJInputStream extends InputStream {
36  
37    TCPJSocketImpl socket ;
38    
39    /*
40     * Creates an input stream to read from the named socket.
41     */
42     
43    public TCPJInputStream( TCPJSocketImpl socket ){
44      this.socket = socket ;
45    }
46  
47    /**
48     * Reads a single byte.
49     */
50    
51    public int read() throws IOException {
52  
53      byte[] buffer = new byte[ 1 ];
54  
55      socket.read( buffer , 0 , 1 );
56  
57      return (int) buffer[ 0 ];
58    }
59  
60    /**
61     * Reads an entire buffer.
62     */
63    
64    public int read( byte[] buffer ) throws IOException {
65      
66      return socket.read( buffer , 0 , buffer.length ); 
67    }
68  
69    /**
70     * Reads a partial buffer.
71     */
72    
73    public int read( byte[] buffer , int offset , int count ) throws IOException {
74    
75      return socket.read( buffer , offset , count );
76    }
77  
78    /**
79     * Closes the stream.
80     */
81    
82    public void close() throws IOException {
83    
84      socket.close();
85    }
86  }
87