read bit from segments.

@param segments target segments.
@param baseOffset bits base offset.
@param index bit index from base offset.
487903
public static boolean bitGet(MemorySegment[] segments, int baseOffset, int index) {
		int offset = baseOffset + ((index & BIT_BYTE_POSITION_MASK) >>> 3);
		byte current = getByte(segments, offset);
		return (current & (1 << (index & BIT_BYTE_INDEX_MASK))) != 0;
	}
1118411
public int getOffset(int index) throws IOException {
		int ret = -1;

		if (this.lastIndex != index) {
			this.readRecord(index);
		}

		ret = this.recOffset;

		return 2 * ret;
	}
1210969
public void setReadPosition(long pointer) {
		final int bufferNum = (int) (pointer >>> this.segmentSizeBits);
		final int offset = (int) (pointer & (this.memorySegmentSize - 1));
		
		this.currentBufferNum = bufferNum;
		seekInput(this.partitionBuffers[bufferNum], offset,
					bufferNum < this.partitionBuffers.length-1 ? this.memorySegmentSize : this.finalBufferLimit);
		
	}
891083
private void checkRange(long index) {
    Assert.indexNot(isEmpty(), "segment is empty");
    Assert.indexNot(index < firstIndex(), index + " is less than the first index in the segment");
    Assert.indexNot(index > lastIndex(), index + " is greater than the last index in the segment");
  }
370761
int getAbsoluteOffset(int index) throws JMFUninitializedAccessException {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) JmfTr.entry(this, tc, "getAbsoluteOffset", new Object[]{Integer.valueOf(index)});

    MessageMap.Remap remap = map.fields[index];

    if (remap == null) {
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) JmfTr.exit(this, tc, "getAbsoluteOffset", "JMFUninitializedAccessException");
      throw new JMFUninitializedAccessException(schema.getPathName(fields[index]) + " Schema: " + schema.getName());
    }

    int varOffset = remap.offsetIndex;
    varOffset = (varOffset < 0) ? 0 : oTable[varOffset];

    int result = dataOffset + varOffset + remap.fixedIncr;

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) JmfTr.exit(this, tc, "getAbsoluteOffset", Integer.valueOf(result));
    return result;
  }
1043669
public static double getDouble(MemorySegment[] segments, int offset) {
		if (inFirstSegment(segments, offset, 8)) {
			return segments[0].getDouble(offset);
		} else {
			return getDoubleMultiSegments(segments, offset);
		}
	}
200139
public void setBytes(long memoryOffset, byte[] buffer, int bufferOffset, int count)
    {
        if (buffer == null)
            throw new NullPointerException();
        else if (bufferOffset < 0
                 || count < 0
                 || bufferOffset + count > buffer.length)
            throw new IndexOutOfBoundsException();
        else if (count == 0)
            return;

        long end = memoryOffset + count;
        checkBounds(memoryOffset, end);

        unsafe.copyMemory(buffer, BYTE_ARRAY_BASE_OFFSET + bufferOffset, null, peer + memoryOffset, count);
    }
1318018
@Override
	public final byte get(int index) {
		final long pos = address + index;
		if (index >= 0 && pos < addressLimit) {
			return UNSAFE.getByte(heapMemory, pos);
		}
		else if (address > addressLimit) {
			throw new IllegalStateException("segment has been freed");
		}
		else {
			// index is in fact invalid
			throw new IndexOutOfBoundsException();
		}
	}
1128900
public void setBytes(long memoryOffset, byte[] buffer, int bufferOffset, int count)
    {
        if (buffer == null)
            throw new NullPointerException();
        else if (bufferOffset < 0
                 || count < 0
                 || bufferOffset + count > buffer.length)
            throw new IndexOutOfBoundsException();
        else if (count == 0)
            return;

        checkPosition(memoryOffset);
        long end = memoryOffset + count;
        checkPosition(end - 1);
        while (memoryOffset < end)
        {
            unsafe.putByte(peer + memoryOffset, buffer[bufferOffset]);
            memoryOffset++;
            bufferOffset++;
        }
    }
