Package com.dyuproject.protostuff

Examples of com.dyuproject.protostuff.ProtostuffException


               
            case ID_ARRAY:
                final String typeArray = input.readString();
               
                if(input.readFieldNumber(schema) != ID_ARRAY_LEN)
                    throw new ProtostuffException("Corrupt input.");
                final int len = input.readUInt32();
               
                if(input.readFieldNumber(schema) != ID_ARRAY_DIMENSION)
                    throw new ProtostuffException("Corrupt input.");
                final int dimensions = input.readUInt32();

                final ArrayWrapper arrayWrapper = newArrayWrapper(typeArray, len,
                        dimensions);
               
                COLLECTION_SCHEMA.mergeFrom(input, arrayWrapper);
               
                return arrayWrapper.array;
               
            case ID_OBJECT:
                if(input.readUInt32() != 0)
                    throw new ProtostuffException("Corrupt input.");
               
                value = new Object();
                break;
               
            case ID_ENUM:
                final String typeEnum = input.readString();
                final EnumIO<?> eio = EnumIO.get(typeEnum,
                        AUTO_LOAD_POLYMORPHIC_CLASSES);
               
                if(eio == null)
                    throw new ProtostuffException("Unknown enum class: " + typeEnum);
               
                if(input.readFieldNumber(schema) != ID_ENUM_VALUE)
                    throw new ProtostuffException("Corrupt input.");
               
                value = eio.readFrom(input);
                break;
               
            case ID_COLLECTION:
                final String collectionType = input.readString();
                if(collectionType.indexOf('.') != -1)
                {
                    // EnumSet
                    final Collection<?> c = EnumIO.get(collectionType, true).newEnumSet();
                    COLLECTION_SCHEMA.mergeFrom(input, (Collection<Object>)c);
                    return c;
                }
               
                final Collection<Object> collection =
                    CollectionSchema.MessageFactories.getFactory(
                            collectionType).newMessage();
               
                COLLECTION_SCHEMA.mergeFrom(input, collection);
               
                return collection;
               
            case ID_MAP:
                final String mapType = input.readString();
                if(mapType.indexOf('.') != -1)
                {
                    // EnumMap
                    final Map<?,Object> m = EnumIO.get(mapType, true).newEnumMap();
                    MAP_SCHEMA.mergeFrom(input, (Map<Object, Object>)m);
                    return m;
                }
               
                final Map<Object,Object> map =
                    MapSchema.MessageFactories.getFactory(mapType).newMessage();
               
                MAP_SCHEMA.mergeFrom(input, map);
               
                return map;
               
            case ID_POJO:
                final String typePojo = input.readString();
                final HasSchema<Object> wrapper = RuntimeSchema.getSchemaWrapper(
                        typePojo, AUTO_LOAD_POLYMORPHIC_CLASSES);
               
                if(wrapper == null)
                    throw new ProtostuffException("Unknown pojo class: " + typePojo);
               
                final Schema<Object> derivedSchema = wrapper.getSchema();
                final Object pojo = derivedSchema.newMessage();
               
                derivedSchema.mergeFrom(input, pojo);
                return pojo;
               
            default:
                throw new ProtostuffException("Corrupt input.  Unknown field number: " + number);
        }
       
        if(input.readFieldNumber(schema) != 0)
            throw new ProtostuffException("Corrupt input.");
       
        return value;
    }
