[Mulgara-svn] r628 - trunk/src/jar/util-xa/java/org/mulgara/store/xa
pag at mulgara.org
pag at mulgara.org
Thu Jan 24 22:47:58 UTC 2008
Author: pag
Date: 2008-01-24 14:47:57 -0800 (Thu, 24 Jan 2008)
New Revision: 628
Modified:
trunk/src/jar/util-xa/java/org/mulgara/store/xa/Block.java
Log:
Supressed warning, fixed some formatting, and simplified the limit calculation for get(int,ByteBuffer). Added getSlice(int,int) to avoid a copy operation that isn't needed in XAStringPoolImpl
Modified: trunk/src/jar/util-xa/java/org/mulgara/store/xa/Block.java
===================================================================
--- trunk/src/jar/util-xa/java/org/mulgara/store/xa/Block.java 2008-01-24 22:42:41 UTC (rev 627)
+++ trunk/src/jar/util-xa/java/org/mulgara/store/xa/Block.java 2008-01-24 22:47:57 UTC (rev 628)
@@ -30,7 +30,6 @@
// Java 2 standard packages
import java.io.*;
import java.nio.*;
-import java.nio.channels.*;
// Third party packages
import org.apache.log4j.Category;
@@ -63,6 +62,7 @@
public static final long INVALID_BLOCK_ID = -1;
+ @SuppressWarnings("unused")
private final static Category logger =
Category.getInstance(Block.class.getName());
@@ -273,16 +273,33 @@
* @param offset The location of the required buffer within the data block.
* @param byteBuffer The buffer to fill.
*/
-
public void get(int offset, ByteBuffer byteBuffer) {
- ByteBuffer src = bb.asReadOnlyBuffer();
- int start = byteOffset + offset;
- src.position(start);
- src.limit(Math.min(start + byteBuffer.limit() - byteBuffer.position(), src.limit()));
- byteBuffer.put(src);
+ assert offset + byteBuffer.remaining() <= blockSize;
+
+ ByteBuffer src = bb.asReadOnlyBuffer();
+ int pos = byteOffset + offset;
+ src.position(pos);
+ src.limit(pos + byteBuffer.remaining());
+ byteBuffer.put(src);
}
/**
+ * Gets a read-only portion of the buffer.
+ *
+ * @param offset The location of the required buffer within the data block.
+ * @param size The size of the slice to retrieve.
+ * @return The read only portion of the buffer desired.
+ */
+ public ByteBuffer getSlice(int offset, int size) {
+ assert offset + size <= blockSize;
+
+ ByteBuffer data = bb.asReadOnlyBuffer();
+ data.position(byteOffset + offset);
+ data.limit(byteOffset + offset + size);
+ return data.slice();
+ }
+
+ /**
* Gets an array of integers from the buffer.
*
* @param offset The integer offset to get the data from.
More information about the Mulgara-svn
mailing list