984644
private void debugSegment(WriteStream out, 
                            SegmentServiceImpl segmentService,
                            SegmentExtent extent,
                            byte []debugTableKey)
    throws IOException
  {
    int length = extent.length();
    
    try (InSegment in = segmentService.openRead(extent)) {
      ReadStream is = new ReadStream(in);

      is.position(length - BLOCK_SIZE);

      long seq = BitsUtil.readLong(is);

      if (seq <= 0) {
        return;
      }

      byte []tableKey = new byte[32];
      is.readAll(tableKey, 0, tableKey.length);
      
      TableEntry table = segmentService.findTable(tableKey);

      if (table == null) {
        return;
      }
      
      if (debugTableKey != null && ! Arrays.equals(debugTableKey, tableKey)) {
        return;
      }

      out.println();
      
      StringBuilder sb = new StringBuilder();
      Base64Util.encode(sb, seq);
      long time = _idGen.time(seq);
      
      out.println("Segment: " + extent.getId() + " (seq: " + sb
                  + ", table: " + Hex.toShortHex(tableKey)
                  + ", addr: 0x" + Long.toHexString(extent.address())
                  + ", len: 0x" + Integer.toHexString(length)
                  + ", time: " + LocalDateTime.ofEpochSecond(time / 1000, 0, ZoneOffset.UTC)
                  + ")");
      
      debugSegmentEntries(out, is, extent, table);
    }
  }
590266
public void set(int index) {
		Preconditions.checkArgument(index < bitLength && index >= 0);

		int byteIndex = (index & BYTE_POSITION_MASK) >>> 3;
		byte current = memorySegment.get(offset + byteIndex);
		current |= (1 << (index & BYTE_INDEX_MASK));
		memorySegment.put(offset + byteIndex, current);
	}
847086
@Override
    public int getInt(final int index) {
        boundsCheck(index, Bits.INT_SIZE_IN_BYTES);

        int bits = MEM.getInt(byteArray, addressOffset + index);
        if (NATIVE_BYTE_ORDER != PROTOCOL_BYTE_ORDER) {
            bits = Integer.reverseBytes(bits);
        }

        return bits;
    }
1040207
long getEndOffsetForSegment(Segment segment) {
        return Optional.ofNullable(sync.getState().getEndSegments().get(segment)).orElse(Long.MAX_VALUE);
    }
756583
@Override
	public final void get(DataOutput out, int offset, int length) throws IOException {
		if (address <= addressLimit) {
			if (heapMemory != null) {
				out.write(heapMemory, offset, length);
			}
			else {
				while (length >= 8) {
					out.writeLong(getLongBigEndian(offset));
					offset += 8;
					length -= 8;
				}

				while (length > 0) {
					out.writeByte(get(offset));
					offset++;
					length--;
				}
			}
		}
		else {
			throw new IllegalStateException("segment has been freed");
		}
	}
595013
synchronized JournalSegment<E> getSegment(long index) {
    assertOpen();
    // Check if the current segment contains the given index first in order to prevent an unnecessary map lookup.
    if (currentSegment != null && index > currentSegment.index()) {
      return currentSegment;
    }

    // If the index is in another segment, get the entry with the next lowest first index.
    Map.Entry<Long, JournalSegment<E>> segment = segments.floorEntry(index);
    if (segment != null) {
      return segment.getValue();
    }
    return getFirstSegment();
  }
205670
@NonNull public <T> T peek(int index) {
    //noinspection unchecked
    return (T) history.get(history.size() - index - 1);
  }
514198
@SuppressWarnings("unchecked")
  private void readNext() {
    // Compute the index of the next entry in the segment.
    final long index = getNextIndex();

    try {
      // Read more bytes from the segment if necessary.
      if (memory.remaining() < maxEntrySize) {
        long position = channel.position() + memory.position();
        channel.position(position);
        memory.clear();
        channel.read(memory);
        channel.position(position);
        memory.flip();
      }

      // Mark the buffer so it can be reset if necessary.
      memory.mark();

      try {
        // Read the length of the entry.
        final int length = memory.getInt();

        // If the buffer length is zero then return.
        if (length <= 0 || length > maxEntrySize) {
          memory.reset().limit(memory.position());
          nextEntry = null;
          return;
        }

        // Read the checksum of the entry.
        long checksum = memory.getInt() & 0xFFFFFFFFL;

        // Compute the checksum for the entry bytes.
        final Checksum crc32 = new CRC32();
        crc32.update(memory.array(), memory.position(), length);

        // If the stored checksum equals the computed checksum, return the entry.
        if (checksum == crc32.getValue()) {
          int limit = memory.limit();
          memory.limit(memory.position() + length);
          E entry = namespace.deserialize(memory);
          memory.limit(limit);
          nextEntry = new Indexed<>(index, entry, length);
        } else {
          memory.reset().limit(memory.position());
          nextEntry = null;
        }
      } catch (BufferUnderflowException e) {
        memory.reset().limit(memory.position());
        nextEntry = null;
      }
    } catch (IOException e) {
      throw new StorageException(e);
    }
  }