Пример #1
0
 /**
  * ensure that have number char available and not allready read
  *
  * @param number ?
  * @throws IOException
  */
 private void fill(int number) throws IOException {
   int needed = nextChar + number - buffer.size();
   if (needed > 0) {
     char[] cbuf = new char[needed + READ_AHEAD];
     int read = in.read(cbuf);
     for (int i = 0; i < read; i++) {
       buffer.add(cbuf[i]);
     }
   }
 }
Пример #2
0
  /**
   * remove number of char in buffer
   *
   * @param number
   * @return the real number of char removed from the head of buffer
   * @throws IOException
   */
  private int free(int number) throws IOException {
    // fill(number);
    int result = Math.min(buffer.size(), number);
    buffer.subList(0, result).clear();

    nextChar -= result;
    markChar -= result;

    return result;
  }
Пример #3
0
 /**
  * read one char in buffer
  *
  * @return the next car
  * @throws IOException pour tout pb de lecture
  */
 public int read() throws IOException {
   fill(1);
   int result = -1;
   if (nextChar < buffer.size()) {
     result = buffer.get(nextChar++);
     charNumber++;
     if (result == '\n') {
       lineNumber++;
     }
   }
   return result;
 }
Пример #4
0
  /**
   * go left in reading char buffer
   *
   * @param number
   * @return realy unread char number
   */
  public int unread(int number) {
    int result = Math.min(number, nextChar);
    nextChar -= result;

    charNumber -= result;
    for (int i = nextChar; i < nextChar + result; i++) {
      if (buffer.get(i) == '\n') {
        lineNumber--;
      }
    }

    return result;
  }