Esempio n. 1
0
 public static void main(String[] args) {
   StringReader r = new StringReader("    --1234,");
   ShortTermMemoryReader reader = new ShortTermMemoryReader(r);
   IntegerReadService service = new IntegerReadService();
   try {
     Integer i = service.read(reader);
     System.out.println(i);
   } catch (Exception e) {
     System.out.println(((RowColumnReaderException) e).getColumn());
     e.printStackTrace();
   }
 }
Esempio n. 2
0
  public Double read(ShortTermMemoryReader reader) throws RowColumnReaderException {
    try {
      IntegerReadService.removeSpaces(reader);
      char c = (char) reader.read();
      if (Character.isDigit(c) || c == '-' || c == '+') {
        StringBuilder sb = new StringBuilder();
        sb.append(c);
        IntegerReadService.readDigitStar(reader, sb);
        c = (char) reader.read();
        if (c == '.') {
          sb.append(c);
          IntegerReadService.readDigitStar(reader, sb);
          c = (char) reader.read();
        }

        if (c == 'e' || c == 'E') {
          sb.append(c);
          c = (char) reader.read();
          if (c == '-' || c == '+') {
            sb.append(c);
          } else {
            IntegerReadService.back(c, reader);
          }
          IntegerReadService.readDigitStar(reader, sb);
        } else {
          IntegerReadService.back(c, reader);
        }
        return Double.parseDouble(sb.toString());
      }
      throw new Exception("Unexpected symbol " + c);
    } catch (Exception e) {
      throw reader.getException("Double Parser Error " + e.getMessage());
    }
  }