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;
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;
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;
break;
default:
- throw new IllegalArgumentException("unexpected type: " + type);
+ throw new BSONException("unexpected type: " + type);
}
}
} 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());
}
}
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());
}
}
--- /dev/null
+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);
+ }
+}
package org.ejdb.bson.io;
+import org.ejdb.bson.BSONException;
import org.ejdb.bson.BSONObject;
import java.io.UnsupportedEncodingException;
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 {
position += length;
return s;
} catch (UnsupportedEncodingException e) {
- throw new RuntimeException("can not decode string", e);
+ throw new BSONException("can not decode string", e);
}
}
}
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);
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");
}
}
package org.ejdb.bson.io;
+import org.ejdb.bson.BSONException;
+
import java.io.UnsupportedEncodingException;
/**
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);