/* (non-Javadoc)
@see org.parosproxy.paros.db.paros.TableScan#read(int)
178308
@Override
	public synchronized RecordScan read(int scanId) throws DatabaseException {
    	SqlPreparedStatementWrapper psRead = null;
        try {
        	psRead = DbSQL.getSingleton().getPreparedStatement("scan.ps.read");
			psRead.getPs().setInt(1, scanId);
			
			try (ResultSet rs = psRead.getPs().executeQuery()) {
				return build(rs);
			}
		} catch (SQLException e) {
			throw new DatabaseException(e);
		} finally {
			DbSQL.getSingleton().releasePreparedStatement(psRead);
		}
	}
64116
public ServerPrepareResult read(PacketInputStream reader, boolean eofDeprecated)
      throws IOException, SQLException {
    Buffer buffer = reader.getPacket(true);
    byte firstByte = buffer.getByteAt(buffer.position);

    if (firstByte == ERROR) {
      throw buildErrorException(buffer);
    }

    if (firstByte == OK) {

      /* Prepared Statement OK */
      buffer.readByte(); /* skip field count */
      final int statementId = buffer.readInt();
      final int numColumns = buffer.readShort() & 0xffff;
      final int numParams = buffer.readShort() & 0xffff;

      ColumnInformation[] params = new ColumnInformation[numParams];
      ColumnInformation[] columns = new ColumnInformation[numColumns];

      if (numParams > 0) {
        for (int i = 0; i < numParams; i++) {
          params[i] = new ColumnInformation(reader.getPacket(false));
        }

        if (numColumns > 0) {
          if (!eofDeprecated) {
            protocol.skipEofPacket();
          }
          for (int i = 0; i < numColumns; i++) {
            columns[i] = new ColumnInformation(reader.getPacket(false));
          }
        }
        if (!eofDeprecated) {
          protocol.readEofPacket();
        }
      } else {
        if (numColumns > 0) {
          for (int i = 0; i < numColumns; i++) {
            columns[i] = new ColumnInformation(reader.getPacket(false));
          }
          if (!eofDeprecated) {
            protocol.readEofPacket();
          }
        } else {
          //read warning only if no param / columns, because will be overwritten by EOF warning data
          buffer.readByte(); // reserved
          protocol.setHasWarnings(buffer.readShort() > 0);
        }
      }

      ServerPrepareResult serverPrepareResult = new ServerPrepareResult(sql, statementId, columns,
          params, protocol);
      if (protocol.getOptions().cachePrepStmts
          && protocol.getOptions().useServerPrepStmts
          && sql != null
          && sql.length() < protocol.getOptions().prepStmtCacheSqlLimit) {
        String key = protocol.getDatabase() + "-" + sql;
        ServerPrepareResult cachedServerPrepareResult = protocol
            .addPrepareInCache(key, serverPrepareResult);
        return cachedServerPrepareResult != null ? cachedServerPrepareResult : serverPrepareResult;
      }
      return serverPrepareResult;

    } else {
      throw new SQLException("Unexpected packet returned by server, first byte " + firstByte);
    }
  }
1047526
@Override
	public int read(byte[] b, int off, int len) throws IOException
    {
        if (len == 0)
            return 0;
        
        int totalRead = 0;
        do
        {
            int amount = readBufferedOrAvailable(b,off+totalRead,len-totalRead);
            if (amount <= 0)
                return (totalRead == 0) ? amount : totalRead;
            totalRead += amount;
            
            // Did we get enough ?
            if (totalRead >= len)
                break;
        }
        while (in.available() > 0);
        
        return totalRead;
    }
