1 20 package org.apache.mina.filter.codec.serialization; 21 22 import java.io.Serializable ; 23 24 import org.apache.mina.common.BufferDataException; 25 import org.apache.mina.common.ByteBuffer; 26 import org.apache.mina.common.IoSession; 27 import org.apache.mina.filter.codec.CumulativeProtocolDecoder; 28 import org.apache.mina.filter.codec.ProtocolDecoder; 29 import org.apache.mina.filter.codec.ProtocolDecoderOutput; 30 31 38 public class ObjectSerializationDecoder extends CumulativeProtocolDecoder { 39 private final ClassLoader classLoader; 40 41 private int maxObjectSize = 1048576; 43 47 public ObjectSerializationDecoder() { 48 this(Thread.currentThread().getContextClassLoader()); 49 } 50 51 54 public ObjectSerializationDecoder(ClassLoader classLoader) { 55 if (classLoader == null) { 56 throw new NullPointerException ("classLoader"); 57 } 58 this.classLoader = classLoader; 59 } 60 61 67 public int getMaxObjectSize() { 68 return maxObjectSize; 69 } 70 71 77 public void setMaxObjectSize(int maxObjectSize) { 78 if (maxObjectSize <= 0) { 79 throw new IllegalArgumentException ("maxObjectSize: " 80 + maxObjectSize); 81 } 82 83 this.maxObjectSize = maxObjectSize; 84 } 85 86 protected boolean doDecode(IoSession session, ByteBuffer in, 87 ProtocolDecoderOutput out) throws Exception { 88 if (!in.prefixedDataAvailable(4, maxObjectSize)) { 89 return false; 90 } 91 92 out.write(in.getObject(classLoader)); 93 return true; 94 } 95 } 96 | Popular Tags |