diff --git a/lang/java/src/com/wiredtiger/db/PackFormatInputStream.java b/lang/java/src/com/wiredtiger/db/PackFormatInputStream.java index fc4b99ae435..0b067651cd9 100644 --- a/lang/java/src/com/wiredtiger/db/PackFormatInputStream.java +++ b/lang/java/src/com/wiredtiger/db/PackFormatInputStream.java @@ -84,7 +84,6 @@ public class PackFormatInputStream { protected char getType() throws WiredTigerPackingException { if (formatOff >= format.length()) { - System.err.println("Raw format is: " + format); throw new WiredTigerPackingException( "No more fields in format."); } diff --git a/lang/java/src/com/wiredtiger/db/PackInputStream.java b/lang/java/src/com/wiredtiger/db/PackInputStream.java index f0e5bb9663d..7cc33a51eef 100644 --- a/lang/java/src/com/wiredtiger/db/PackInputStream.java +++ b/lang/java/src/com/wiredtiger/db/PackInputStream.java @@ -224,6 +224,7 @@ public class PackInputStream { public String getString() throws WiredTigerPackingException { int stringLength = 0; + int skipnull = 0; format.checkType('S', false); // Get the length for a fixed length string if (format.getType() != 'S') { @@ -234,10 +235,11 @@ public class PackInputStream { // string length. for (; valueOff + stringLength < value.length && value[valueOff + stringLength] != 0; stringLength++) {} + skipnull = 1; } format.consume(); String result = new String(value, valueOff, stringLength); - valueOff += stringLength + 1; + valueOff += stringLength + skipnull; return result; } @@ -249,7 +251,7 @@ public class PackInputStream { private short unpackShort(boolean signed) throws WiredTigerPackingException { long ret = unpackLong(true); - if ((signed && (ret > Short.MAX_VALUE || ret > Short.MIN_VALUE)) || + if ((signed && (ret > Short.MAX_VALUE || ret < Short.MIN_VALUE)) || (!signed && (short)ret < 0)) { throw new WiredTigerPackingException("Overflow unpacking short."); } @@ -264,7 +266,7 @@ public class PackInputStream { private int unpackInt(boolean signed) throws WiredTigerPackingException { long ret = unpackLong(true); - if ((signed && (ret > Integer.MAX_VALUE || ret > Integer.MIN_VALUE)) || + if ((signed && (ret > Integer.MAX_VALUE || ret < Integer.MIN_VALUE)) || (!signed && (int)ret < 0)) { throw new WiredTigerPackingException("Overflow unpacking integer."); } diff --git a/lang/java/src/com/wiredtiger/db/PackOutputStream.java b/lang/java/src/com/wiredtiger/db/PackOutputStream.java index 185068d2093..918949c13ab 100644 --- a/lang/java/src/com/wiredtiger/db/PackOutputStream.java +++ b/lang/java/src/com/wiredtiger/db/PackOutputStream.java @@ -173,13 +173,16 @@ public class PackOutputStream { char fieldFormat = format.getType(); int stringLen = 0; int padBytes = 0; + int valLen = 0; // Strings have two possible encodings. A lower case 's' is not null // terminated, and has a length define in the format (default 1). An // upper case 'S' is variable length and has a null terminator. if (fieldFormat == 's') { stringLen = format.getLengthFromFormat(true); - if (stringLen > value.length()) { - padBytes = stringLen - value.length(); + valLen = value.length(); + if (stringLen > valLen) { + padBytes = stringLen - valLen; + stringLen = valLen; } } else { stringLen = value.length(); diff --git a/lang/java/wiredtiger.i b/lang/java/wiredtiger.i index 0b2b4cdd1d2..23196625302 100644 --- a/lang/java/wiredtiger.i +++ b/lang/java/wiredtiger.i @@ -650,6 +650,19 @@ WT_ASYNC_CALLBACK javaApiAsyncHandler = {javaAsyncHandler}; return this; } + /** + * Append a record number to the async_op's key. + * + * \param value The value to append + * \return This async_op object, so put calls can be chained. + */ + public AsyncOp putKeyRecord(long value) + throws WiredTigerPackingException { + keyUnpacker = null; + keyPacker.addRecord(value); + return this; + } + /** * Append a short integer to the async_op's key. * @@ -742,6 +755,19 @@ WT_ASYNC_CALLBACK javaApiAsyncHandler = {javaAsyncHandler}; return this; } + /** + * Append a record number to the async_op's value. + * + * \param value The value to append + * \return This async_op object, so put calls can be chained. + */ + public AsyncOp putValueRecord(long value) + throws WiredTigerPackingException { + valueUnpacker = null; + valuePacker.addRecord(value); + return this; + } + /** * Append a short integer to the async_op's value. * @@ -833,6 +859,16 @@ WT_ASYNC_CALLBACK javaApiAsyncHandler = {javaAsyncHandler}; return getKeyUnpacker().getLong(); } + /** + * Retrieve a record number from the async_op's key. + * + * \return The requested value. + */ + public long getKeyRecord() + throws WiredTigerPackingException { + return getKeyUnpacker().getRecord(); + } + /** * Retrieve a short integer from the async_op's key. * @@ -918,6 +954,16 @@ WT_ASYNC_CALLBACK javaApiAsyncHandler = {javaAsyncHandler}; return getValueUnpacker().getLong(); } + /** + * Retrieve a record number from the async_op's value. + * + * \return The requested value. + */ + public long getValueRecord() + throws WiredTigerPackingException { + return getValueUnpacker().getRecord(); + } + /** * Retrieve a short integer from the async_op's value. * @@ -1200,6 +1246,18 @@ WT_ASYNC_CALLBACK javaApiAsyncHandler = {javaAsyncHandler}; return this; } + /** + * Append a record number to the cursor's key. + * + * \param value The value to append + * \return This cursor object, so put calls can be chained. + */ + public Cursor putKeyRecord(long value) + throws WiredTigerPackingException { + keyPacker.addRecord(value); + return this; + } + /** * Append a short integer to the cursor's key. * @@ -1286,6 +1344,18 @@ WT_ASYNC_CALLBACK javaApiAsyncHandler = {javaAsyncHandler}; return this; } + /** + * Append a record number to the cursor's value. + * + * \param value The value to append + * \return This cursor object, so put calls can be chained. + */ + public Cursor putValueRecord(long value) + throws WiredTigerPackingException { + valuePacker.addRecord(value); + return this; + } + /** * Append a short integer to the cursor's value. * @@ -1375,6 +1445,16 @@ WT_ASYNC_CALLBACK javaApiAsyncHandler = {javaAsyncHandler}; return keyUnpacker.getLong(); } + /** + * Retrieve a record number from the cursor's key. + * + * \return The requested value. + */ + public long getKeyRecord() + throws WiredTigerPackingException { + return keyUnpacker.getRecord(); + } + /** * Retrieve a short integer from the cursor's key. * @@ -1460,6 +1540,16 @@ WT_ASYNC_CALLBACK javaApiAsyncHandler = {javaAsyncHandler}; return valueUnpacker.getLong(); } + /** + * Retrieve a record number from the cursor's value. + * + * \return The requested value. + */ + public long getValueRecord() + throws WiredTigerPackingException { + return valueUnpacker.getRecord(); + } + /** * Retrieve a short integer from the cursor's value. * @@ -1800,7 +1890,8 @@ err: if (ret != 0) if ((ret = $self->open_cursor($self, uri, to_dup, config, &cursor)) != 0) goto err; - cursor->flags |= WT_CURSTD_RAW; + if ((cursor->flags & WT_CURSTD_DUMP_JSON) == 0) + cursor->flags |= WT_CURSTD_RAW; if ((ret = __wt_calloc_def((WT_SESSION_IMPL *)cursor->session, 1, &jcb)) != 0)