Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package lt.marsrutai.mobile.serialize;
 
 import java.util.List;
 import java.util.Map;
public class ProtostuffSerializer implements Serializer {
    @SuppressWarnings("rawtypes")
    private Map<StringSchemarequestToSchemaMap = new HashMap<StringSchema>();
    @SuppressWarnings("unchecked")
    @Override
    public byte[] writeObject(SerializeRequest request) {
        if (!.containsKey(request.getName())) {
            throw new SerializeException("Unknown object name: " + request.getName());
        }
        List<ObjectobjectList = null;
        if (.contains(request.getName())) {
            objectList = new ArrayList<Object>();
            objectList.add(request.getObject());
        }
        else {
            objectList = (List<Object>) request.getObject();
        }
        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            GZIPOutputStream gos = new GZIPOutputStream(bos);
            ProtostuffIOUtil.writeListTo(gosobjectList.get(request.getName()), LinkedBuffer.allocate(256));
            gos.flush();
            gos.close();
            return bos.toByteArray();
        }
        catch (IOException e) {
            throw new SerializeException(e);
        }
    }
    @SuppressWarnings("unchecked")
    @Override
    public Object readObject(DeserializeRequest request) {
        if (!.containsKey(request.getName())) {
            throw new SerializeException("Unknown object name: " + request.getName());
        }
        try {
            ByteArrayInputStream bis = new ByteArrayInputStream(request.getArray());
            GZIPInputStream gis = new GZIPInputStream(bis);
            Object object = ProtostuffIOUtil.parseListFrom(gis.get(request.getName()));
            if (.contains(request.getName())) {
                List<ObjectobjectList = (List<Object>) object;
                if (null != objectList && objectList.size() == 1) {
                    object = objectList.get(0);
                }
            }
            return object;
        }
        catch (IOException e) {
            throw new SerializeException(e);
        }
    }
    @SuppressWarnings("rawtypes")
    public void configure(Map<StringClass<?>> requestToClassMapList<StringrequestsReturningObject) {
         = new HashMap<StringSchema>(requestToClassMap.size());
        for (Map.Entry<StringClass<?>> entryrequestToClassMap.entrySet()) {
            .put(entry.getKey(), RuntimeSchema.getSchema(entry.getValue()));
        }
        this. = requestsReturningObject;
    }
New to GrepCode? Check out our FAQ X