Chan Chen Coding...

          Buffer

          class BinaryFileBuffer {
              public static int BUFFERSIZE = 2048;
              public BufferedReader fbr;
              public File originalfile;
              private String cache;
              private boolean empty;

              public BinaryFileBuffer(File f, Charset cs) throws IOException {
                  originalfile = f;
                  fbr = new BufferedReader(new InputStreamReader(new FileInputStream(f), cs), BUFFERSIZE);
                  reload();
              }

              public boolean empty() {
                  return empty;
              }

              private void reload() throws IOException {
                  try {
                      if ((this.cache = fbr.readLine()) == null) {
                          empty = true;
                          cache = null;
                      } else {
                          empty = false;
                      }
                  } catch (EOFException oef) {
                      empty = true;
                      cache = null;
                  }
              }

              public void close() throws IOException {
                  fbr.close();
              }

              public String peek() {
                  if (empty())
                      return null;
                  return cache.toString();
              }

              public String pop() throws IOException {
                  String answer = peek();
                  reload();
                  return answer;
              }

          }


          -----------------------------------------------------
          Silence, the way to avoid many problems;
          Smile, the way to solve many problems;

          posted on 2012-07-04 06:17 Chan Chen 閱讀(312) 評論(0)  編輯  收藏 所屬分類: Algorithm

          主站蜘蛛池模板: 桃园市| 祁阳县| 酒泉市| 抚顺县| 浑源县| 两当县| 陆河县| 荥经县| 黄龙县| 乐清市| 闸北区| 新郑市| 金堂县| 合江县| 阳春市| 开化县| 宁德市| 呼和浩特市| 泌阳县| 沾化县| 石家庄市| 明溪县| 合水县| 汶上县| 临潭县| 南平市| 永靖县| 扶余县| 资阳市| 含山县| 荔浦县| 宜兰市| 桐城市| 乐至县| 元朗区| 四子王旗| 南乐县| 古蔺县| 浠水县| 垦利县| 邵东县|