public static Page decodePage(ByteBuffer buf) throws IOException {
   Page p = new Page();
   buf.position(0);
   p.setPageNumber(Dlugosz.readLong(buf));
   p.setByteOffset(Dlugosz.readLong(buf));
   p.setTimeOffset(Dlugosz.readLong(buf));
   p.setData(buf.slice());
   return p;
 }
  /** Gets the page, including metadata, as a byte buffer ready for sending over the network */
  public static ByteBuffer pageToByteBuffer(Page p) {
    int bufLen = encodedPageSize(p);

    ByteBuffer result = ByteBuffer.allocate(bufLen);
    Dlugosz.encode(p.getPageNumber(), result);
    Dlugosz.encode(p.getByteOffset(), result);
    Dlugosz.encode(p.getTimeOffset(), result);
    p.getData().flip();
    result.put(p.getData());

    return result;
  }
 /** @syncpriority 200 */
 public void receivePage(Page p) {
   synchronized (this) {
     // We might have already stopped receiving, in which case the
     // pagebuf will be closed
     if (!isReceiving()) return;
     try {
       pageBuf.putPage(p);
     } catch (IOException e) {
       log.error("Error putting page into buffer", e);
       stop();
       return;
     }
   }
   prm.notifyPageReceived(p.getPageNumber());
   updateStreamStatus();
   if (isReceiving() && !isRebroadcasting()) startRebroadcast();
   if (pageBuf.getLastContiguousPage() == (pageBuf.getTotalPages() - 1)) receptionCompleted();
 }
 public static int encodedPageSize(Page p) {
   return Dlugosz.bytesToEncode(p.getPageNumber())
       + Dlugosz.bytesToEncode(p.getByteOffset())
       + Dlugosz.bytesToEncode(p.getTimeOffset())
       + p.getData().limit();
 }