public boolean canEncodePartialPage();
/**
- * Decodes the given page buffer inline.
+ * Returns {@code true} if this handler can decode a page inline,
+ * {@code false} otherwise. If this method returns {@code false}, the
+ * {@link #decodePage} method will always be called with separate buffers.
+ */
+ public boolean canDecodeInline();
+
+ /**
+ * Decodes the given page buffer.
*
- * @param page the page to be decoded
+ * @param inPage the page to be decoded
+ * @param outPage the decoded page. if {@link #canDecodeInline} is {@code
+ * true}, this will be the same buffer as inPage.
* @param pageNumber the page number of the given page
*
* @throws IOException if an exception occurs during decoding
*/
- public void decodePage(ByteBuffer page, int pageNumber) throws IOException;
+ public void decodePage(ByteBuffer inPage, ByteBuffer outPage, int pageNumber)
+ throws IOException;
/**
* Encodes the given page buffer into a new page buffer and returns it. The
return true;
}
- public void decodePage(ByteBuffer page, int pageNumber) throws IOException {
+ public boolean canDecodeInline() {
+ return true;
+ }
+
+ public void decodePage(ByteBuffer inPage, ByteBuffer outPage,
+ int pageNumber)
+ throws IOException
+ {
// does nothing
}
return true;
}
- public void decodePage(ByteBuffer page, int pageNumber) throws IOException {
+ public boolean canDecodeInline() {
+ return true;
+ }
+
+ public void decodePage(ByteBuffer inPage, ByteBuffer outPage,
+ int pageNumber)
+ throws IOException
+ {
throw new UnsupportedCodecException("Decoding not supported. Please choose a CodecProvider which supports reading the current database encoding.");
}
/** handler for the current database encoding type */
private CodecHandler _codecHandler = DefaultCodecProvider.DUMMY_HANDLER;
/** temp page buffer used when pages cannot be partially encoded */
- private final TempPageHolder _fullPageEncodeBufferH =
- TempPageHolder.newHolder(TempBufferHolder.Type.SOFT);
+ private TempPageHolder _fullPageEncodeBufferH;
+ private TempBufferHolder _tempDecodeBufferH;
private int _writeCount;
/**
{
// initialize page en/decoding support
_codecHandler = codecProvider.createHandler(this, database.getCharset());
+ if(!_codecHandler.canEncodePartialPage()) {
+ _fullPageEncodeBufferH =
+ TempPageHolder.newHolder(TempBufferHolder.Type.SOFT);
+ }
+ if(!_codecHandler.canDecodeInline()) {
+ _tempDecodeBufferH = TempBufferHolder.newHolder(
+ TempBufferHolder.Type.SOFT, true);
+ }
// note the global usage map is a special map where any page outside of
// the current range is assumed to be "on"
throws IOException
{
validatePageNumber(pageNumber);
- buffer.clear();
+
+ ByteBuffer inPage = buffer;
+ ByteBuffer outPage = buffer;
+ if((pageNumber != 0) && !_codecHandler.canDecodeInline()) {
+ inPage = _tempDecodeBufferH.getPageBuffer(this);
+ outPage.clear();
+ }
+
+ inPage.clear();
int bytesRead = _channel.read(
- buffer, (long) pageNumber * (long) getFormat().PAGE_SIZE);
- buffer.flip();
+ inPage, (long) pageNumber * (long) getFormat().PAGE_SIZE);
+ inPage.flip();
if(bytesRead != getFormat().PAGE_SIZE) {
throw new IOException("Failed attempting to read " +
getFormat().PAGE_SIZE + " bytes from page " +
// de-mask header (note, page 0 never has additional encoding)
applyHeaderMask(buffer);
} else {
- _codecHandler.decodePage(buffer, pageNumber);
+ _codecHandler.decodePage(inPage, outPage, pageNumber);
}
}
public boolean canEncodePartialPage() {
return true;
}
+
+ public boolean canDecodeInline() {
+ return true;
+ }
- public void decodePage(ByteBuffer page, int pageNumber) throws IOException {
- byte[] arr = page.array();
+ public void decodePage(ByteBuffer inPage, ByteBuffer outPage,
+ int pageNumber)
+ throws IOException
+ {
+ byte[] arr = inPage.array();
simpleDecode(arr, arr, pageNumber);
}
public boolean canEncodePartialPage() {
return false;
}
+
+ public boolean canDecodeInline() {
+ return true;
+ }
- public void decodePage(ByteBuffer page, int pageNumber) throws IOException {
- byte[] arr = page.array();
+ public void decodePage(ByteBuffer inPage, ByteBuffer outPage,
+ int pageNumber)
+ throws IOException
+ {
+ byte[] arr = inPage.array();
fullDecode(arr, arr, pageNumber);
}