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

📄 index.java

📁 RMS记录集源码
💻 JAVA
字号:
/*
 * Created on 2004-7-11
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.north.phonebook.model;

import java.io.*;

/**
 * @author P2800
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class Index
{
    private String key;
    private int recordID;

    public Index(String key, int recordID)
    {
        this.key = key;
        this.recordID = recordID;
    }

    private Index()
    {
    }

    /**
     * @return Returns the key.
     */
    public String getKey()
    {
        return key;
    }
    /**
     * @param key The key to set.
     */
    public void setKey(String key)
    {
        this.key = key;
    }
    /**
     * @return Returns the recordID.
     */
    public int getRecordID()
    {
        return recordID;
    }
    /**
     * @param recordID The recordID to set.
     */
    public void setRecordID(int recordID)
    {
        this.recordID = recordID;
    }
    public byte[] serialize() throws IOException
    {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);

        dos.writeUTF(key);
        dos.writeInt(recordID);
        baos.close();
        dos.close();

        return baos.toByteArray();
    }

    public static Index deserialize(byte[] data) throws IOException
    {
        ByteArrayInputStream bais = new ByteArrayInputStream(data);
        DataInputStream dis = new DataInputStream(bais);

        Index index = new Index();

        index.key = dis.readUTF();
        index.recordID = dis.readInt();
	bais.close();
	dis.close();
        return index;
    }

    public static boolean matches(byte[] data, String key,int type) throws IOException
    {
        ByteArrayInputStream bais = new ByteArrayInputStream(data);
        DataInputStream dis = new DataInputStream(bais);
        
        if(type == 101)
        {
            return (dis.readUTF()).equals(key);
        }
        else if(type == 102)
        {
            return (dis.readUTF()).startsWith(key);
        }
        return false;
    }

}

⌨️ 快捷键说明

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