535328
@Override
    public int read(byte[] output, int offset, int length) throws IOException {
        synchronized(this){
            int value = 0;
            if(closed) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isErrorEnabled())
                    Tr.error(tc, "stream.is.closed.no.read.write");
                throw new IOException(Tr.formatMessage(tc, "stream.is.closed.no.read.write"));
            }
            if(output == null){
                if (TraceComponent.isAnyTracingEnabled() && tc.isErrorEnabled())
                    Tr.error(tc, "read.write.bytearray.null");
                throw new NullPointerException(Tr.formatMessage(tc, "read.write.bytearray.null"));
            }
            if((offset < 0) || (length < 0) || (length > (output.length - offset))){
                if (TraceComponent.isAnyTracingEnabled() && tc.isErrorEnabled())
                    Tr.error(tc, "read.write.offset.length.bytearraylength", new Object[] {offset, length, output.length});
                throw new IndexOutOfBoundsException(Tr.formatMessage(tc, "read.write.offset.length.bytearraylength", new Object[] {offset, length, output.length}));
            }

            if (this._inBuffer != null) {
                value = _inBuffer.read(output, offset, length);
            }
            else {
                value = this.in.read(output, offset, length);
            }

            return value;
        }
    }
1106877
@Override
    public int read() throws IOException {
        int r = read(singleByte, 0, 1);
        while (r == 0) {
            r = read(singleByte, 0, 1);
        }
        if (r > 0) {
            final byte b = singleByte[0];
            return b < 0 ? 256 + b : b;
        }
        return EOF;
    }
847314
public int read(byte []buf, int offset, int length) throws IOException
  {
    if (_stream != null)
      return _stream.read(buf, offset, length);
    else
      return -1;
  }
41877
public int read(byte []buffer, int offset, int length)
    throws IOException
  {
    int len = _next.read(buffer, offset, length);

    _crc = Crc64.generate(_crc, buffer, offset, len);

    return len;
  }
522979
@Override
    public int read(byte[] output, int offset, int length) throws IOException {
        
        //Return -1 here because if we are closed or finished, we're at the end of the stream
        if(isClosed || isFinished()){
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                Tr.debug(tc, "Nothing to read, stream is closed : " + isClosed + ", or finished : " + isFinished());
            return -1;
        }        
        
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(tc, "read" , "SRTInputStream31.read(byte[], int, int)");
        }
        
        if(output == null){
            if (TraceComponent.isAnyTracingEnabled() && tc.isErrorEnabled())
                Tr.error(tc, "read.write.bytearray.null");
            throw new NullPointerException(Tr.formatMessage(tc, "read.write.bytearray.null"));
        }
        if((offset < 0) || (length < 0) || (length > (output.length - offset))){
            if (TraceComponent.isAnyTracingEnabled() && tc.isErrorEnabled())
                Tr.error(tc, "read.write.offset.length.bytearraylength", new Object[] {offset, length, output.length});
            throw new IndexOutOfBoundsException(Tr.formatMessage(tc, "read.write.offset.length.bytearraylength", new Object[] {offset, length, output.length}));
        }
        
        int returnSize = 0;
        
        if(this.request.isAsyncStarted() && (this.getReadListener()!= null)){
            synchronized(this){
                //Check if isReady had returned false. If it did then an IllegalArgumentException will be thrown if a listener is set
                isReadyFalseCheck();
                
                returnSize = super.read(output, offset, length);
            }
        } else{
            returnSize = super.read(output, offset, length);
        }
        
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(tc, "read" , "SRTInputStream31.read(byte[], int, int) : " + returnSize);
        }
        
        return returnSize;
    }
1126123
@Override
  public int read(byte []buf, int offset, int length) throws IOException
  {
    try {
      SocketChannel s = _s;
      
      if (s == null) {
        return -1;
      }
      
      int remaining = _readBuffer.remaining();
      if (remaining <= 0) {
        _readBuffer.clear();
        
        if (s.read(_readBuffer) < 0) {
          _readBuffer.flip();
          return -1;
        }
        
        _readBuffer.flip();
        
        remaining = _readBuffer.remaining();
      }
      
      int sublen = Math.min(remaining, length); 

      _readBuffer.get(buf, offset, sublen);
      
      int readLength = sublen;

      if (readLength >= 0) {
        _totalReadBytes += readLength;
      }

      return readLength;
    } catch (InterruptedIOException e) {
      if (_throwReadInterrupts)
        throw e;
      
      log.log(Level.FINEST, e.toString(), e);
    } catch (IOException e) {
      if (_throwReadInterrupts) {
        throw e;
      }

      if (log.isLoggable(Level.FINEST)) {
        log.log(Level.FINEST, e.toString(), e);
      }
      else {
        log.finer(e.toString());
      }
      // server/0611
      /*
      try {
        close();
      } catch (IOException e1) {
      }
      */
    }

    return -1;
  }
