Code example for Socket

Methods: getChannel, getSoTimeout

0
   *   
   * @param socket should have a channel associated with it. 
   * @throws IOException 
   */ 
  public SocketInputStream(Socket socket) throws IOException {
    this(socket.getChannel(), socket.getSoTimeout());
  } 
   
  @Override 
  public int read() throws IOException { 
    /* Allocation can be removed if required. 
     * probably no need to optimize or encourage single byte read. 
     */ 
    byte[] buf = new byte[1];
    int ret = read(buf, 0, 1);
    if (ret > 0) {
      return (byte)buf[0];
    } 
    if (ret != -1) {
      // unexpected 
      throw new IOException("Could not read from stream");