View Full Code Here


                break;
            case ID_ARRAY:
                input.transferByteRangeTo(output, true, number, false);
               
                if(input.readFieldNumber(pipeSchema.wrappedSchema) != ID_ARRAY_LEN)
                    throw new ProtostuffException("Corrupt input.");
               
                output.writeUInt32(ID_ARRAY_LEN, input.readUInt32(), false);
               
                if(input.readFieldNumber(pipeSchema.wrappedSchema) != ID_ARRAY_DIMENSION)
                    throw new ProtostuffException("Corrupt input.");
               
                output.writeUInt32(ID_ARRAY_DIMENSION, input.readUInt32(), false);
               
                if(output instanceof StatefulOutput)
                {
                    // update using the derived schema.
                    ((StatefulOutput)output).updateLast(ARRAY_PIPE_SCHEMA, pipeSchema);
                }
               
                Pipe.transferDirect(ARRAY_PIPE_SCHEMA, pipe, input, output);
                return;
            case ID_OBJECT:
                output.writeUInt32(number, input.readUInt32(), false);
                break;
            case ID_ENUM:
                input.transferByteRangeTo(output, true, number, false);
               
                if(input.readFieldNumber(pipeSchema.wrappedSchema) != ID_ENUM_VALUE)
                    throw new ProtostuffException("Corrupt input.");
               
                EnumIO.transfer(pipe, input, output, 1, false);
                break;
            case ID_COLLECTION:
                input.transferByteRangeTo(output, true, number, false);
               
                if(output instanceof StatefulOutput)
                {
                    // update using the derived schema.
                    ((StatefulOutput)output).updateLast(COLLECTION_PIPE_SCHEMA, pipeSchema);
                }
               
                Pipe.transferDirect(COLLECTION_PIPE_SCHEMA, pipe, input, output);
                return;
            case ID_MAP:
                input.transferByteRangeTo(output, true, number, false);
               
                if(output instanceof StatefulOutput)
                {
                    // update using the derived schema.
                    ((StatefulOutput)output).updateLast(MAP_PIPE_SCHEMA, pipeSchema);
                }
               
                Pipe.transferDirect(MAP_PIPE_SCHEMA, pipe, input, output);
                return;
            case ID_POJO:
                final String typePojo = input.readString();
                final HasSchema<Object> wrapper = RuntimeSchema.getSchemaWrapper(
                        typePojo, AUTO_LOAD_POLYMORPHIC_CLASSES);
               
                if(wrapper == null)
                    throw new ProtostuffException("Unknown pojo class: " + typePojo);
               
                output.writeString(number, typePojo, false);
               
                final Pipe.Schema<Object> derivedPipeSchema = wrapper.getPipeSchema();
               
               
                if(output instanceof StatefulOutput)
                {
                    // update using the derived schema.
                    ((StatefulOutput)output).updateLast(derivedPipeSchema, pipeSchema);
                }
               
                Pipe.transferDirect(derivedPipeSchema, pipe, input, output);
                return;
            default:
                throw new ProtostuffException("Corrupt input.  Unknown field number: " + number);
        }
       
        if(input.readFieldNumber(pipeSchema.wrappedSchema) != 0)
            throw new ProtostuffException("Corrupt input.");
    }
View Full Code Here

       
        final HasSchema<T> wrapper = getSchemaWrapper(className,
                RuntimeEnv.AUTO_LOAD_POLYMORPHIC_CLASSES);
        if(wrapper == null)
        {
            throw new ProtostuffException("polymorphic pojo not registered: " +
                    className);
        }
       
        output.writeString(fieldNumber, className, false);
       
View Full Code Here

        final String className = input.readString();
       
        final HasSchema<T> wrapper = getSchemaWrapper(className,
                RuntimeEnv.AUTO_LOAD_POLYMORPHIC_CLASSES);
        if(wrapper == null)
            throw new ProtostuffException("polymorphic pojo not registered: " + className);
       
        return wrapper;
    }
View Full Code Here

                break;
            case ID_BIGINTEGER:
                BIGINTEGER.transfer(pipe, input, output, number, false);
                break;
            default:
                throw new ProtostuffException("Corrupt input.");
        }
    }
