⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objectserializationcodecfactory.java

📁 mina是以Java实现的一个开源的网络程序框架
💻 JAVA
字号:
/* *  Licensed to the Apache Software Foundation (ASF) under one *  or more contributor license agreements.  See the NOTICE file *  distributed with this work for additional information *  regarding copyright ownership.  The ASF licenses this file *  to you under the Apache License, Version 2.0 (the *  "License"); you may not use this file except in compliance *  with the License.  You may obtain a copy of the License at * *    http://www.apache.org/licenses/LICENSE-2.0 * *  Unless required by applicable law or agreed to in writing, *  software distributed under the License is distributed on an *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *  KIND, either express or implied.  See the License for the *  specific language governing permissions and limitations *  under the License. * */package org.apache.mina.filter.codec.serialization;import org.apache.mina.core.buffer.BufferDataException;import org.apache.mina.core.session.IoSession;import org.apache.mina.filter.codec.ProtocolCodecFactory;import org.apache.mina.filter.codec.ProtocolDecoder;import org.apache.mina.filter.codec.ProtocolEncoder;/** * A {@link ProtocolCodecFactory} that serializes and deserializes Java objects. * This codec is very useful when you have to prototype your application rapidly * without any specific codec. * * @author The Apache MINA Project (dev@mina.apache.org) * @version $Rev: 671827 $, $Date: 2008-06-26 10:49:48 +0200 (Thu, 26 Jun 2008) $ */public class ObjectSerializationCodecFactory implements ProtocolCodecFactory {    private final ObjectSerializationEncoder encoder;    private final ObjectSerializationDecoder decoder;    /**     * Creates a new instance with the {@link ClassLoader} of     * the current thread.     */    public ObjectSerializationCodecFactory() {        this(Thread.currentThread().getContextClassLoader());    }    /**     * Creates a new instance with the specified {@link ClassLoader}.     */    public ObjectSerializationCodecFactory(ClassLoader classLoader) {        encoder = new ObjectSerializationEncoder();        decoder = new ObjectSerializationDecoder(classLoader);    }    public ProtocolEncoder getEncoder(IoSession session) {        return encoder;    }    public ProtocolDecoder getDecoder(IoSession session) {        return decoder;    }    /**     * Returns the allowed maximum size of the encoded object.     * If the size of the encoded object exceeds this value, the encoder     * will throw a {@link IllegalArgumentException}.  The default value     * is {@link Integer#MAX_VALUE}.     * <p>     * This method does the same job with {@link ObjectSerializationEncoder#getMaxObjectSize()}.     */    public int getEncoderMaxObjectSize() {        return encoder.getMaxObjectSize();    }    /**     * Sets the allowed maximum size of the encoded object.     * If the size of the encoded object exceeds this value, the encoder     * will throw a {@link IllegalArgumentException}.  The default value     * is {@link Integer#MAX_VALUE}.     * <p>     * This method does the same job with {@link ObjectSerializationEncoder#setMaxObjectSize(int)}.     */    public void setEncoderMaxObjectSize(int maxObjectSize) {        encoder.setMaxObjectSize(maxObjectSize);    }    /**     * Returns the allowed maximum size of the object to be decoded.     * If the size of the object to be decoded exceeds this value, the     * decoder will throw a {@link BufferDataException}.  The default     * value is <tt>1048576</tt> (1MB).     * <p>     * This method does the same job with {@link ObjectSerializationDecoder#getMaxObjectSize()}.     */    public int getDecoderMaxObjectSize() {        return decoder.getMaxObjectSize();    }    /**     * Sets the allowed maximum size of the object to be decoded.     * If the size of the object to be decoded exceeds this value, the     * decoder will throw a {@link BufferDataException}.  The default     * value is <tt>1048576</tt> (1MB).     * <p>     * This method does the same job with {@link ObjectSerializationDecoder#setMaxObjectSize(int)}.     */    public void setDecoderMaxObjectSize(int maxObjectSize) {        decoder.setMaxObjectSize(maxObjectSize);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -