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

📄 mark.java

📁 很好的基于java的手机文本阅读器anyview 2.0源码,
💻 JAVA
字号:
package com.ismyway.anyview;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.*;

/**
 * <p>Title: AnyView</p>
 *
 * <p>Description: E680(I) Reader</p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: www.ismyway.com</p>
 *
 * @author ZhangJian
 * @version 1.0
 */

//////////////////////////
// Mark类主要是对书签项进行封装
/////////////////////////
public class Mark {
    public int chapter = 0; //当前章节(当格式为TXT时,此处为0)
    public int offset = 0; //当前偏移
    public byte[] data = new byte[24]; //从当前偏移开始的24字节(校验用)

    private Mark() {

    }

    /**
     * 新建一个书签项
     * @param chapter int 章节信息
     * @param offset int 相对于章节的偏移量
     * @param data byte[] 章节数据
     */
    public Mark(int chapter, int offset, byte[] data) {
        this.chapter = chapter;
        this.offset = offset;
        for (int i = 0; data != null && i < 24 && i < data.length; i++) {
            this.data[i] = data[i];
        }
    }

    /**
     * 将字节数组转换为书签项
     * @param data byte[] 字节组数
     * @return Mark 返回书签项对象
     */
    public final static Mark getMark(byte[] data) {
        Mark mark = new Mark();
        try {
            ByteArrayInputStream bais = new ByteArrayInputStream(
                    data);
            DataInputStream dis = new DataInputStream(bais);
            mark.chapter = dis.readInt();
            mark.offset = dis.readInt();
            dis.read(mark.data);
            dis.close();
            bais.close();
        } catch (IOException ex) {
        }
        return mark;
    }

    /**
     * 以字节数组形式返回当前书签,数组长度应该为32
     * @return byte[]
     */
    public byte[] getByte() {
        byte[] abyte0 = null;
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(baos);
            dos.writeInt(chapter);
            dos.writeInt(offset);
            dos.write(data);
            abyte0 = baos.toByteArray();
            dos.close();
            baos.close();
        } catch (IOException ex) {
            abyte0 = null;
        }
        return abyte0;
    }


    /*public final static byte[] getByte(int chapter, int offset, byte[] data) {
        byte[] b = new byte[24];
        for (int i = 0; data != null && i < 24 && i < data.length; i++) {
            b[i] = data[i];
        }

        byte[] abyte0 = null;
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(baos);
            dos.writeInt(chapter);
            dos.writeInt(offset);
            dos.write(b);
            abyte0 = baos.toByteArray();
            dos.close();
            baos.close();
        } catch (IOException ex) {
            abyte0 = null;
        }
        return abyte0;
         }*/

}

⌨️ 快捷键说明

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