Package voldemort.serialization

Examples of voldemort.serialization.SerializationException


        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);
        }
View Full Code Here


            if(s.equals(version))
                return entry.getKey();

        }

        throw new SerializationException("Writer's schema invalid!");
    }
View Full Code Here

    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));

        byte[] dataBytes = new byte[bytes.length - 1];
        System.arraycopy(bytes, 1, dataBytes, 0, bytes.length - 1);
        Decoder decoder = DecoderFactory.defaultFactory().createBinaryDecoder(dataBytes, 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);
        }

    }
View Full Code Here

        try {
            toBytes(object, output);
            output.flush();
            return bytes.toByteArray();
        } catch(IOException e) {
            throw new SerializationException(e);
        }
    }
View Full Code Here

    public Object toObject(byte[] bytes) {
        DataInputStream input = new DataInputStream(new ByteArrayInputStream(bytes));
        try {
            return toObject(input);
        } catch(IOException e) {
            throw new SerializationException(e);
        }
    }
View Full Code Here

        Integer version = 0;
        if(hasVersion)
            version = Integer.valueOf(input.readByte());
        JsonTypeDefinition typeDef = typeDefVersions.get(version);
        if(typeDef == null)
            throw new SerializationException("No schema found for schema version " + version + ".");
        return read(input, typeDef.getType());
    }
View Full Code Here

    @SuppressWarnings("unchecked")
    private void write(DataOutputStream output, Object object, Object type) throws IOException {
        try {
            if(type instanceof Map) {
                if(object != null && !(object instanceof Map))
                    throw new SerializationException("Expected Map, but got " + object.getClass()
                                                     + ": " + object);
                writeMap(output, (Map<String, Object>) object, (Map<String, Object>) type);
            } else if(type instanceof List) {
                if(object != null && !(object instanceof List))
                    throw new SerializationException("Expected List but got " + object.getClass()
                                                     + ": " + object);
                writeList(output, (List<Object>) object, (List<Object>) type);
            } else if(type instanceof JsonTypes) {
                JsonTypes jsonType = (JsonTypes) type;
                switch(jsonType) {
                    case STRING:
                        writeString(output, (String) object);
                        break;
                    case INT8:
                        writeInt8(output, (Byte) object);
                        break;
                    case INT16:
                        writeInt16(output, coerceToShort(object));
                        break;
                    case INT32:
                        writeInt32(output, coerceToInteger(object));
                        break;
                    case INT64:
                        writeInt64(output, coerceToLong(object));
                        break;
                    case FLOAT32:
                        writeFloat32(output, coerceToFloat(object));
                        break;
                    case FLOAT64:
                        writeFloat64(output, coerceToDouble(object));
                        break;
                    case DATE:
                        writeDate(output, coerceToDate(object));
                        break;
                    case BYTES:
                        writeBytes(output, (byte[]) object);
                        break;
                    case BOOLEAN:
                        writeBoolean(output, (Boolean) object);
                        break;
                    default:
                        throw new SerializationException("Unknown type: " + type);
                }
            }
        } catch(ClassCastException e) {
            // simpler than doing every test
            throw new SerializationException("Expected type " + type
                                             + " but got object of incompatible type "
                                             + object.getClass().getName() + ".", e);
        }
    }
View Full Code Here

                case BYTES:
                    return readBytes(stream);
                case STRING:
                    return readString(stream);
                default:
                    throw new SerializationException("Unknown type: " + type);
            }
        } else {
            throw new SerializationException("Unknown type of class " + type.getClass());
        }
    }
View Full Code Here

        if(c == Short.class)
            return (Short) o;
        else if(c == Byte.class)
            return ((Byte) o).shortValue();
        else
            throw new SerializationException("Object of type " + c.getName()
                                             + " cannot be coerced to type " + JsonTypes.INT16
                                             + " as the schema specifies.");
    }
View Full Code Here

        else if(c == Byte.class)
            return ((Byte) o).intValue();
        else if(c == Short.class)
            return ((Short) o).intValue();
        else
            throw new SerializationException("Object of type " + c.getName()
                                             + " cannot be coerced to type " + JsonTypes.INT32
                                             + " as the schema specifies.");
    }
View Full Code Here

TOP

Related Classes of voldemort.serialization.SerializationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.