View Full Code Here

   
    static Object readObjectFrom(Input input,  Schema<?> schema, Object owner,
            IdStrategy strategy) throws IOException
    {
        if(ID_ENUM != input.readFieldNumber(schema))
            throw new ProtostuffException("Corrupt input.");
       
        final EnumIO<?> eio = strategy.resolveEnumFrom(input);
       
        if(ID_ENUM_VALUE != input.readFieldNumber(schema))
            throw new ProtostuffException("Corrupt input.");
       
        final Object value = eio.readFrom(input);
       
        if(input instanceof GraphInput)
        {
            // update the actual reference.
            ((GraphInput)input).updateLast(value, owner);
        }
       
        if(0 != input.readFieldNumber(schema))
            throw new ProtostuffException("Corrupt input.");
       
        return value;
    }
View Full Code Here

   
    static void transferObject(Pipe.Schema<Object> pipeSchema, Pipe pipe,
            Input input, Output output, IdStrategy strategy) throws IOException
    {
        if(ID_ENUM != input.readFieldNumber(pipeSchema.wrappedSchema))
            throw new ProtostuffException("Corrupt input.");
       
        strategy.transferEnumId(input, output, ID_ENUM);
       
        if(ID_ENUM_VALUE != input.readFieldNumber(pipeSchema.wrappedSchema))
            throw new ProtostuffException("Corrupt input.");
       
        EnumIO.transfer(pipe, input, output, 1, false);
       
        if(0 != input.readFieldNumber(pipeSchema.wrappedSchema))
            throw new ProtostuffException("Corrupt input.");
    }
