/* (non-Javadoc)
@see org.parosproxy.paros.db.paros.TableTag#read(long)
495212
@Override
	public synchronized RecordTag read(long tagId) throws DatabaseException {
    	SqlPreparedStatementWrapper psRead = null;
        try {
        	psRead = DbSQL.getSingleton().getPreparedStatement("tag.ps.read");
			psRead.getPs().setLong(1, tagId);
			
			try (ResultSet rs = psRead.getPs().executeQuery()) {
				return build(rs);
			}
		} catch (SQLException e) {
			throw new DatabaseException(e);
		} finally {
			DbSQL.getSingleton().releasePreparedStatement(psRead);
		}
	}
384024
@Override
  public final Long getLong(final String pColumnName) throws Exception {
    int columnIndex = this.resultSet.getColumnIndex(pColumnName);
    Long result = null;
    if (!this.resultSet.isNull(columnIndex)) {
      result = this.resultSet.getLong(columnIndex);
    }
    return result;
  }
458179
public int read(long fileOffset, byte []buffer, int offset, int length)
    throws IOException
  {
    _file.seek(fileOffset);
    
    return _file.read(buffer, offset, length);
  }
28218
public void read(ByteBuffer buffer) {
        Persistables.persistable(streamableNoBuffers()).read(buffer);

        final int n = getNumDataBuffers();
        int lengthsPosition = buffer.position();
        buffer.position(buffer.position() + 2 * n); // skip positions
        for (int i = 0; i < n; i++) {
            final int size = buffer.getShort(lengthsPosition) & 0xFFFF; // big-endian
            lengthsPosition += 2;

            final ByteBuffer b1 = Persistables.slice(buffer, size);
            setDataBuffer(i, b1);
        }
    }
583028
public void read(long pos, Buffer sink, long byteCount) throws IOException {
    if (byteCount < 0) throw new IndexOutOfBoundsException();

    while (byteCount > 0L) {
      long bytesRead = fileChannel.transferTo(pos, byteCount, sink);
      pos += bytesRead;
      byteCount -= bytesRead;
    }
  }
562785
public long readVLong() {
        /* This is the original code of this method,
         * but a Hotspot bug (see LUCENE-2975) corrupts the for-loop if
         * readByte() is inlined. So the loop was unwinded!
         byte b = readByte();
         long i = b & 0x7F;
         for (int shift = 7; (b & 0x80) != 0; shift += 7) {
         b = readByte();
         i |= (b & 0x7FL) << shift;
         }
         return i;
         */
        byte b = readByte();
        if (b >= 0) {
            return b;
        }
        long i = b & 0x7FL;
        b = readByte();
        i |= (b & 0x7FL) << 7;
        if (b >= 0) {
            return i;
        }
        b = readByte();
        i |= (b & 0x7FL) << 14;
        if (b >= 0) {
            return i;
        }
        b = readByte();
        i |= (b & 0x7FL) << 21;
        if (b >= 0) {
            return i;
        }
        b = readByte();
        i |= (b & 0x7FL) << 28;
        if (b >= 0) {
            return i;
        }
        b = readByte();
        i |= (b & 0x7FL) << 35;
        if (b >= 0) {
            return i;
        }
        b = readByte();
        i |= (b & 0x7FL) << 42;
        if (b >= 0) {
            return i;
        }
        b = readByte();
        i |= (b & 0x7FL) << 49;
        if (b >= 0) {
            return i;
        }
        b = readByte();
        i |= (b & 0x7FL) << 56;
        if (b >= 0) {
            return i;
        }
        throw new RuntimeException("Invalid vLong detected (negative values disallowed)");
    }
1042396
public static long readLong(ByteBuffer buf) {
        byte len=buf.get();
        if(len == 0)
            return 0;
        return makeLong(buf, len);
    }
491676
@Override
	public synchronized RecordStructure read(long sessionId, long urlId) throws DatabaseException {
		try {
			psRead.setLong(1, sessionId);
			psRead.setLong(2, urlId);
			
			try (ResultSet rs = psRead.executeQuery()) {
				RecordStructure result = build(rs);
				return result;
			}
		} catch (SQLException e) {
			throw new DatabaseException(e);
		}
	}
632190
@Override
    public long read(long numBytes, int timeout) throws IOException {

        long readCount = 0;
        H2StreamProcessor p = muxLink.getStreamProcessor(streamID);

        try {
            p.getReadLatch().await(timeout, TimeUnit.MILLISECONDS);
            readCount = p.readCount(numBytes, this.getBuffers());
        } catch (InterruptedException e) {
            throw new IOException("read was stopped by an InterruptedException: " + e);
        }
        return readCount;
    }
