// Path: hawtdb/src/main/java/org/fusesource/hawtdb/api/IOPagingException.java
// public class IOPagingException extends PagingException {
// 
//     private static final long serialVersionUID = -886491791391276951L;
// 
//     public IOPagingException() {
//         super();
//     }
// 
//     public IOPagingException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public IOPagingException(String message) {
//         super(message);
//     }
// 
//     public IOPagingException(Throwable cause) {
//         super(cause);
//     }
//     
// }
// 
// Path: hawtdb/src/main/java/org/fusesource/hawtdb/api/Paged.java
// public interface Paged {
// 
//     /**
//      * @return An object which provides access to allocate/deallocate pages.
//      */
//     Allocator allocator();
//     
//     /**
//      * does the same as allocator().alloc(1)
//      * @return a newly allocated page location.
//      */
//     int alloc();
// 
//     /**
//      * does the same as allocator().free(page, 1)
//      */
//     void free(int page);
// 
//     enum SliceType {
//         READ, WRITE, READ_WRITE
//     }
// 
//     /**
//      * Provides direct access to the memory associated with a page. Specifying
//      * the correct mode argument is especially critical and the Paged resources
//      * is being accessed in a transaction context so that the transaction can
//      * maintain snapshot isolation.
//      * 
//      * @param mode
//      *            how will the buffer be used.
//      * @param pageId
//      *            the starting page of the buffer
//      * @param count
//      *            the number of pages to include in the buffer.
//      * @return
//      * @throws IOPagingException
//      */
//     public ByteBuffer slice(SliceType mode, int pageId, int count) throws IOPagingException;
// 
//     public void unslice(ByteBuffer buffer);
// 
//     /**
//      * Copies the contents of a page into the buffer space. The buffer offset
//      * will be updated to reflect the amount of data copied into the buffer.
//      * 
//      * @param pageId
//      * @param buffer
//      */
//     public void read(int pageId, Buffer buffer);
// 
//     /**
//      * Copies the buffer into the page. The buffer offset will be updated to
//      * reflect the amount of data copied to the page.
//      * 
//      * @param pageId
//      * @param buffer
//      */
//     public void write(int pageId, Buffer buffer);
//     
//     /**
//      * @return the maximum number of bytes that be read or written to a page.
//      */
//     int getPageSize();
// 
//     /**
//      * @return the number of pages that would be required to store the specified
//      *         number of bytes
//      */
//     int pages(int length);
//     
//     void flush();
//     
//     
//     /**
//      * Gets an object previously put at the given page.  The returned object SHOULD NEVER be mutated.
//      *  
//      * @param page
//      * @return
//      */
//     <T> T get(PagedAccessor<T> pagedAccessor, int page);
//     
//     /**
//      * Put an object at a given page.  The supplied object SHOULD NEVER be mutated 
//      * once it has been stored.
//      * 
//      * @param page
//      * @param value
//      */
//     <T> void put(PagedAccessor<T> pagedAccessor, int page, T value);
//     
//     /**
//      * Frees any pages associated with the value stored at the given page if any.  Does not free
//      * the page supplied.
//      *  
//      * @param page
//      * @return
//      */
//     <T> void clear(PagedAccessor<T> pagedAccessor, int page);
// 
// }
// 
// Path: hawtdb/src/main/java/org/fusesource/hawtdb/api/Paged.java
// enum SliceType {
//     READ, WRITE, READ_WRITE
// }


import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.List;
import org.fusesource.hawtdb.api.IOPagingException;
import org.fusesource.hawtdb.api.Paged;
import org.fusesource.hawtdb.api.Paged.SliceType;
import org.fusesource.hawtbuf.Buffer;
    }
    
    public void readOpen() {
        readHeader();
        int pages = paged.pages(length);
        if( pages > 1 ) {
            paged.unslice(buffer);
            buffer = paged.slice(SliceType.READ, page, pages);
        }
        buffer.position(magic.length+8);
        buffer.limit(length);
    }

    public void writeOpen(short size) {
        buffer = paged.slice(SliceType.WRITE, page, size);
        buffer.position(magic.length+8);
    }

    public int writeCloseLinked(int next) {
        this.next = next;
        length = buffer.position();
        buffer.position(0);
        buffer.put(magic.data, magic.offset, magic.length);
        IntBuffer ib = buffer.asIntBuffer();
        ib.put(length);
        ib.put(next);
        paged.unslice(buffer);
        return length;
    }