View Full Code Here

        final int number = input.readFieldNumber(schema);
        switch(number)
        {
            case ID_EMPTY_SET:
                if(0 != input.readUInt32())
                    throw new ProtostuffException("Corrupt input.");
               
                if(graph)
                {
                    // update the actual reference.
                    ((GraphInput)input).updateLast(Collections.EMPTY_SET, owner);
                }
               
                ret = Collections.EMPTY_SET;
                break;
               
            case ID_EMPTY_LIST:
                if(0 != input.readUInt32())
                    throw new ProtostuffException("Corrupt input.");
               
                if(graph)
                {
                    // update the actual reference.
                    ((GraphInput)input).updateLast(Collections.EMPTY_LIST, owner);
                }
               
                ret = Collections.EMPTY_LIST;
                break;
               
            case ID_SINGLETON_SET:
            {
                if(0 != input.readUInt32())
                    throw new ProtostuffException("Corrupt input.");
               
                final Object collection = iSingletonSet.newInstance();
                if(graph)
                {
                    // update the actual reference.
                    ((GraphInput)input).updateLast(collection, owner);
                }
               
                final int next = input.readFieldNumber(schema);
                if(next == 0)
                {
                    // null element
                    return collection;
                }
               
                if(next != 1)
                    throw new ProtostuffException("Corrupt input");
               
                final Wrapper wrapper = new Wrapper();
                Object element = input.mergeObject(wrapper, strategy.OBJECT_SCHEMA);
                if(!graph || !((GraphInput)input).isCurrentMessageReference())
                    element = wrapper.value;
               
                try
                {
                    fSingletonSet_element.set(collection, element);
                }
                catch (IllegalArgumentException e)
                {
                    throw new RuntimeException(e);
                }
                catch (IllegalAccessException e)
                {
                    throw new RuntimeException(e);
                }
               
                ret = collection;
                break;
            }
           
            case ID_SINGLETON_LIST:
            {
                if(0 != input.readUInt32())
                    throw new ProtostuffException("Corrupt input.");
               
                final Object collection = iSingletonList.newInstance();
                if(graph)
                {
                    // update the actual reference.
                    ((GraphInput)input).updateLast(collection, owner);
                }
               
                final int next = input.readFieldNumber(schema);
                if(next == 0)
                {
                    // null element
                    return collection;
                }
               
                if(next != 1)
                    throw new ProtostuffException("Corrupt input.");
               
                final Wrapper wrapper = new Wrapper();
                Object element = input.mergeObject(wrapper, strategy.OBJECT_SCHEMA);
                if(!graph || !((GraphInput)input).isCurrentMessageReference())
                    element = wrapper.value;
               
                try
                {
                    fSingletonList_element.set(collection, element);
                }
                catch (IllegalArgumentException e)
                {
                    throw new RuntimeException(e);
                }
                catch (IllegalAccessException e)
                {
                    throw new RuntimeException(e);
                }
               
                ret = collection;
                break;
            }
           
            case ID_SET_FROM_MAP:
            {
                final Object collection = iSetFromMap.newInstance();
                if(graph)
                {
                    // update the actual reference.
                    ((GraphInput)input).updateLast(collection, owner);
                }
               
                final Wrapper wrapper = new Wrapper();
                Object m = input.mergeObject(wrapper, strategy.POLYMORPHIC_MAP_SCHEMA);
                if(!graph || !((GraphInput)input).isCurrentMessageReference())
                    m = wrapper.value;
               
                try
                {
                    fSetFromMap_m.set(collection, m);
                    fSetFromMap_s.set(collection, ((Map<?,?>)m).keySet());
                }
                catch (IllegalArgumentException e)
                {
                    throw new RuntimeException(e);
                }
                catch (IllegalAccessException e)
                {
                    throw new RuntimeException(e);
                }
               
                ret = collection;
                break;
            }
               
            case ID_COPIES_LIST:
            {
                if(0 != input.readUInt32())
                    throw new ProtostuffException("Corrupt input.");
               
                final Object collection = iCopiesList.newInstance();
                if(graph)
                {
                    // update the actual reference.
                    ((GraphInput)input).updateLast(collection, owner);
                }
               
                if(1 != input.readFieldNumber(schema))
                    throw new ProtostuffException("Corrupt input.");
               
                final int n = input.readUInt32(),
                        next = input.readFieldNumber(schema);
               
                if(next == 0)
                {
                    // null element
                    try
                    {
                        fCopiesList_n.setInt(collection, n);
                    }
                    catch (IllegalArgumentException e)
                    {
                        throw new RuntimeException(e);
                    }
                    catch (IllegalAccessException e)
                    {
                        throw new RuntimeException(e);
                    }
                   
                    return collection;
                }
               
                if(next != 2)
                    throw new ProtostuffException("Corrupt input.");
               
                final Wrapper wrapper = new Wrapper();
                Object element = input.mergeObject(wrapper, strategy.OBJECT_SCHEMA);
                if(!graph || !((GraphInput)input).isCurrentMessageReference())
                    element = wrapper.value;
               
                try
                {
                    fCopiesList_n.setInt(collection, n);
                    fCopiesList_element.set(collection, element);
                }
                catch (IllegalArgumentException e)
                {
                    throw new RuntimeException(e);
                }
                catch (IllegalAccessException e)
                {
                    throw new RuntimeException(e);
                }
               
                ret = collection;
                break;
            }
           
            case ID_UNMODIFIABLE_COLLECTION:
                ret = readUnmodifiableCollectionFrom(input, schema, owner, strategy, graph, 
                        iUnmodifiableCollection.newInstance(), false, false);
                break;
            case ID_UNMODIFIABLE_SET:
                ret = readUnmodifiableCollectionFrom(input, schema, owner, strategy, graph, 
                        iUnmodifiableSet.newInstance(), false, false);
                break;
            case ID_UNMODIFIABLE_SORTED_SET:
                ret = readUnmodifiableCollectionFrom(input, schema, owner, strategy, graph, 
                        iUnmodifiableSortedSet.newInstance(), true, false);
                break;
            case ID_UNMODIFIABLE_LIST:
                ret = readUnmodifiableCollectionFrom(input, schema, owner, strategy, graph, 
                        iUnmodifiableList.newInstance(), false, true);
                break;
            case ID_UNMODIFIABLE_RANDOM_ACCESS_LIST:
                ret = readUnmodifiableCollectionFrom(input, schema, owner, strategy, graph, 
                        iUnmodifiableRandomAccessList.newInstance(), false, true);
                break;
               
            case ID_SYNCHRONIZED_COLLECTION:
                ret = readSynchronizedCollectionFrom(input, schema, owner, strategy, graph, 
                        iSynchronizedCollection.newInstance(), false, false);
                break;
            case ID_SYNCHRONIZED_SET:
                ret = readSynchronizedCollectionFrom(input, schema, owner, strategy, graph, 
                        iSynchronizedSet.newInstance(), false, false);
                break;
            case ID_SYNCHRONIZED_SORTED_SET:
                ret = readSynchronizedCollectionFrom(input, schema, owner, strategy, graph, 
                        iSynchronizedSortedSet.newInstance(), true, false);
                break;
            case ID_SYNCHRONIZED_LIST:
                ret = readSynchronizedCollectionFrom(input, schema, owner, strategy, graph, 
                        iSynchronizedList.newInstance(), false, true);
                break;
            case ID_SYNCHRONIZED_RANDOM_ACCESS_LIST:
                ret = readSynchronizedCollectionFrom(input, schema, owner, strategy, graph, 
                        iSynchronizedRandomAccessList.newInstance(), false, true);
                break;
               
            case ID_CHECKED_COLLECTION:
                ret = readCheckedCollectionFrom(input, schema, owner, strategy, graph, 
                        iCheckedCollection.newInstance(), false, false);
                break;
            case ID_CHECKED_SET:
                ret = readCheckedCollectionFrom(input, schema, owner, strategy, graph, 
                        iCheckedSet.newInstance(), false, false);
                break;
            case ID_CHECKED_SORTED_SET:
                ret = readCheckedCollectionFrom(input, schema, owner, strategy, graph, 
                        iCheckedSortedSet.newInstance(), true, false);
                break;
            case ID_CHECKED_LIST:
                ret = readCheckedCollectionFrom(input, schema, owner, strategy, graph, 
                        iCheckedList.newInstance(), false, true);
                break;
            case ID_CHECKED_RANDOM_ACCESS_LIST:
                ret = readCheckedCollectionFrom(input, schema, owner, strategy, graph, 
                        iCheckedRandomAccessList.newInstance(), false, true);
                break;
               
            case ID_ENUM_SET:
            {
                final Collection<?> es = strategy.resolveEnumFrom(input).newEnumSet();
               
                if(graph)
                {
                    // update the actual reference.
                    ((GraphInput)input).updateLast(es, owner);
                }
               
                // TODO enum schema
                strategy.COLLECTION_SCHEMA.mergeFrom(input, (Collection<Object>)es);
                return es;
            }
               
            case ID_COLLECTION:
            {
                final Collection<Object> collection = strategy.resolveCollectionFrom(
                        input).newMessage();
               
                if(graph)
                {
                    // update the actual reference.
                    ((GraphInput)input).updateLast(collection, owner);
                }
               
                strategy.COLLECTION_SCHEMA.mergeFrom(input, collection);
               
                return collection;
            }
               
            default: throw new ProtostuffException("Corrupt input.");
        }
       
        if(0 != input.readFieldNumber(schema))
            throw new ProtostuffException("Corrupt input.");
       
        return ret;
    }
