Пример #1
0
  public ByteSource asByteSource(ReadOnlyTransaction txn) throws IOException {
    ByteBuffer snapshotHeader = ByteBuffer.allocate(HEADER_SIZE);

    {
      ByteBuffer header = buildHeader();
      assert header.remaining() == MASTERPAGE_HEADER_SIZE;
      snapshotHeader.put(header);
    }

    // We build a master header with just the current snapshot transaction
    for (int i = 0; i < MASTERPAGE_SLOTS; i++) {
      int position = MASTERPAGE_HEADER_SIZE + (i * MASTERPAGE_SLOT_SIZE);

      ByteBuffer mmap = ByteBuffer.allocate(MASTERPAGE_SLOT_SIZE);
      assert mmap.position() == 0;

      int rootPage = txn.rootPageId;
      int transactionPage = txn.transactionPageId;
      long transactionId = txn.snapshotTransactionId;

      MasterPage.create(mmap, rootPage, transactionPage, transactionId);
      mmap.position(MASTERPAGE_SLOT_SIZE);
      mmap.flip();
      assert mmap.remaining() == MASTERPAGE_SLOT_SIZE;

      snapshotHeader.position(position);
      snapshotHeader.put(mmap);
    }

    snapshotHeader.position(0);

    ByteSource dataByteSource = asByteSource0();
    dataByteSource = dataByteSource.slice(HEADER_SIZE, Long.MAX_VALUE);

    return ByteSource.concat(new ByteBufferByteSource(snapshotHeader), dataByteSource);
  }
Пример #2
0
 protected Payload doSlice(ByteSource content, long offset, long length) {
   return new ByteSourcePayload(content.slice(offset, length));
 }