diff options
| author | Michael Cahill <michael.cahill@mongodb.com> | 2016-05-05 15:38:12 +1000 |
|---|---|---|
| committer | Michael Cahill <michael.cahill@mongodb.com> | 2016-05-05 15:38:12 +1000 |
| commit | 636a7b25ef3eca6b98009330f4d35337d4f35717 (patch) | |
| tree | 7cc2e03ad96e206cbe73343feef10197023a37da /lang/java/src | |
| parent | eaa7b5f0fcc62f356c33a2c56f45b609a73ca5dd (diff) | |
| parent | 75c22bc0c662622c14e5c47d99ff262cede2c6bf (diff) | |
Merge branch 'develop' into mongodb-3.4mongodb-3.3.6
Diffstat (limited to 'lang/java/src')
| -rw-r--r-- | lang/java/src/com/wiredtiger/db/PackFormatInputStream.java | 7 | ||||
| -rw-r--r-- | lang/java/src/com/wiredtiger/db/PackInputStream.java | 35 | ||||
| -rw-r--r-- | lang/java/src/com/wiredtiger/db/PackOutputStream.java | 2 |
3 files changed, 36 insertions, 8 deletions
diff --git a/lang/java/src/com/wiredtiger/db/PackFormatInputStream.java b/lang/java/src/com/wiredtiger/db/PackFormatInputStream.java index 02639bfe77a..4f05e153607 100644 --- a/lang/java/src/com/wiredtiger/db/PackFormatInputStream.java +++ b/lang/java/src/com/wiredtiger/db/PackFormatInputStream.java @@ -40,6 +40,7 @@ import com.wiredtiger.db.WiredTigerPackingException; public class PackFormatInputStream { protected String format; + protected boolean isRaw; protected int formatOff; protected int formatRepeatCount; @@ -48,8 +49,9 @@ public class PackFormatInputStream { * * \param format the encoded format backing string. */ - protected PackFormatInputStream(String format) { + protected PackFormatInputStream(String format, boolean isRaw) { this.format = format; + this.isRaw = isRaw; formatOff = 0; formatRepeatCount = 0; } @@ -114,6 +116,9 @@ public class PackFormatInputStream { throws WiredTigerPackingException { char expected = getType(); + if (isRaw) + throw new WiredTigerPackingException( + "Format mismatch for raw mode"); if (Character.toLowerCase(expected) != Character.toLowerCase(asking)) throw new WiredTigerPackingException( "Format mismatch. Wanted: " + asking + ", got: " + expected); diff --git a/lang/java/src/com/wiredtiger/db/PackInputStream.java b/lang/java/src/com/wiredtiger/db/PackInputStream.java index f265d041d94..732bf450acd 100644 --- a/lang/java/src/com/wiredtiger/db/PackInputStream.java +++ b/lang/java/src/com/wiredtiger/db/PackInputStream.java @@ -43,6 +43,7 @@ public class PackInputStream { protected byte[] value; protected int valueOff; protected int valueLen; + protected boolean isRaw; /** * Constructor. @@ -52,7 +53,7 @@ public class PackInputStream { * \param value The raw bytes that back the stream. */ public PackInputStream(String format, byte[] value) { - this(format, value, 0, value.length); + this(format, value, false, 0, value.length); } /** @@ -61,14 +62,29 @@ public class PackInputStream { * \param format A String that contains the WiredTiger format that * defines the layout of this packed value. * \param value The raw bytes that back the stream. + * \param isRaw The stream is opened raw. + */ + public PackInputStream(String format, byte[] value, boolean isRaw) { + this(format, value, isRaw, 0, value.length); + } + + /** + * Constructor. + * + * \param format A String that contains the WiredTiger format that + * defines the layout of this packed value. + * \param value The raw bytes that back the stream. + * \param isRaw The stream is opened raw. * \param off Offset into the value array at which the stream begins. * \param len Length of the value array that forms the stream. */ - public PackInputStream(String format, byte[] value, int off, int len) { - this.format = new PackFormatInputStream(format); + public PackInputStream( + String format, byte[] value, boolean isRaw, int off, int len) { + this.format = new PackFormatInputStream(format, isRaw); this.value = value; this.valueOff = off; this.valueLen = len; + this.isRaw = isRaw; } /** @@ -117,7 +133,9 @@ public class PackInputStream { */ public void getByteArray(byte[] dest, int off, int len) throws WiredTigerPackingException { - format.checkType('U', false); + if (!isRaw) { + format.checkType('U', false); + } getByteArrayInternal(getByteArrayLength(), dest, off, len); } @@ -127,7 +145,9 @@ public class PackInputStream { */ public byte[] getByteArray() throws WiredTigerPackingException { - format.checkType('U', false); + if (!isRaw) { + format.checkType('U', false); + } int itemLen = getByteArrayLength(); byte[] unpacked = new byte[itemLen]; getByteArrayInternal(itemLen, unpacked, 0, itemLen); @@ -142,7 +162,10 @@ public class PackInputStream { throws WiredTigerPackingException { int itemLen = 0; - if (format.hasLength()) { + if (isRaw) { + // The rest of the buffer is a byte array. + itemLen = valueLen - valueOff; + } else if (format.hasLength()) { // If the format has a length, it's always used. itemLen = format.getLengthFromFormat(true); } else if (format.getType() == 'U') { diff --git a/lang/java/src/com/wiredtiger/db/PackOutputStream.java b/lang/java/src/com/wiredtiger/db/PackOutputStream.java index 805e34f6ca8..46b3aef0974 100644 --- a/lang/java/src/com/wiredtiger/db/PackOutputStream.java +++ b/lang/java/src/com/wiredtiger/db/PackOutputStream.java @@ -50,7 +50,7 @@ public class PackOutputStream { * defines the layout of this packed value. */ public PackOutputStream(String format) { - this.format = new PackFormatInputStream(format); + this.format = new PackFormatInputStream(format, false); intBuf = new byte[MAX_INT_BYTES]; packed = new ByteArrayOutputStream(100); } |
