<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 閱讀(969) 評論(0)  編輯  收藏 所屬分類: Java
    主站蜘蛛池模板: 亚洲av永久中文无码精品| 你是我的城池营垒免费观看完整版| 国产午夜免费高清久久影院| 亚洲中文字幕无码专区| 黄色a三级三级三级免费看| 日韩视频在线免费观看| 亚洲成aⅴ人片久青草影院按摩 | 亚洲国产片在线观看| 100部毛片免费全部播放完整| 91嫩草国产在线观看免费| 亚洲乱码卡三乱码新区| 无码日韩精品一区二区免费| 亚洲中文字幕乱码AV波多JI| 国产中文字幕在线免费观看| 亚洲精品无码av人在线观看| 国产精品99精品久久免费| 亚洲综合久久久久久中文字幕| 91网站免费观看| 亚洲国产无线乱码在线观看| 四虎国产精品免费久久影院| ssswww日本免费网站片| 在线v片免费观看视频| 亚洲色大成网站www尤物| 四虎成人精品在永久免费| aaa毛片视频免费观看| 亚洲视频在线免费观看| 综合在线免费视频| 精品亚洲视频在线| 亚洲精品亚洲人成人网| 无码av免费毛片一区二区| 亚洲欧洲一区二区| 18禁无遮挡无码网站免费| 西西人体大胆免费视频| 亚洲AV人无码激艳猛片| 大地资源二在线观看免费高清| 女人裸身j部免费视频无遮挡| 日本特黄特黄刺激大片免费| 99久久免费国产特黄| 亚洲AV综合色区无码二区偷拍 | 18禁黄网站禁片免费观看不卡| 亚洲美国产亚洲AV|