diff options
author | Vyacheslav Tyutyunkov <tyutyunkov@gmail.com> | 2013-03-27 17:30:57 +0700 |
---|---|---|
committer | Vyacheslav Tyutyunkov <tyutyunkov@gmail.com> | 2013-03-27 17:30:57 +0700 |
commit | 4d1cb1904a81fca48b5a328654e3667d11d8065e (patch) | |
tree | b9be6c5ce9a5b9c69cb2ce7a4d29faf7a15156ad | |
parent | 24b2f9d1db6956c33b595a1694e66679ac529b9a (diff) | |
download | ejdb-4d1cb1904a81fca48b5a328654e3667d11d8065e.tar.gz ejdb-4d1cb1904a81fca48b5a328654e3667d11d8065e.tar.bz2 ejdb-4d1cb1904a81fca48b5a328654e3667d11d8065e.zip |
#21
-rw-r--r-- | jejdb/src/java/org/ejdb/bson/BSONDecoder.java | 8 | ||||
-rw-r--r-- | jejdb/src/java/org/ejdb/bson/BSONEncoder.java | 4 | ||||
-rw-r--r-- | jejdb/src/java/org/ejdb/bson/BSONException.java | 23 | ||||
-rw-r--r-- | jejdb/src/java/org/ejdb/bson/io/InputBuffer.java | 9 | ||||
-rw-r--r-- | jejdb/src/java/org/ejdb/bson/io/OutputBuffer.java | 4 |
5 files changed, 37 insertions, 11 deletions
diff --git a/jejdb/src/java/org/ejdb/bson/BSONDecoder.java b/jejdb/src/java/org/ejdb/bson/BSONDecoder.java index f4ee2ea..1b96e8d 100644 --- a/jejdb/src/java/org/ejdb/bson/BSONDecoder.java +++ b/jejdb/src/java/org/ejdb/bson/BSONDecoder.java @@ -42,7 +42,7 @@ class BSONDecoder { BSONObject result = this.readObject(input.subBuffer(length - 5)); if (0x00 != input.read()) { - throw new IllegalArgumentException("unexpected end of document"); + throw new BSONException("unexpected end of document"); } return result; @@ -84,7 +84,7 @@ class BSONDecoder { int binlen = input.readInt(); byte subtype = input.read(); if (0x00 != subtype) { - throw new IllegalArgumentException("unexpected binary type: " + subtype); + throw new BSONException("unexpected binary type: " + subtype); } result.put(name, input.readBytes(binlen)); break; @@ -96,7 +96,7 @@ class BSONDecoder { case BSON.BOOLEAN: byte bvalue = input.read(); if (0x00 != bvalue && 0x01 != bvalue) { - throw new IllegalArgumentException("unexpected boolean value"); + throw new BSONException("unexpected boolean value"); } result.put(name, 0x01 == bvalue); break; @@ -123,7 +123,7 @@ class BSONDecoder { break; default: - throw new IllegalArgumentException("unexpected type: " + type); + throw new BSONException("unexpected type: " + type); } } diff --git a/jejdb/src/java/org/ejdb/bson/BSONEncoder.java b/jejdb/src/java/org/ejdb/bson/BSONEncoder.java index 3de9cd2..5349497 100644 --- a/jejdb/src/java/org/ejdb/bson/BSONEncoder.java +++ b/jejdb/src/java/org/ejdb/bson/BSONEncoder.java @@ -91,7 +91,7 @@ class BSONEncoder { } else if (value instanceof Pattern) { writeRegex(name, (Pattern) value); } else { - throw new IllegalArgumentException("can not serialize object: " + value.getClass().getName()); + throw new BSONException("can not serialize object: " + value.getClass().getName()); } } @@ -110,7 +110,7 @@ class BSONEncoder { writeFieldSpec(BSON.DOUBLE, name); output.writeDouble(value.doubleValue()); } else { - throw new IllegalArgumentException("can not serialize object: " + value.getClass().getName()); + throw new BSONException("can not serialize object: " + value.getClass().getName()); } } diff --git a/jejdb/src/java/org/ejdb/bson/BSONException.java b/jejdb/src/java/org/ejdb/bson/BSONException.java new file mode 100644 index 0000000..b3186b1 --- /dev/null +++ b/jejdb/src/java/org/ejdb/bson/BSONException.java @@ -0,0 +1,23 @@ +package org.ejdb.bson; + +/** + * @author Tyutyunkov Vyacheslav (tve@softmotions.com) + * @version $Id$ + */ +public class BSONException extends RuntimeException { + public BSONException() { + super(); + } + + public BSONException(String message) { + super(message); + } + + public BSONException(String message, Throwable cause) { + super(message, cause); + } + + public BSONException(Throwable cause) { + super(cause); + } +} diff --git a/jejdb/src/java/org/ejdb/bson/io/InputBuffer.java b/jejdb/src/java/org/ejdb/bson/io/InputBuffer.java index 065db8a..48af376 100644 --- a/jejdb/src/java/org/ejdb/bson/io/InputBuffer.java +++ b/jejdb/src/java/org/ejdb/bson/io/InputBuffer.java @@ -1,5 +1,6 @@ package org.ejdb.bson.io; +import org.ejdb.bson.BSONException; import org.ejdb.bson.BSONObject; import java.io.UnsupportedEncodingException; @@ -71,7 +72,7 @@ public class InputBuffer { if (length > 0) { ensure(length); if ((byte) 0x00 != data[offset + position + length - 1]) { - throw new IllegalArgumentException("unexpected end of string"); + throw new BSONException("unexpected end of string"); } try { @@ -79,7 +80,7 @@ public class InputBuffer { position += length; return s; } catch (UnsupportedEncodingException e) { - throw new RuntimeException("can not decode string", e); + throw new BSONException("can not decode string", e); } } @@ -89,7 +90,7 @@ public class InputBuffer { } if (position + length > limit) { - throw new IllegalArgumentException("unexpected end of string"); + throw new BSONException("unexpected end of string"); } String s = new String(data, offset + position, length); @@ -112,7 +113,7 @@ public class InputBuffer { protected void ensure(int size) { if (size > limit - position) { - throw new IllegalArgumentException("can not allocate sub buffer: not enought bytes"); + throw new BSONException("can not allocate sub buffer: not enought bytes"); } } diff --git a/jejdb/src/java/org/ejdb/bson/io/OutputBuffer.java b/jejdb/src/java/org/ejdb/bson/io/OutputBuffer.java index 2387a92..549b8bf 100644 --- a/jejdb/src/java/org/ejdb/bson/io/OutputBuffer.java +++ b/jejdb/src/java/org/ejdb/bson/io/OutputBuffer.java @@ -1,5 +1,7 @@ package org.ejdb.bson.io; +import org.ejdb.bson.BSONException; + import java.io.UnsupportedEncodingException; /** @@ -92,7 +94,7 @@ public class OutputBuffer { try { this.write(value.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); + throw new BSONException("can not encode string", e); } this.write((byte) 0x00); |