// Path: hawtdb/src/main/java/org/fusesource/hawtdb/api/IOPagingException.java
// public class IOPagingException extends PagingException {
// 
//     private static final long serialVersionUID = -886491791391276951L;
// 
//     public IOPagingException() {
//         super();
//     }
// 
//     public IOPagingException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public IOPagingException(String message) {
//         super(message);
//     }
// 
//     public IOPagingException(Throwable cause) {
//         super(cause);
//     }
//     
// }
// 
// Path: hawtdb/src/main/java/org/fusesource/hawtdb/api/Paged.java
// public interface Paged {
// 
//     /**
//      * @return An object which provides access to allocate/deallocate pages.
//      */
//     Allocator allocator();
//     
//     /**
//      * does the same as allocator().alloc(1)
//      * @return a newly allocated page location.
//      */
//     int alloc();
// 
//     /**
//      * does the same as allocator().free(page, 1)
//      */
//     void free(int page);
// 
//     enum SliceType {
//         READ, WRITE, READ_WRITE
//     }
// 
//     /**
//      * Provides direct access to the memory associated with a page. Specifying
//      * the correct mode argument is especially critical and the Paged resources
//      * is being accessed in a transaction context so that the transaction can
//      * maintain snapshot isolation.
//      * 
//      * @param mode
//      *            how will the buffer be used.
//      * @param pageId
//      *            the starting page of the buffer
//      * @param count
//      *            the number of pages to include in the buffer.
//      * @return
//      * @throws IOPagingException
//      */
//     public ByteBuffer slice(SliceType mode, int pageId, int count) throws IOPagingException;
// 
//     public void unslice(ByteBuffer buffer);
// 
//     /**
//      * Copies the contents of a page into the buffer space. The buffer offset
//      * will be updated to reflect the amount of data copied into the buffer.
//      * 
//      * @param pageId
//      * @param buffer
//      */
//     public void read(int pageId, Buffer buffer);
// 
//     /**
//      * Copies the buffer into the page. The buffer offset will be updated to
//      * reflect the amount of data copied to the page.
//      * 
//      * @param pageId
//      * @param buffer
//      */
//     public void write(int pageId, Buffer buffer);
//     
//     /**
//      * @return the maximum number of bytes that be read or written to a page.
//      */
//     int getPageSize();
// 
//     /**
//      * @return the number of pages that would be required to store the specified
//      *         number of bytes
//      */
//     int pages(int length);
//     
//     void flush();
//     
//     
//     /**
//      * Gets an object previously put at the given page.  The returned object SHOULD NEVER be mutated.
//      *  
//      * @param page
//      * @return
//      */
//     <T> T get(PagedAccessor<T> pagedAccessor, int page);
//     
//     /**
//      * Put an object at a given page.  The supplied object SHOULD NEVER be mutated 
//      * once it has been stored.
//      * 
//      * @param page
//      * @param value
//      */
//     <T> void put(PagedAccessor<T> pagedAccessor, int page, T value);
//     
//     /**
//      * Frees any pages associated with the value stored at the given page if any.  Does not free
//      * the page supplied.
//      *  
//      * @param page
//      * @return
//      */
//     <T> void clear(PagedAccessor<T> pagedAccessor, int page);
// 
// }
// 
// Path: hawtdb/src/main/java/org/fusesource/hawtdb/api/Paged.java
// enum SliceType {
//     READ, WRITE, READ_WRITE
// }


// Path: hawtdb/src/main/java/org/fusesource/hawtdb/internal/page/Extent.java
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.List;
import org.fusesource.hawtdb.api.IOPagingException;
import org.fusesource.hawtdb.api.Paged;
import org.fusesource.hawtdb.api.Paged.SliceType;
import org.fusesource.hawtbuf.Buffer;

    }
    
    public void readOpen() {
        readHeader();
        int pages = paged.pages(length);
        if( pages > 1 ) {
            paged.unslice(buffer);
            buffer = paged.slice(SliceType.READ, page, pages);
        }
        buffer.position(magic.length+8);
        buffer.limit(length);
    }

    public void writeOpen(short size) {
        buffer = paged.slice(SliceType.WRITE, page, size);
        buffer.position(magic.length+8);
    }

    public int writeCloseLinked(int next) {
        this.next = next;
        length = buffer.position();
        buffer.position(0);
        buffer.put(magic.data, magic.offset, magic.length);
        IntBuffer ib = buffer.asIntBuffer();
        ib.put(length);
        ib.put(next);
        paged.unslice(buffer);
        return length;
    }

    public void writeCloseEOF() {