1 17 18 package com.finalist.jag.template.parser; 19 20 import java.io.*; 21 22 23 30 public class CharBuffer extends InputBuffer { 31 32 34 35 private Reader input = null; 36 37 38 private String inputString = null; 39 40 41 private int stringIndex = 0; 42 43 44 private int stringLength = 0; 45 46 47 52 public CharBuffer(Reader input) { 53 super(); 54 this.input = input; 55 } 56 57 58 63 public CharBuffer(String input) { 64 super(); 65 this.inputString = input; 66 this.stringLength = input.length(); 67 } 68 69 70 77 public void fill(int amount) throws CharStreamException { 78 try { 79 syncConsume(); 80 while (queue.nbrEntries < amount + markerOffset) { 82 queue.append(read()); 83 } 84 } 85 catch (IOException io) { 86 throw new CharStreamIOException(io); 87 } 88 } 89 90 91 100 private char read() throws IOException { 101 if (input != null) { 102 return (char) input.read(); 103 } 104 105 if ((inputString != null) && (stringIndex < stringLength)) { 106 return (char) inputString.charAt(stringIndex++); 107 } 108 return (char) -1; 109 } 110 } | Popular Tags |