340956
public long readLong () throws KryoException {
		require(8);
		byte[] buffer = this.buffer;
		int p = position;
		position = p + 8;
		return buffer[p] & 0xFF //
			| (buffer[p + 1] & 0xFF) << 8 //
			| (buffer[p + 2] & 0xFF) << 16 //
			| (long)(buffer[p + 3] & 0xFF) << 24 //
			| (long)(buffer[p + 4] & 0xFF) << 32 //
			| (long)(buffer[p + 5] & 0xFF) << 40 //
			| (long)(buffer[p + 6] & 0xFF) << 48 //
			| (long)buffer[p + 7] << 56;
	}
986880
public synchronized long read(long offset, final ByteBuffer buf) {
		if (!validState) {
			throw new InvalidStateException();
		}
		try {
			int readed;
			while (true) {
				if (offset >= offsetOutputCommited) {
					if (bufOutput.position() > 0) {
						log.warn("WARN: autoflush forced");
						flushBuffer();
					}
				}
				bufInput.clear();
				readed = fcInput.position(offset).read(bufInput); // Read 1 sector
				if (readed < HEADER_LEN) { // short+int (6 bytes)
					return -1;
				}
				bufInput.flip();
				final int magicB1 = (bufInput.get() & 0xFF); 	// Header - Magic (short, 2 bytes, msb-first)
				final int magicB2 = (bufInput.get() & 0xFF); 	// Header - Magic (short, 2 bytes, lsb-last)
				if (alignBlocks && (magicB1 == MAGIC_PADDING)) {
					final int diffOffset = nextBlockBoundary(offset);
					if (diffOffset > 0) {
						// log.info("WARN: skipping " + diffOffset + "bytes to next block-boundary");
						offset += diffOffset;
						continue;
					}
				}
				final int magic = ((magicB1 << 8) | magicB2);
				if (magic != MAGIC) {
					log.error("MAGIC HEADER fake=" + Integer.toHexString(magic) + " expected="
							+ Integer.toHexString(MAGIC));
					return -1;
				}
				break;
			}
			//
			final int datalen = bufInput.getInt(); 	// Header - Data Size (int, 4 bytes)
			final int dataUnderFlow = (datalen - (readed - HEADER_LEN));
			int footer = -12345678;
			if (dataUnderFlow < 0) {
				footer = bufInput.get(datalen + HEADER_LEN); 	// Footer (byte)
			}
			bufInput.limit(Math.min(readed, datalen + HEADER_LEN));
			buf.put(bufInput);
			if (dataUnderFlow > 0) {
				buf.limit(datalen);
				int len = fcInput.read(buf);
				if (len < dataUnderFlow) {
					log.error("Unable to read payload readed=" + len + " expected=" + dataUnderFlow);
					return -1;
				}
			}
			if (dataUnderFlow >= 0) {
				// Read Footer (byte)
				bufInput.clear();
				bufInput.limit(FOOTER_LEN);
				if (fcInput.read(bufInput) < FOOTER_LEN) {
					return -1;
				}
				bufInput.flip();
				footer = bufInput.get();
			}
			if (footer != MAGIC_FOOT) {
				log.error("MAGIC FOOT fake=" + Integer.toHexString(footer) + " expected="
						+ Integer.toHexString(MAGIC_FOOT));
				return -1;
			}
			buf.flip();
			return (offset + HEADER_LEN + datalen + FOOTER_LEN);
		} catch (Exception e) {
			log.error("Exception in read(" + offset + ")", e);
		}
		return -1;
	}
1340907
@Override
    public int read(char[] cbuf, int off, int len) throws IOException
    {
        if (m_stringReader == null) {
            m_bytes = m_jarFile.get(m_path);
            if (m_bytes == null) {
                // A stubborn caller will get StringReader exceptions.
                m_stringReader = new StringReader("");
                throw new IOException(String.format(
                        "DDL file \"%s\" not found in in-memory jar file.",
                        m_path));
            }
            m_stringReader = new StringReader(new String(m_bytes, "UTF-8"));
        }
        return m_stringReader.read(cbuf, off, len);
    }
