亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? complexserializer.java

?? SyncML的java實現類庫 funambol公司發布的
?? JAVA
字號:
/*
 * Copyright (C) 2006-2007 Funambol
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package com.funambol.storage;

import com.funambol.util.StringUtil;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.util.Date;
import java.util.Hashtable;
import java.util.Vector;
import java.util.Enumeration;
import java.io.IOException;

import com.funambol.util.Log;

/**
 * A helper class useful to persist objects like <code>Vector</code>s and
 * <code>Hashtable</code>s into the device's store
 */
public class ComplexSerializer {
    
    private static final int NULL = 0;
    private static final int INTEGER = 1;
    private static final int STRING = 2;
    private static final int SERIALIZED = 3;
    private static final int BYTE_ARRAY = 4;
    private static final int HASHTABLE = 5;
    private static final int VECTOR = 6;
    
    
    /**
     * A helper method to serialize an <code>Object</code>.<p>
     * 
     * It can serialize basic objects and the ones implementing the Serializable
     * interface.
     * 
     * TODO: implement more basic objects.
     * @param dout The stream to write data to
     * @param obj The Object to be serialized
     */
    public static void serializeObject(DataOutputStream dout, Object obj)
            throws IOException {
        if (obj instanceof String) {
            dout.writeByte(STRING);
            dout.writeUTF((String)obj);
        } else if (obj instanceof Integer) {
            dout.writeByte(INTEGER);
            dout.writeInt(((Integer)obj).intValue());
        } else if (obj instanceof byte[]) {
            dout.writeByte(BYTE_ARRAY);
            dout.writeInt(((byte[])obj).length);
            dout.write((byte[])obj, 0, ((byte[])obj).length);
        } else if (obj instanceof Serializable) {
            dout.writeByte(SERIALIZED);
            dout.writeUTF(obj.getClass().getName());
            ((Serializable)obj).serialize(dout);
        } else if (obj instanceof Hashtable) {
            dout.writeByte(HASHTABLE);
            serializeHashTable(dout, (Hashtable) obj);
        } else if (obj instanceof Vector) {
            dout.writeByte(VECTOR);
            serializeVector(dout, (Vector) obj);
        } else if (obj == null) {
            dout.writeByte(NULL);
        } else {
            throw new IOException("Cannot serialize object of type "
                    + obj.getClass().getName());
        }
    }
    
    
    /**
     * A helper method to deserialize an <code>Object</code>.<p> It can
     * deserialize basic objects and the ones implementing the Serializable
     * interface.
     * 
     * TODO: implement more basic objects.
     * @param din The stream to write data from
     * @return The Object deserialzed
     */
    public static Object deserializeObject(DataInputStream din)
            throws IOException {

        int type = din.readByte();

        if (type == NULL) {
            return null;
        } else if (type == INTEGER) {
            return (Object)(new Integer(din.readInt()));
        } else if (type == BYTE_ARRAY) {
            byte[] array = new byte[din.readInt()];
            din.read(array);
            return array;
        } else if (type == STRING) {
            return (Object)(din.readUTF());
        } else if (type == HASHTABLE) {
            return deserializeHashTable(din);
        } else if (type == VECTOR) {
            return deserializeVector(din);
        } else if (type == SERIALIZED) {
            String cname = din.readUTF();

            try {
                Class cl = Class.forName(cname);
                Object obj = cl.newInstance();
                ((Serializable)obj).deserialize(din);
                return obj;
            } catch (IOException ioe) {
                Log.error("[deserializeObject] cname: " + cname + " - " + 
                        ioe.toString());
               
                throw ioe;
            } catch (IllegalAccessException iae) {
                String msg = "[deserializeObject] Cannot instantiate class: " +
                        cname + " - " + iae.toString();
                Log.error(msg);
            
                throw new IOException(msg);
            } catch (Exception e) {
                String msg = "[deserializeObject] Exception on cname: " + 
                        cname + " - " + e.toString();
                Log.error(msg);
           
                throw new IOException(msg);
            }
        } else {
            throw new IOException("Deserialization error. Unknown type: [" + 
                    type + "]");
        }
    }
    
    
    /**
     * A helper method to serialize a <code>Hashtable</code> <p>
     *
     * @param dout
     *            The stream to write data to
     * @param ht
     *            The Hashtable to be serialized
     */
    public static void serializeHashTable(DataOutputStream dout, Hashtable ht)
    throws IOException {
        // Store size
        dout.writeInt(ht.size());
        // Iterate through keys
        for(Enumeration e = ht.keys(); e.hasMoreElements(); ){
            Object key = e.nextElement();
            Object val = ht.get(key);
            serializeObject(dout, key);
            serializeObject(dout, val);
        }
    }
    
    
    /**
     * A helper method to deserialize a <code>Hashtable</code> <p>
     *
     * @param din
     *            The stream to write data from
     * @return
     *            The Hashtable deserialzed
     */
    public static Hashtable deserializeHashTable(DataInputStream din)
    throws IOException {
        // Retrieve size
        int size = din.readInt();
        Hashtable ht = new Hashtable();
        
        for(int i=0; i<size; i++){
            Object key = deserializeObject(din);
            Object val = deserializeObject(din);
            ht.put(key, val);
        }
        return ht;
    }
    
    
    /**
     * A helper method to serialize a <code>Vector</code> <p>
     * @param dout The stream to write data to
     * @param v The Vector to be serialized
     */
    public static void serializeVector(DataOutputStream dout, Vector v ) 
                                                            throws IOException {
        
        int n = v.size();
        try {
            dout.writeInt( n );
        } catch (IOException ex) {
            ex.printStackTrace();
            Log.error("IOException  in serializeVector!");
        }
        
        for( int i = 0; i < n; i++ ){
                serializeObject(dout, v.elementAt(i));
        }
    }
    
    
    /**
     * A helper method to deserialize a <code>Vector</code> <p>
     * @param din The stream to write data to
     * @return The deserialized Vector
     */
    public static Vector deserializeVector(DataInputStream din)
    throws IOException {
        
        Vector v = new Vector();
        int n = din.readInt();
        
        for( int i = 0; i < n; ++i ){
            Object obj = deserializeObject(din);
            v.addElement(obj);
        }
        
        return v;
        
    }
    
