<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    夢幻之旅

    DEBUG - 天道酬勤

       :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      671 隨筆 :: 6 文章 :: 256 評論 :: 0 Trackbacks
    package org.upeng.mail.net.util;

    import org.apache.mina.core.buffer.IoBuffer;
    import org.apache.mina.core.session.IoSession;
    import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
    import org.apache.mina.filter.codec.ProtocolDecoderOutput;

    public class MessageDecoder extends CumulativeProtocolDecoder
    {
        
    public static final int MAX_IMAGE_SIZE = 1024 * 1024 * 5;
        
        
    private static final String DECODER_STATE_KEY = getKey();
        
        
    protected boolean doDecode(IoSession session, IoBuffer in,
                ProtocolDecoderOutput out) 
    throws Exception
        
    {
            System.out.println(
    "decode-開始");
            
            Context context 
    = (Context) session.getAttribute(DECODER_STATE_KEY);
            
    if(context == null)
            
    {
                context 
    = new Context();
                session.setAttribute(DECODER_STATE_KEY, context);
            }

            
            
    while(true)
            
    {
                
    if (in.prefixedDataAvailable(4, MAX_IMAGE_SIZE))
                
    {
                    
    int pieceLength = in.getInt();
                    
    int totalLength = in.getInt();
                    context.setTotalLength(totalLength);
                    
    byte[] bytes = new byte[pieceLength - 4];
                    in.get(bytes);
                    context.addPiece(bytes);
                    
    if (context.isComplete())
                    
    {
                        Message message 
    = new Message(context.getTotalData());
                        out.write(message);
                        session.removeAttribute(DECODER_STATE_KEY);
                        
    return true;
                    }

                }

                
    else
                
    {
                    
    return false;
                }

            }

            
    //System.out.println("decode-結束");
            
    //return false;
        }

        
        
    /**
         * <ul>
         * <li>Description:[得到鍵值]</li>
         * <li>Created by [Huyvanpull] [2011-9-5]</li>
         * <li>Midified by [modifier] [modified time]</li>
         * </ul>
         * 
         * 
    @return
         
    */

        
    private static String getKey()
        
    {
            
    return MessageDecoder.class.getName() + ".STATE";
        }

    }

    2.
    package org.upeng.mail.net.util;

    import java.util.List;

    import org.apache.mina.core.buffer.IoBuffer;
    import org.apache.mina.core.session.IoSession;
    import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
    import org.apache.mina.filter.codec.ProtocolEncoderOutput;

    public class MessageEncoder extends ProtocolEncoderAdapter
    {
        
    public void encode(IoSession session, Object message,
                ProtocolEncoderOutput out) 
    throws Exception
        
    {
            System.out.println(
    "encode-開始");
            Message msg 
    = (Message) message;
            
            IoBuffer buffer 
    = IoBuffer.allocate(1024).setAutoExpand(true);
            
            
    // 定義上下文
            Context context = new Context(msg.getDataBody());
            List
    <byte[]> pieceLst = context.getPieceLst();
            
    for (int i=0; i<pieceLst.size(); i++)
            
    {
                
    byte[] temp = pieceLst.get(i);
                buffer.putInt(temp.length 
    + 4);
                buffer.putInt(msg.getDataBody().length);
                buffer.put(temp);
            }

            buffer.flip();
            out.write(buffer);
            out.flush();
            System.out.println(
    "decode-結束");
        }

        
    }



    posted on 2011-09-05 19:17 HUIKK 閱讀(959) 評論(0)  編輯  收藏 所屬分類: Java
    主站蜘蛛池模板: 污污污视频在线免费观看| 黄色网站软件app在线观看免费 | 中文无码日韩欧免费视频| 国产精品亚洲片在线| 韩国免费一级成人毛片| 免费播放美女一级毛片| 亚洲男人天堂av| 妞干网免费观看视频| a在线视频免费观看| 亚洲男人的天堂久久精品| 亚洲国产精品成人| 91精品成人免费国产片| 日韩精品视频在线观看免费| 精品亚洲麻豆1区2区3区| 啊v在线免费观看| 6080午夜一级毛片免费看6080夜福利 | 麻豆一区二区三区蜜桃免费| 亚洲AV日韩AV永久无码免下载| 成人黄动漫画免费网站视频 | 久久久久国产成人精品亚洲午夜| 84pao强力永久免费高清| 黄色网址大全免费| 久久精品国产亚洲av麻豆图片| 最新亚洲成av人免费看| 成人性生交大片免费看午夜a| 日本免费在线中文字幕| 美女被爆羞羞网站免费| 亚洲videosbestsex日本| 亚洲中文字幕日产乱码高清app| 在线播放高清国语自产拍免费| 一区二区三区在线免费看| 一个人看的www免费在线视频| 美女视频黄免费亚洲| 亚洲自偷自拍另类12p| 中文字幕亚洲天堂| 免费看国产一级片| 夜夜爽免费888视频| 久草免费在线观看视频| 中国人免费观看高清在线观看二区| 久久久久亚洲AV无码去区首| 亚洲免费观看网站|