414284
public TTable readTable(
			UserCoreConnection<TColumn, TTable, TRow, TResult> db) {

		List<TColumn> columnList = new ArrayList<TColumn>();

		TResult result = db.rawQuery(
				"PRAGMA table_info(" + CoreSQLUtils.quoteWrap(tableName) + ")",
				null);
		try {
			while (result.moveToNext()) {
				int index = result.getInt(result.getColumnIndex(CID));
				String name = result.getString(result.getColumnIndex(NAME));
				String type = result.getString(result.getColumnIndex(TYPE));
				boolean notNull = result
						.getInt(result.getColumnIndex(NOT_NULL)) == 1;
				boolean primaryKey = result.getInt(result.getColumnIndex(PK)) == 1;

				// If the type has a max limit on it, pull it off
				Long max = null;
				if (type != null && type.endsWith(")")) {
					int maxStart = type.indexOf("(");
					if (maxStart > -1) {
						String maxString = type.substring(maxStart + 1,
								type.length() - 1);
						if (!maxString.isEmpty()) {
							try {
								max = Long.valueOf(maxString);
								type = type.substring(0, maxStart);
							} catch (NumberFormatException e) {
								logger.log(Level.WARNING,
										"Failed to parse type max from type: "
												+ type, e);
							}
						}
					}
				}

				// Get the geometry or data type and default value
				int defaultValueIndex = result.getColumnIndex(DFLT_VALUE);

				TColumn column = createColumn(result, index, name, type, max,
						notNull, defaultValueIndex, primaryKey);
				columnList.add(column);
			}
		} finally {
			result.close();
		}
		if (columnList.isEmpty()) {
			throw new GeoPackageException("Table does not exist: " + tableName);
		}

		return createTable(tableName, columnList);
	}
986008
@Override
  public synchronized int read() throws IOException {
    long startTime = System.nanoTime();

    // TODO(user): Wrap this in a while-loop if we ever introduce a non-blocking mode for the
    // underlying channel.
    int numRead = channel.read(ByteBuffer.wrap(singleReadBuf));
    if (numRead == -1) {
      return -1;
    }
    if (numRead != 1) {
      throw new IOException(
          String.format(
              "Somehow read %d bytes using single-byte buffer for path %s ending in position %d!",
              numRead, gcsPath, channel.position()));
    }
    byte b = singleReadBuf[0];

    totalBytesRead++;
    statistics.incrementBytesRead(1);
    long duration = System.nanoTime() - startTime;
    ghfs.increment(GoogleHadoopFileSystemBase.Counter.READ1);
    ghfs.increment(GoogleHadoopFileSystemBase.Counter.READ1_TIME, duration);
    return (b & 0xff);
  }
455942
private void readTable(InputStream is, SynchroTable table) throws IOException
   {
      int skip = table.getOffset() - m_offset;
      if (skip != 0)
      {
         StreamHelper.skip(is, skip);
         m_offset += skip;
      }

      String tableName = DatatypeConverter.getString(is);
      int tableNameLength = 2 + tableName.length();
      m_offset += tableNameLength;

      int dataLength;
      if (table.getLength() == -1)
      {
         dataLength = is.available();
      }
      else
      {
         dataLength = table.getLength() - tableNameLength;
      }

      SynchroLogger.log("READ", tableName);

      byte[] compressedTableData = new byte[dataLength];
      is.read(compressedTableData);
      m_offset += dataLength;

      Inflater inflater = new Inflater();
      inflater.setInput(compressedTableData);
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream(compressedTableData.length);
      byte[] buffer = new byte[1024];
      while (!inflater.finished())
      {
         int count;

         try
         {
            count = inflater.inflate(buffer);
         }
         catch (DataFormatException ex)
         {
            throw new IOException(ex);
         }
         outputStream.write(buffer, 0, count);
      }
      outputStream.close();
      byte[] uncompressedTableData = outputStream.toByteArray();

      SynchroLogger.log(uncompressedTableData);

      m_tableData.put(table.getName(), uncompressedTableData);
   }
799864
public static long readLong(byte[] source, int position) {
        return (long) (source[position] & 0xFF) << 56
                | (long) (source[position + 1] & 0xFF) << 48
                | (long) (source[position + 2] & 0xFF) << 40
                | (long) (source[position + 3] & 0xFF) << 32
                | (long) (source[position + 4] & 0xFF) << 24
                | (source[position + 5] & 0xFF) << 16
                | (source[position + 6] & 0xFF) << 8
                | (source[position + 7] & 0xFF);
    }
1114147
public long readLong(final int offset) throws IOException {
        final int bytesToRead = Math.max(0, offset + 8 - used);
        if (bytesToRead > 0) {
            readMore(bytesToRead);
        }
        return ((buf[offset] & 0xffL) << 56) //
                | ((buf[offset + 1] & 0xffL) << 48) //
                | ((buf[offset + 2] & 0xffL) << 40) //
                | ((buf[offset + 3] & 0xffL) << 32) //
                | ((buf[offset + 4] & 0xffL) << 24) //
                | ((buf[offset + 5] & 0xffL) << 16) //
                | ((buf[offset + 6] & 0xffL) << 8) //
                | (buf[offset + 7] & 0xffL);
    }