Package anvil.java.io

Examples of anvil.java.io.GenericInputStream


  private Token readPattern(int ch) throws IOException
  {
    _allowPattern = false;
    Token token = createToken(PATTERN);
    GenericInputStream input = _input;
    StringBuffer image = _image;
    boolean escaped = false;
    boolean brackets = false;
    boolean finished = false;
    int line = input.getLineNumber();
    int column = input.getColumnNumber();

    image.setLength(0);
    image.append('/');
   
    finished:
    for(;;) {
      if (finished) {
        if (ch == -1) {
          column--;
          break finished;
        } else if (Character.isJavaIdentifierPart((char)ch)) {
          _image.append((char)ch);
        } else {
          backup(ch, line, column);
          column--;
          break finished;
        }
      } else {
        switch(ch) {
        case -1:
          _parser.error(_parser.toLocation(line, column),
            "Unexpected end of pattern");
          break finished;

        case '\\':
          escaped = !escaped;
          image.append('\\');
          break;

        case '[':
          if (!escaped) {
            brackets = true;
          }
          escaped = false;
          image.append('[');
          break;

        case ']':
          if (!escaped) {
            brackets = false;
          }
          escaped = false;
          image.append(']');
          break;

        case '/':
          if (!escaped && !brackets) {
            finished = true;
          }
          escaped = false;
          image.append('/');
          break;

        /*case '\n':
        case '\r':
          _parser.error(_parser.toLocation(line, column),
            "Pattern cannot span over lines");
          break finished;*/

        default:
          image.append((char)ch);
          escaped = false;

        }
      }
      line = input.getLineNumber();
      column = input.getColumnNumber();     
      ch = input.read();

    }

    token.image = image.toString();
    token.endLine = line;
View Full Code Here


  }


  public Token operator(int ch) throws IOException
  {
    GenericInputStream input = _input;
    switch(ch) {
    case '!':
      ch = input.read();
      if (ch == '=') {
        ch = input.read();
        if (ch == '=') {
          return createToken(EXACT_NOT_EQUAL, "!==");
        } else {
          _backup = ch;
          return createToken(NOT_EQUAL, "!=");
        }
      } else if (ch == '~') {
        return createToken(NO_MATCH, "!~");
      } else {
        _backup = ch;
        return createToken(NEGATION, "!");
      }
   
    case '%':
      ch = input.read();
      if (ch == '=') {
        return createToken(ASSIGN_REMAINDER, "%=");
      } else {
        _backup = ch;
        return createToken(REMAINDER, "%");
      }
   
    case '&':
      ch = input.read();
      if (ch == '&') {
        return createToken(BOOLEAN_AND, "&&");
      } else if (ch == '=') {
        return createToken(ASSIGN_CONCAT, "&=");
      } else {
        _backup = ch;
        return createToken(ET, "&");
      }
     
    case '*':
      ch = input.read();
      if (ch == '=') {
        return createToken(ASSIGN_MULTIPLY, "*=");
      } else {
        _backup = ch;
        return createToken(STAR, "*");
      }

    case '?':
      ch = input.read();
      if (ch == '?') {
        return createToken(HOOKHOOK, "??");
      } else if (ch == '=') {
        return createToken(ASSIGN_INIT, "=?");
      } else {
        _backup = ch;
        return createToken(HOOK, "?");
      }
 
     case '+':
      ch = input.read();
      if (ch == '+') {
        return createToken(PLUSPLUS, "++");
      } else if (ch == '=') {
        return createToken(ASSIGN_ADD, "+=");
      } else {
        _backup = ch;
        return createToken(PLUS, "+");
      }

     case '-':
      ch = input.read();
      if (ch == '-') {
        return createToken(MINUSMINUS, "--");
      } else if (ch == '=') {
        return createToken(ASSIGN_SUBSTRACT, "-=");
      } else if (ch == '>') {
        return createToken(ARROW, "->");
      } else {
        _backup = ch;
        return createToken(MINUS, "-");
      }
       
    case '.':
      ch = input.read();
      if (ch == '.') {
        return createToken(RANGE, "..");
      } else {
        _backup = ch;
        return createToken(DOT, ".");
      }
     
    case '/':
      ch = input.read();
      if (ch == '*') {
        return skipToEndOfComment();
      } else if (ch == '/') {
        return skipToEndOfLineComment("//");
      } else if (ch == '=') {
        return createToken(ASSIGN_DIVIDE, "/=");
      } else {
        if (_allowPattern) {
          return readPattern(ch);
        } else {
          _backup = ch;
          return createToken(SLASH, "/");
        }
      }

    case '<':
      ch = input.read();
      if (ch == '=') {
        ch = input.read();
        if (ch == '>') {
          return createToken(COMPARE, "<=>");
        } else if (ch == '=') {
          ch = input.read();
          if (ch == '>') {
            return createToken(EXACT_COMPARE, "<==>");
          }
          _backup = ch;
        } else {
          _backup = ch;
          return createToken(LESS_OR_EQUAL, "<=");
        }
      } else {
        _backup = ch;
        return createToken(LESS, "<");
      }
         
    case '=':
      ch = input.read();
      if (ch == '=') {
        ch = input.read();
        if (ch == '=') {
          return createToken(EXACT_EQUAL, "===");
        } else {
          _backup = ch;
          return createToken(EQUAL, "==");
        }
      } else if (ch == '>') {
        return createToken(MAP, "=>");
      } else {
        _backup = ch;
        return createToken(ASSIGN, "=");
      }

    case '>':
      ch = input.read();
      if (ch == '=') {
        return createToken(GREATER_OR_EQUAL, ">=");
      } else {
        _backup = ch;
        return createToken(GREATER, ">");
      }
     
    case '^':
      ch = input.read();
      if (ch == '^') {
        return createToken(BOOLEAN_XOR, "^^");
      } else {
        _backup = ch;
        return createToken(CARET, "^");
        /*_parser.error(_parser.toLocation(_beginLine, _beginColumn),
          "Invalid operator ^, ^^ assumed");
        _beginColumn++;
        return createToken(BOOLEAN_XOR, "^");*/
      }

    case '|':
      ch = input.read();
      if (ch == '|') {
        return createToken(BOOLEAN_OR, "||");
      } else {
        _backup = ch;
        return createToken(PIPE, "|");
View Full Code Here

  }
 

  public Token readWhitespace(int ch) throws IOException
  {
    GenericInputStream input = _input;
    StringBuffer image = _image;
    int line, column;
    image.setLength(0);
    image.append((char)ch);
    out: for(;;) {
      line = input.getLineNumber();
      column = input.getColumnNumber();
      ch = input.read();
      switch(ch) {
      case -1:
        break out;
      case ' ':
      case '\t':
View Full Code Here

 
 
  public Token doGetNextToken()
  {
    boolean returnIgnorable = _returnIgnorable;
    GenericInputStream input = _input;
    Token t;
    int ch;

    try {

      readMore:
      for(;;) {
        if (_backup != -1) {
          ch = _backup;
          _backup = -1;
        } else {
          _beginLine = input.getLineNumber();
          _beginColumn = input.getColumnNumber();
          ch = input.read();
        }

        switch(ch) {
        case -1:
          return eof();
         
        case ' ':
        case '\t':
        case '\r':
        case '\n':
        case 0xa0:
          if (returnIgnorable) {
            return readWhitespace(ch);
          } else {
            continue readMore;
          }
         
        case '#':
          t = skipToEndOfLineComment("#");
          if (t != null) {
            return t;
          } else {
            continue readMore;
          }
         
        case '\"':
          return readString('\"');

        case '\'':
          return readString('\'');
         
        case '`':
          return readString('`');

        case ';':
          return createToken(SEMICOLON, ";");

        case '{':
          return createToken(BEGIN, "{");

        case '}':
          return createTokenNP(END, "}");

        case '(':
          return createToken(OPEN, "(");

        case ')':
          return createTokenNP(CLOSE, ")");

        case '[':
          return createToken(OPEN_BRACKET, "[");

        case ']':
          return createTokenNP(CLOSE_BRACKET, "]");

        case ':':
          return createToken(COLON, ":");

        case '@':
          return createToken(AT, "@");

        case ',':
          return createToken(COMMA, ",");

        case '~':
          return createToken(MATCH, "~");
         
        case '.':
        case '!':
        case '=':
        case '<':
        case '>':
        case '+':
        case '-':
        case '*':
        case '%':
        case '|':
        case '&':
        case '^':
        case '/':
        case '?':
          t = operator(ch);
          if (t == null) {
            continue readMore;
          } else {
            if ((_backup != -1) && (t.kind != PATTERN) && (t.kind != COMMENT)) {
              _beginColumn += t.image.length();
            }
            return t;
          }
        
        case '\\':
          ch = input.read();
          if (ch == '{') {
            return createToken(BEGIN_LIST, "\\{");
           
          } else if (Character.isJavaIdentifierStart((char)ch)) {
            Token token = readSymbol(ch);
            token.kind = STRING_LITERAL;
            token.image = '"' + token.image + '"';
            return token;
          } else {
            _backup = ch;
            _parser.error(_parser.toLocation(_beginLine, _beginColumn),
              "Invalid use of '\\'");
          }
          break;
       
        case '0': case '1': case '2': case '3': case '4':
        case '5': case '6': case '7': case '8': case '9':
          return readNumber((char)ch);
         
        case '$':
          return readSymbol(0);

        default:
          if (Character.isJavaIdentifierStart((char)ch)) {
            return readSymbol((char)ch);
          } else {
            _parser.error(_parser.toLocation(_beginLine, _beginColumn),
              "Invalid character '"+(char)ch+"' (0x"+Integer.toString(ch, 16)+") on input ");
          }
        }
       
      }
     
    } catch (IOException e) {
      _parser.error(_parser.toLocation(input.getLineNumber(),
        input.getColumnNumber()), "IO-error: " + e.getMessage());
      return eof();
    }
   
  }
View Full Code Here

        }    
        return files.keysAndElements();
       
      } else {
        return new InputStreamEnumeration(
          new GenericInputStream(new FileInputStream(_file)));
         
      }
     
    } catch (IOException e) {
      return BindingEnumeration.EMPTY;
View Full Code Here

  public ConfigReader(ServerControl serverControl, File source) throws IOException
  {
    _serverControl = serverControl;
    _source = source;
    _input = new GenericInputStream(new FileInputStream(source));
  }
View Full Code Here

    if (_input != null) {
      return;
    }
    try {
      _socket = new Socket(_address, _port);
      _input = new GenericInputStream(_socket.getInputStream());
      _output = new PrintStream(new BufferedOutputStream(_socket.getOutputStream()));
    } catch (IOException e) {
      closeConnection();
      throw new RuntimeException("Couldn't establish connection to remote session container: "+e);
    }
View Full Code Here

      }
    }
   
    _context = new Context(_zone);
    InetAddress address = socket.getInetAddress();
    GenericInputStream input = null;
    PrintStream output = null;
    String hostname = address.getHostName();
    _log.info("Connection from "+hostname);
   
    try {
     
      boolean firstrequest = true;
      socket.setSoTimeout(0);
      input = new GenericInputStream(socket.getInputStream());
      output = new PrintStream(new BufferedOutputStream(socket.getOutputStream()));
      handleRequest(input, output);
     
    } catch (InterruptedIOException e) {
      _log.debug("Connection from "+address.getHostName()+" timed out.");

    } catch (SocketException e) {
      _log.error("Connection from "+address.getHostName()+": "+e.getMessage());
     
    } catch (IOException e) {
      _log.error("Connection from "+address.getHostName(), e);

    } catch (Throwable t) {
      _log.error("Connection from "+address.getHostName(), t);
     
    } finally {
      if (input != null) {
        try {
          input.close();
        } catch (Throwable t) {
        }
      }
      if (output != null) {
        try {
View Full Code Here

TOP

Related Classes of anvil.java.io.GenericInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.