    /**
     * Write a UTF field to the given DataOutputStream
     * If the field is not null or empty write a "true" before the field, 
     * just "False" otherwise
     * @param out is the DataOutputStream to be written on
     * @param field is the field to be written on the 
     * @throws IOException
     * <p><b>USE THIS METHOD JUST TO WRITE A STRING INTO AN OBJECT WHICH STATE 
     * IS UNKNOWN AT THE MOMENT OF THE DESERIALIZATION: null field will be  
     * written as boolean false into the OutputStream. </p>
     * <p> Read the written Stream using the
     * com.funambol.common.ComplexSerializer.readField(DataOutputStream in) 
     * method.</b></p>
     *
    public static void writeNullOrEmptyField(DataOutputStream out, String field) throws IOException {
        if (!StringUtil.isNullOrEmpty(field)) {
            out.writeBoolean(true);
            out.writeUTF(field);
        } else {
            out.writeBoolean(false);
        }
    }*/
  
    /**
     * Write a UTF field to the given DataOutputStream
     * If the field is not null write a "true" before the field, 
     * just "False" otherwise. This method write true for Empty strings.
     * @param out is the DataOutputStream to be written on
     * @param field is the field to be written on the 
     * @throws IOException
     *
     * <p>Use this method to write a string that can be null at the moment
     * of the serialization: null field will be written as boolean false 
     * into the OutputStream. </p>
     * <p> Read the written Stream using the
     * com.funambol.common.ComplexSerializer.readField(DataOutputStream in) 
     * method.</p>
     */
    public static void writeField(DataOutputStream out, String field) throws IOException {
        if (field!=null) {
            out.writeBoolean(true);
            out.writeUTF(field);
        } else {
            out.writeBoolean(false);
        }
    }
  
    
    /**
     * Read a UTF field to the given DataInputStream
     * If the field exists write a "true", "False" otherwise
     * @param in is the DataInputStream to be read
     * @throws IOException
     * @return String if field exists, null otherwise
     * <p>Use this method to read a string written with:
     * com.funambol.common.ComplexSerializer.writeField(DataInputStream out, 
     * String field) method.</p>
     */
    public static String readField(DataInputStream in) throws IOException {
        if (in.readBoolean()) {
            return in.readUTF();
        }
        return null;
    }
    