762387
@Override
	public int read(byte[] b) throws IOException {
		int result = stream.read(b);
		update(result);
		return result;
	}
861848
@Override
    public List readData(String tableName, EntityMetadata m, final Object rowKey, byte[] startRow, byte[] endRow,
            List<Map<String, Object>> columnsToOutput, FilterList filterList) throws IOException
    {
        Table hTable = gethTable(tableName);
        filterList = getExtPropertyFilters(m, filterList);
        boolean isFindKeyOnly = HBaseUtils.isFindKeyOnly(m, columnsToOutput);
        filterList = onFindKeyOnly(filterList, isFindKeyOnly);
        List<HBaseDataWrapper> results = hbaseReader.loadData(hTable, rowKey, startRow, endRow, null, filterList,
                !isFindKeyOnly ? columnsToOutput : new ArrayList<Map<String, Object>>());
        return onRead(m, columnsToOutput, hTable, results);
    }
727327
@Override
  public int read(byte []buf, int offset, int length)
    throws IOException
  {
    if (buf == null)
      throw new NullPointerException();
    else if (offset < 0 || buf.length < offset + length)
      throw new ArrayIndexOutOfBoundsException();

    int result = nativeRead(_fd, buf, offset, length);

    if (result > 0)
      _pos += result;

    return result;
  }
634743
public int read() throws IOException {
        int b = in.read();
        if (b != -1) {
            cksum.update(b);
        }
        return b;
    }
724898
@Override
  public P readPage(int pageID) {
    try {
      countRead();
      long offset = ((long) (header.getReservedPages() + pageID)) * (long) pageSize;
      byte[] buffer = new byte[pageSize];
      file.seek(offset);
      file.read(buffer);
      return byteArrayToPage(buffer);
    }
    catch(IOException e) {
      throw new RuntimeException("IOException occurred during reading of page " + pageID + "\n", e);
    }
  }
521616
@Override
  public synchronized int read(byte[] buf, int off, int len)
      throws IOException {
    checkNotClosed();

    validatePositionedReadArgs(nextReadPos, buf, off, len);
    if (len == 0) {
      return 0;
    }

    if (contentLength == 0 || (nextReadPos >= contentLength)) {
      return -1;
    }

    try {
      lazySeek(nextReadPos, len);
    } catch (EOFException e) {
      // the end of the file has moved
      return -1;
    }

    int bytesRead;
    try {
      bytesRead = wrappedStream.read(buf, off, len);
    } catch (EOFException e) {
      onReadFailure(e, len);
      // the base implementation swallows EOFs.
      return -1;
    } catch (IOException e) {
      onReadFailure(e, len);
      bytesRead = wrappedStream.read(buf, off, len);
    }

    if (bytesRead > 0) {
      pos += bytesRead;
      nextReadPos += bytesRead;
    }
    incrementBytesRead(bytesRead);
    return bytesRead;
  }
314621
@Override
  public IScan getScanByNum(int scanNum) {
    IScan scan = getNum2scan().get(scanNum);
    if (scan != null) {
      return scan;
    }
    return null;
  }
1223564
@javax.annotation.Nonnull
  public static byte[] read(@javax.annotation.Nonnull final DataInputStream i, final int s) throws IOException {
    @javax.annotation.Nonnull final byte[] b = new byte[s];
    int pos = 0;
    while (b.length > pos) {
      final int read = i.read(b, pos, b.length - pos);
      if (0 == read) {
        throw new RuntimeException();
      }
      pos += read;
    }
    return b;
  }