use of voldemort.serialization.SerializationException in project voldemort by voldemort.
the class AvroVersionedGenericSerializer method toBytes.
/*
* Serialize a given object using a non latest schema With auto rebootstrap
* the client gets the latest schema updated on the server However an
* application may still create objects using an old schema this lets us
* serialize those objects without an exception
*/
private byte[] toBytes(Object object, Schema writer, Integer writerVersion) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
Encoder encoder = new BinaryEncoder(output);
GenericDatumWriter<Object> datumWriter = null;
output.write(writerVersion.byteValue());
try {
datumWriter = new GenericDatumWriter<Object>(writer);
datumWriter.write(object, encoder);
encoder.flush();
} catch (IOException e) {
throw new SerializationException(e);
} catch (SerializationException sE) {
throw sE;
} finally {
SerializationUtils.close(output);
}
return output.toByteArray();
}
use of voldemort.serialization.SerializationException in project voldemort by voldemort.
the class AvroVersionedGenericSerializer method toBytes.
public byte[] toBytes(Object object) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
Encoder encoder = new BinaryEncoder(output);
GenericDatumWriter<Object> datumWriter = null;
output.write(newestVersion.byteValue());
try {
datumWriter = new GenericDatumWriter<Object>(typeDef);
datumWriter.write(object, encoder);
encoder.flush();
} catch (SerializationException sE) {
throw sE;
} catch (IOException e) {
throw new SerializationException(e);
} catch (Exception aIOBE) {
// probably the object sent to us was not created using the latest
// schema
// We simply check the old version number and serialize it using the
// old schema version
Schema writer = ((GenericContainer) object).getSchema();
Integer writerVersion = getSchemaVersion(writer);
return toBytes(object, writer, writerVersion);
} finally {
SerializationUtils.close(output);
}
return output.toByteArray();
}
use of voldemort.serialization.SerializationException in project voldemort by voldemort.
the class AvroVersionedGenericSerializer method toObject.
public Object toObject(byte[] bytes) {
Integer version = Integer.valueOf(bytes[0]);
if (version > newestVersion)
throw new SerializationException("Client needs to rebootstrap! \n Writer's schema version greater than Reader");
Schema typeDefWriter = Schema.parse(typeDefVersions.get(version));
Decoder decoder = DecoderFactory.defaultFactory().createBinaryDecoder(bytes, 1, bytes.length - 1, null);
GenericDatumReader<Object> reader = null;
try {
reader = new GenericDatumReader<Object>(typeDefWriter, typeDef);
// writer's schema
reader.setSchema(typeDefWriter);
// Reader's schema
reader.setExpected(typeDef);
return reader.read(null, decoder);
} catch (IOException e) {
throw new SerializationException(e);
}
}
use of voldemort.serialization.SerializationException in project voldemort by voldemort.
the class JsonReader method readUnicodeLiteral.
private char readUnicodeLiteral() {
int value = 0;
for (int i = 0; i < 4; i++) {
next();
value <<= 4;
if (Character.isDigit(current()))
value += current() - '0';
else if ('a' <= current() && 'f' >= current())
value += 10 + current() - 'a';
else if ('A' <= current() && 'F' >= current())
value += 10 + current() - 'A';
else
throw new SerializationException("Invalid character in unicode sequence on line " + getCurrentLineNumber() + ": " + currentChar());
}
return (char) value;
}
use of voldemort.serialization.SerializationException in project voldemort by voldemort.
the class JsonReader method next.
private int next() {
try {
// read a character
this.current = this.reader.read();
// increment the character count and maybe line number
this.charsRead++;
this.lineOffset++;
if (this.current == this.lineBreak) {
this.line++;
this.lineOffset = 1;
}
// add to context buffer
this.contextBuffer[this.contextOffset] = (char) this.current;
this.contextOffset = (contextOffset + 1) % this.contextBuffer.length;
return this.current;
} catch (IOException e) {
throw new SerializationException("Error reading from JSON stream.", e);
}
}
Aggregations