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

          主站蜘蛛池模板: 象州县| 安义县| 铅山县| 广灵县| 洛扎县| 庆云县| 波密县| 娄烦县| 延津县| 河池市| 鲁山县| 那坡县| 武城县| 缙云县| 通化市| 饶河县| 富裕县| 区。| 耒阳市| 舟山市| 荃湾区| 日照市| 南涧| 莲花县| 张北县| 青岛市| 恭城| 定南县| 庆阳市| 秦皇岛市| 库车县| 大安市| 苍梧县| 甘泉县| 怀来县| 买车| 武平县| 新蔡县| 射洪县| 德保县| 夹江县|