    /**
     * Serialize a given array of objects into a given DataOutputStream
     * @param out is the stream to be written
     * @param s is the Serializable object array to be serialized
     */
    public static void serializeObjectArray(DataOutputStream out, 
                                          Object[] obj/*Serializable[] s*/) throws IOException {
        
        /*out.writeInt(s.length);
        for (int i=0; i<s.length; i++) {
            s[i].serialize(out);
        }*/
        
        out.writeInt(obj.length);
        for (int i=0; i<obj.length; i++) {
            serializeObject(out, obj[i]);
        }
    }
    
    /**
     * Deserialize a given DataInputStream into a given array of objects.
     *
     * @param out is the stream to be written
     * @param s is the Serializable object array to be serialized
     */
    public static Object[] deserializeObjectArray(
                                        DataInputStream in) throws IOException {
        
        /*int length = in.readInt();
        for (int i=0; i<length; i++) {
            s[i].deserialize(in);
        }
        return s;*/
        
        int length = in.readInt();
        Object[] obj = new Object[length];
        for (int i=0; i<length; i++) {
            obj[i] = deserializeObject(in);
        }
        return obj;
    }
    
    /**
     * Write a Date field to the given DataOutputStream.
     * <p>Use this method to write a Date field that can be null: null field 
     * will be written as 0L into the OutputStream. </p>
     * <p> Read the written Stream using the
     * com.funambol.common.ComplexSerializer.readDateField(DataOutputStream in) 
     * method.
     *
     * @param out is the DataOutputStream to be written on
     * @param Date is the field to be written on the 
     * @throws IOException
     *
     * Note: the midnight of the 01/01/1970 will be considered null.</p>
     */
    public static void writeDateField(DataOutputStream out, Date field)
    throws IOException {   
        if (field!=null) {
            out.writeLong(field.getTime());
        } else {
            out.writeLong(0L);
        }
    }
  
    
    /**
     * Read a UTF field to the given DataInputStream.
     * <p>Use this method to read a string written with:
     * com.funambol.common.ComplexSerializer.writeDateField(DataInputStream out, 
     * String field) method.</b></p>
     *
     * @param in is the DataInputStream to be read
     * @throws IOException
     * @return Date value if field exists, null otherwise
     */
    public static Date readDateField(DataInputStream in) throws IOException {
        long d = in.readLong();
        if (d > 0) {
            return new Date(d);
        }
        return null;
    }
    
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品一区二区在线观看| 亚洲日本丝袜连裤袜办公室| 成人亚洲精品久久久久软件| 中文字幕第一区| 色嗨嗨av一区二区三区| 国产精品久久久久久久久搜平片| 青青草97国产精品免费观看 | 日韩欧美电影在线| av中文字幕亚洲| 91麻豆自制传媒国产之光| 国产专区欧美精品| 天天av天天翘天天综合网 | 国产精品66部| 日本中文字幕一区二区有限公司| 亚洲日韩欧美一区二区在线| 久久影院午夜论| 制服丝袜激情欧洲亚洲| 在线一区二区三区做爰视频网站| 国产成人精品一区二区三区四区 | 国产精品 欧美精品| 蜜桃一区二区三区在线| 亚洲成人你懂的| 又紧又大又爽精品一区二区| 中文字幕在线一区| 国产欧美日韩卡一| 久久久久久久久99精品| 精品乱人伦小说| 日韩欧美专区在线| 69堂成人精品免费视频| 欧美精品日韩一本| 3atv一区二区三区| 7777精品伊人久久久大香线蕉的| 国产精品亲子乱子伦xxxx裸| 欧美三级视频在线| 欧美在线高清视频| 欧美手机在线视频| 欧美三区在线视频| 精品视频在线免费| 这里只有精品电影| 日韩欧美一区二区久久婷婷| 日韩欧美一级片| 2020国产精品久久精品美国| 欧美精品一区视频| 中文一区二区在线观看| 国产精品欧美一区喷水| ...av二区三区久久精品| 自拍偷拍国产亚洲| 亚洲精品大片www| 午夜av电影一区| 日本一道高清亚洲日美韩| 美女www一区二区| 国产精品77777| 97久久精品人人做人人爽| 在线观看一区不卡| 在线不卡免费av| www激情久久| 中文字幕不卡的av| 玉足女爽爽91| 免费成人美女在线观看| 国产激情91久久精品导航| 91猫先生在线| 91精品国产综合久久精品麻豆 | 亚洲品质自拍视频| 亚洲国产毛片aaaaa无费看| 日韩中文字幕亚洲一区二区va在线 | 精品成人佐山爱一区二区| 欧美激情一区不卡| 亚洲美女免费视频| 美女一区二区在线观看| 成人黄动漫网站免费app| 欧美艳星brazzers| 亚洲精品一区二区三区福利| 国产91精品精华液一区二区三区 | 精品一区二区三区av| 风间由美一区二区av101| 欧美三级韩国三级日本三斤| 精品理论电影在线观看| 亚洲乱码日产精品bd| 麻豆国产91在线播放| 91小视频在线| 欧美电影免费观看完整版| 亚洲人妖av一区二区| 久久97超碰国产精品超碰| 99v久久综合狠狠综合久久| 欧美一二三区精品| 中文字幕一区二| 久久se精品一区精品二区| 色婷婷亚洲精品| 国产日韩欧美激情| 日韩av中文字幕一区二区三区| 成人午夜大片免费观看| 这里只有精品免费| 亚洲男人电影天堂| 国产麻豆欧美日韩一区| 欧美三级视频在线| 国产精品成人免费| 国产一区二区不卡在线| 欧美精品久久天天躁| 成人欧美一区二区三区1314| 久久se精品一区精品二区| 欧美日韩精品高清| 国产精品国产自产拍高清av| 激情图片小说一区| 色噜噜夜夜夜综合网| 国产精品久久久久影院亚瑟| 美国精品在线观看| 欧美在线啊v一区| 亚洲视频一二三区| 国产高清一区日本| 欧美成人a视频| 日本中文字幕不卡| 91成人看片片| 亚洲日本成人在线观看| 国产成人av在线影院| 精品不卡在线视频| 裸体一区二区三区| 欧美日韩国产综合视频在线观看| 亚洲色图.com| 成人性色生活片免费看爆迷你毛片| 日韩精品一区二区三区在线 | 免费观看久久久4p| 欧美精选一区二区| 亚洲综合久久av| 97久久精品人人做人人爽| 国产精品久久久久久久久免费相片 | 6080亚洲精品一区二区| 一区二区三区蜜桃网| 91在线精品一区二区三区| 国产精品女主播av| av不卡在线播放| 日韩一区日韩二区| 91麻豆成人久久精品二区三区| 国产精品高潮呻吟久久| caoporn国产一区二区| 日本一二三四高清不卡| 丁香婷婷深情五月亚洲| 国产精品天天看| 99免费精品视频| 亚洲黄色av一区| 欧美嫩在线观看| 麻豆91精品91久久久的内涵| 精品久久久久av影院 | 成人国产在线观看| 自拍偷自拍亚洲精品播放| 色激情天天射综合网| 亚洲一区二区不卡免费| 精品污污网站免费看| 日本不卡不码高清免费观看| 精品国产亚洲在线| 国产·精品毛片| 亚洲特黄一级片| 欧美视频第二页| 日韩不卡在线观看日韩不卡视频| 欧美成人欧美edvon| 国产不卡视频在线播放| 综合久久给合久久狠狠狠97色| 色欧美乱欧美15图片| 视频一区二区不卡| wwww国产精品欧美| 不卡区在线中文字幕| 亚洲高清免费视频| 久久这里只有精品6| 92精品国产成人观看免费| 性欧美疯狂xxxxbbbb| 精品国产91乱码一区二区三区| 成人免费视频免费观看| 亚洲午夜激情网站| 精品欧美一区二区久久| 91免费观看视频在线| 日韩电影在线一区| 国产视频一区二区在线观看| 日本精品一区二区三区四区的功能| 无吗不卡中文字幕| 国产亚洲欧美在线| 欧美影视一区在线| 国产一区二区三区日韩| 亚洲免费三区一区二区| 亚洲精品一区二区三区99| 色视频一区二区| 国产在线视视频有精品| 一区二区三区 在线观看视频| 精品成人一区二区三区| 欧美在线你懂得| 懂色av中文一区二区三区| 天天综合色天天综合| 国产精品美女久久久久aⅴ| 6080午夜不卡| 一本一道久久a久久精品| 国产一区二区三区四| 三级欧美韩日大片在线看| 国产精品久久久久久久久免费相片| 91 com成人网| 91偷拍与自偷拍精品| 国产精品综合网| 日本午夜精品视频在线观看 | 国产激情一区二区三区桃花岛亚洲| 亚洲综合小说图片| 国产精品卡一卡二| 精品国产人成亚洲区| 欧美精品自拍偷拍动漫精品|