View Full Code Here

        Object c = input.mergeObject(wrapper, strategy.POLYMORPHIC_COLLECTION_SCHEMA);
        if(!graph || !((GraphInput)input).isCurrentMessageReference())
            c = wrapper.value;
       
        if(1 != input.readFieldNumber(schema))
            throw new ProtostuffException("Corrupt input.");
       
        Object type = input.mergeObject(wrapper, strategy.CLASS_SCHEMA);
        if(!graph || !((GraphInput)input).isCurrentMessageReference())
            type = wrapper.value;
        try
View Full Code Here

                    // null element
                    return;
                }
               
                if(next != 1)
                    throw new ProtostuffException("Corrupt input.");
               
                output.writeObject(1, pipe, strategy.OBJECT_PIPE_SCHEMA, false);
                break;
            }  
            case ID_SET_FROM_MAP:
                output.writeObject(number, pipe, strategy.POLYMORPHIC_MAP_PIPE_SCHEMA, false);
                break;
               
            case ID_COPIES_LIST:
            {
                output.writeUInt32(number, input.readUInt32(), false);
               
                if(1 != input.readFieldNumber(pipeSchema.wrappedSchema))
                    throw new ProtostuffException("Corrupt input.");
               
                // size
                output.writeUInt32(1, input.readUInt32(), false);
               
                final int next = input.readFieldNumber(pipeSchema.wrappedSchema);
                if(next == 0)
                {
                    // null element
                    return;
                }
               
                if(next != 2)
                    throw new ProtostuffException("Corrupt input.");
               
                output.writeObject(2, pipe, strategy.OBJECT_PIPE_SCHEMA, false);
                break;
            }  
            case ID_UNMODIFIABLE_COLLECTION:
            case ID_UNMODIFIABLE_SET:
            case ID_UNMODIFIABLE_SORTED_SET:
            case ID_UNMODIFIABLE_LIST:
            case ID_UNMODIFIABLE_RANDOM_ACCESS_LIST:
                output.writeObject(number, pipe, strategy.POLYMORPHIC_COLLECTION_PIPE_SCHEMA,
                        false);
                break;
               
            case ID_SYNCHRONIZED_COLLECTION:
            case ID_SYNCHRONIZED_SET:
            case ID_SYNCHRONIZED_SORTED_SET:
            case ID_SYNCHRONIZED_LIST:
            case ID_SYNCHRONIZED_RANDOM_ACCESS_LIST:
                output.writeObject(number, pipe, strategy.POLYMORPHIC_COLLECTION_PIPE_SCHEMA,
                        false);
                break;
               
            case ID_CHECKED_COLLECTION:
            case ID_CHECKED_SET:
            case ID_CHECKED_SORTED_SET:
            case ID_CHECKED_LIST:
            case ID_CHECKED_RANDOM_ACCESS_LIST:
                output.writeObject(number, pipe, strategy.POLYMORPHIC_COLLECTION_PIPE_SCHEMA,
                        false);
               
                if(1 != input.readFieldNumber(pipeSchema.wrappedSchema))
                    throw new ProtostuffException("Corrupt input.");
               
                output.writeObject(1, pipe, strategy.CLASS_PIPE_SCHEMA,
                        false);
                break;
               
            case ID_ENUM_SET:
                strategy.transferEnumId(input, output, number);
               
                if(output instanceof StatefulOutput)
                {
                    // update using the derived schema.
                    ((StatefulOutput)output).updateLast(strategy.COLLECTION_PIPE_SCHEMA, pipeSchema);
                }
               
                // TODO use enum schema
                Pipe.transferDirect(strategy.COLLECTION_PIPE_SCHEMA, pipe, input, output);
                return;
            case ID_COLLECTION:
                strategy.transferCollectionId(input, output, number);
               
                if(output instanceof StatefulOutput)
                {
                    // update using the derived schema.
                    ((StatefulOutput)output).updateLast(strategy.COLLECTION_PIPE_SCHEMA, pipeSchema);
                }
               
                Pipe.transferDirect(strategy.COLLECTION_PIPE_SCHEMA, pipe, input, output);
                return;
            default:
                throw new ProtostuffException("Corrupt input.");
        }
       
        if(0 != input.readFieldNumber(pipeSchema.wrappedSchema))
            throw new ProtostuffException("Corrupt input.");
    }
View Full Code Here

TOP

Related Classes of com.dyuproject.protostuff.ProtostuffException

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.