• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            life02

              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
              197 隨筆 :: 3 文章 :: 37 評論 :: 0 Trackbacks
              1 
            http://topic.csdn.net/u/20111214/20/2534c03f-5447-4541-91e2-1ee2ca97c786.html?2906

              2 package Cool;
              3 
              4 import java.io.UnsupportedEncodingException;
              5 import java.util.ArrayList;
              6 import java.util.List;
              7 
              8 import Adapter.MyTextView;
              9 import Util.CT;
             10 import android.widget.TextView;
             11 
             12 public class TextReader {
             13     /** 文件的顯示控件 */
             14     private TextView mTextView;
             15 
             16     /** 文件名 */
             17     private String mFilePath = null;
             18 
             19     /** 默認的文件編碼形式 */
             20     private String mEncoding = "gb2312";
             21 
             22     /** 文件末尾 */
             23     private boolean mEndOfDoc = false;
             24 
             25     /** 文件開頭 */
             26     private boolean mBeforeOfDoc = true;
             27 
             28     /** 當前顯示緩沖的顯示行列表 */
             29     private List<TxtLine> mCurrentList = new ArrayList<TxtLine>();
             30 
             31     /** 讀取文件的輸入流工具類 */
             32     private RandomAccessRead mRaf = null;
             33 
             34     /** 用于保存部分文件的緩沖區大小 */
             35     private int mDataLengthOfOneDoc = 100 * 1024;
             36 
             37     /** 屏幕寬度和高度 */
             38     private int mViewWidth, mViewHeight;
             39 
             40     /** 文件大小 */
             41     private long mFileLength;
             42 
             43     /** 緩沖區中用于顯示當前頁面的第一行 */
             44     private int mCurrentLine = 0;
             45 
             46     /** 緩沖區中用于顯示當前頁面的起始索引 */
             47     private int mCurrentOffset = 0;
             48 
             49     /** 文件中用于顯示當前頁面的起始索引 */
             50     private int mStartOffset = 0;
             51 
             52     /** 用于顯示當前頁面的數組的起始索引 */
             53     private int mDataStartLocation = 0;
             54 
             55     /** 用于顯示當前頁面的數組的結尾索引 */
             56     private int mDataEndLocation = 0;
             57 
             58     /** 當前顯示的文件大小百分比 */
             59     private int mPercent = 0;
             60 
             61     /** 文件中用于顯示當前頁面的結尾索引 */
             62     private int mEndOffset = 0;
             63 
             64     /** 用于顯示當前頁面的數組 */
             65     private byte[] mScreenData = null;
             66 
             67     /** 用于顯示的緩沖數組 */
             68     private byte[] mDisplayBuffer = null;
             69 
             70     /**
             71      * 構造函數
             72      * 
             73      * @param mTextView
             74      *            顯示控件
             75      * @param mScreenWidth
             76      *            屏幕寬度
             77      * @param mScreenHeight
             78      *            屏幕高度
             79      * @param mFilePath
             80      *            文件路徑
             81      * @param mEncoding
             82      *            文件編碼
             83      */
             84     public TextReader(MyTextView mTextView, int mScreenWidth, int mScreenHeight,
             85             String mFilePath, String mEncoding) {
             86         this.mTextView = mTextView;
             87         this.mFilePath = mFilePath;
             88         this.mEncoding = mEncoding;
             89         this.mViewWidth = mScreenWidth;
             90         this.mViewHeight = mScreenHeight;
             91         init();
             92     }
             93 
             94     public void readFile() {
             95         readNextBuffer();
             96         analyzeDisplayBuffer();
             97         displayNextScreen(0);
             98     }
             99 
            100     /**
            101      * 獲取讀取文件的輸入流以及文件大小
            102      */
            103     private void init() {
            104         // TODO Auto-generated method stub
            105         this.mRaf = new RandomAccessRead(mFilePath);
            106         this.mFileLength = mRaf.length();
            107         if (this.mFileLength == 0) {
            108             mTextView.setText(Constant.NODATAINFILE);
            109             return;
            110         }
            111     }
            112 
            113     /**
            114      * 獲取下一個緩沖區
            115      */
            116     private void readNextBuffer() {
            117         mRaf.openNewStream();
            118         mRaf.locate(mStartOffset);
            119         byte[] b = new byte[mDataLengthOfOneDoc];
            120         mCurrentOffset = mStartOffset;
            121         int actualLength = mRaf.readBytes(b);
            122         if (mStartOffset == 0) {
            123             mBeforeOfDoc = true;
            124         } else {
            125             mBeforeOfDoc = false;
            126         }
            127         if (actualLength < mDataLengthOfOneDoc) {
            128             mEndOfDoc = true;
            129         } else {
            130             mEndOfDoc = false;
            131         }
            132 
            133         if (actualLength == -1 && mScreenData.length == 0) {// 意外到了文件流的末尾或者
            134             mTextView.setText("讀取文件失或者文件緩沖區失敗");
            135             return;
            136         }
            137 
            138         if (mEndOfDoc) {
            139             mDisplayBuffer = new byte[actualLength];
            140             System.arraycopy(b, 0, mDisplayBuffer, 0, actualLength);
            141             b = null;
            142             System.gc();
            143             return;
            144         }
            145         /** 最后一個換行符的索引 */
            146         int readDataLength = actualLength;
            147         int nLocation = 0;
            148         while (readDataLength > 0) {
            149             if ((b[readDataLength - 1& 0xff== 10) {
            150                 nLocation = readDataLength;
            151                 break;
            152             }
            153             readDataLength--;
            154         }
            155         if (nLocation == 0) {
            156             System.exit(1);
            157         }
            158         int displayLength = nLocation;
            159         mDisplayBuffer = new byte[displayLength];
            160         System.arraycopy(b, 0, mDisplayBuffer, 0, displayLength);
            161         b = null;
            162         System.gc();
            163     }
            164 
            165     /**
            166      * 獲取上一個緩沖區
            167      */
            168     private void readPreBuffer() {
            169         int offsetOfLastScreen = mCurrentList.get(mCurrentLine).offset;
            170         if (offsetOfLastScreen <= mDataLengthOfOneDoc) {
            171             mBeforeOfDoc = true;
            172             // if(offsetOfLastScreen>=mFileLength){
            173             // mEndOfDoc=true;
            174             // }
            175             byte[] b = new byte[offsetOfLastScreen];
            176             mRaf.openNewStream();
            177             int actualLength = mRaf.readBytes(b);
            178             if (actualLength < offsetOfLastScreen) {
            179                 mEndOfDoc = true;
            180             } else {
            181                 mEndOfDoc = false;
            182             }
            183             if (actualLength == -1 && mScreenData.length == 0) {// 意外到了文件流的末尾或者
            184                 mTextView.setText("讀取文件失或者文件緩沖區失敗");
            185                 return;
            186             }
            187 
            188             if (mEndOfDoc) {
            189                 mDisplayBuffer = new byte[actualLength];
            190                 System.arraycopy(b, 0, mDisplayBuffer, 0, actualLength);
            191                 b = null;
            192                 System.gc();
            193                 mCurrentOffset = 0;
            194                 return;
            195             }
            196             /** 最后一個換行符的索引 */
            197             int readDataLength = actualLength;
            198             int nLocation = 0;
            199             while (readDataLength > 0) {
            200                 if ((b[readDataLength - 1& 0xff== 10) {
            201                     nLocation = readDataLength;
            202                     break;
            203                 }
            204                 readDataLength--;
            205             }
            206             if (nLocation == 0) {
            207                 System.exit(1);
            208             }
            209             int displayLength = nLocation;
            210             mDisplayBuffer = new byte[displayLength];
            211             System.arraycopy(b, 0, mDisplayBuffer, 0, displayLength);
            212             b = null;
            213             System.gc();
            214             mCurrentOffset = 0;
            215             return;
            216         }
            217 
            218         int skipLength = offsetOfLastScreen - mDataLengthOfOneDoc;
            219         mRaf.openNewStream();
            220         mRaf.locate(skipLength);
            221         mCurrentOffset = skipLength;
            222         byte[] b = new byte[mDataLengthOfOneDoc];
            223         int readLength = mRaf.readBytes(b);
            224         mBeforeOfDoc = false;
            225         if (readLength < mDataLengthOfOneDoc) {
            226             mEndOfDoc = true;
            227         }
            228         if (readLength == -1 && mScreenData.length == 0) {// 意外到了文件流的末尾或者
            229             mTextView.setText("讀取文件失或者文件緩沖區失敗");
            230             return;
            231         }
            232 
            233         int nlocation = 0;
            234         while (nlocation < readLength) {
            235             if ((b[readLength - 1& 0xff== 10) {
            236                 nlocation = readLength;
            237                 break;
            238             }
            239             readLength--;
            240         }
            241         if (nlocation == 0) {
            242             System.exit(1);
            243         }
            244 
            245         mDisplayBuffer = new byte[readLength];
            246         System.arraycopy(b, 0, mDisplayBuffer, 0, readLength);
            247         b = null;
            248         System.gc();
            249     }
            250 
            251 
            http://topic.csdn.net/u/20111026/15/18c77efa-f41c-4315-8023-550a3732bd76.html?14299
               
            posted on 2011-12-15 22:13 life02 閱讀(196) 評論(0)  編輯 收藏 引用 所屬分類: Android開發
            亚洲精品无码久久久影院相关影片 | 奇米综合四色77777久久| 欧美丰满熟妇BBB久久久| 国内精品九九久久久精品| 99久久精品免费看国产免费| 亚洲乱码日产精品a级毛片久久| 久久久久亚洲av无码专区喷水 | 国产精品久久久久久影院 | 久久久久免费精品国产| 亚洲?V乱码久久精品蜜桃 | 久久久久99精品成人片欧美| 久久婷婷综合中文字幕| 国产69精品久久久久9999APGF| 99久久无色码中文字幕| 久久午夜无码鲁丝片| 日韩av无码久久精品免费| 亚洲精品国产综合久久一线| 九九精品99久久久香蕉| 综合久久一区二区三区 | 国产91久久精品一区二区| 日日狠狠久久偷偷色综合免费| 亚洲午夜久久久久久久久久| 久久久久一级精品亚洲国产成人综合AV区 | 国内精品久久久久久中文字幕| 国产精品乱码久久久久久软件 | 无码人妻久久一区二区三区| 国产精品一区二区久久精品无码| 久久久亚洲欧洲日产国码aⅴ| 久久亚洲精品国产亚洲老地址 | 亚洲精品久久久www| 大香网伊人久久综合网2020| 国产精品无码久久综合| 久久亚洲欧美国产精品| 久久亚洲私人国产精品vA| 久久亚洲精品国产精品| 狠狠色噜噜色狠狠狠综合久久| 久久99热这里只有精品66| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 国内精品久久久久久99蜜桃| 久久久久人妻精品一区| 精品久久久久久久久午夜福利 |