Package org.openiaml.iacleaner.inline

Examples of org.openiaml.iacleaner.inline.InlineStringReader


             * Remove the "standalone='no'" declaration in generated documents.
             */
            InputStream indent2 = new InputStream() {
             
              // convert into a read-ahead reader
              private InlineStringReader internal = new InlineStringReader(new InputStreamReader(indent)) {

          @Override
          protected void throwWarning(String message, String buffer) {
            // throw exception
            throw new RuntimeException(message);
          }
               
              };

              // ignore key
              private final String IGNORE = " standalone=\"no\"?>";
             
        @Override
        public int read() throws IOException {
          if (IGNORE.equals(internal.readAhead(IGNORE.length()))) {
            // ignore everything except the last two characters
            internal.read(IGNORE.length() - 2);
          }

          // return the next character
          return internal.read();
        }
             
            };
            output.create(indent2, true, monitor);
           
View Full Code Here


  public static class IndentedStream extends InputStream {

    private InlineStringReader internal = null;
   
    public IndentedStream(InputStream i) {
      this.internal = new InlineStringReader(new InputStreamReader(i)) {

        @Override
        protected void throwWarning(String message, String buffer) {
          throw new RuntimeException(message);
        }
View Full Code Here

   *
   * @param readFile
   * @return
   */
  public String cleanNuSMV(String input) throws IOException {
    InlineStringReader reader = new InlineStringReader(new StringReader(input)) {

      @Override
      protected void throwWarning(String message, String buffer) {
        throw new RuntimeException("Warning message: " + message);
      }
     
    };
    InlineStringWriter writer = new InlineStringWriter() {

      @Override
      protected void throwWarning(String message, String buffer) {
        throw new RuntimeException("Warning message: " + message);
      }
     
    };
   
    int c;
    int prev = -1;
    boolean inLTL = false;
    while ((c = reader.read()) != -1) {
      // skip \rs
      if (c == '\r') continue;
     
      if (Character.isWhitespace(c) /* && Character.isWhitespace(prev) */) {
        // skip
      } else if (c == '-' && reader.readAhead() == '-') {
        if (prev != -1 && !Character.isWhitespace(writer.previous())) {
          // we need to add whitespace before this comment
          writer.write(' ');
        }
       
        // a comment
        writer.write('-');
        writer.enableWordwrap(false)// disable wordwrap for comment
        while ((c = reader.read()) != -1) {
          if (c == '\r')
            continue;

          // copy comment directly
          writer.write(c);
         
          if (c == '\n')
            break;
        }
        writer.enableWordwrap(true)// re-enable wordwrap for comment
      } else if (c == 'p' && !Character.isJavaIdentifierPart(prev) && reader.has(7) && reader.readAhead(6).equals("rocess") && !Character.isJavaIdentifierPart(reader.readAhead(7).charAt(6))) {
        // 'process' keyword
        writer.write(c);
        writer.write(reader.read(6));
        writer.write(' ');
        prev = ' ';
      } else if (c == 'M' && reader.has(6) && reader.readAhead(5).equals("ODULE")) {
        // multiple modules will reduce the indent, since MODULE
        // does not have an ending statement
        if (writer.getIndentSize() != 0)
          writer.indentDecrease();
       
        // MODULE
        writer.newLine();
        writer.write(c);
        writer.write(reader.read(5));
        writer.write(' ');
      } else if (c == 'V' && reader.has(3) && reader.readAhead(2).equals("AR")) {
        // VAR
        writer.newLine();
        writer.newLine();
        writer.write(c);
        writer.write(reader.read(2));
        writer.newLine();
       
        // indent
        writer.indentIncrease();
        c = ' ';
      } else if (c == 'A' && reader.has(6) && reader.readAhead(5).equals("SSIGN")) {
        // unindent
        writer.indentDecrease();
       
        // ASSIGN
        writer.newLine();
        writer.write(c);
        writer.write(reader.read(5));
        writer.newLine();
       
        // indent
        writer.indentIncrease();
        c = ' ';
      } else if (c == 'F' && reader.has(8) && reader.readAhead(7).equals("AIRNESS")) {
        // unindent
        writer.indentDecrease();
       
        // ASSIGN
        writer.newLine();
        writer.write(c);
        writer.write(reader.read(7));
        writer.newLine();
       
        // indent
        writer.indentIncrease();
        c = ' ';
      } else if (c == 'L' && reader.has(7) && reader.readAhead(6).equals("TLSPEC")) {
        // unindent
        writer.indentDecrease();

        // LTLSPEC
        writer.newLine();
        writer.write(c);
        writer.write(reader.read(6));
        writer.newLine();
       
        // indent
        writer.indentIncrease();
        c = ' ';
       
        inLTL = true// now in LTL space
      } else if (c == 'c' && reader.has(4) && reader.readAhead(3).equals("ase") && Character.isWhitespace(reader.readAhead(4).charAt(3))) {
        // starting a case statement
        writer.write(c);
        writer.write(reader.read(3));
        writer.newLine();
       
        // indent
        writer.indentIncrease();
        c = ' ';
       
      } else if (c == 'e' &&  reader.has(4) && reader.readAhead(3).equals("sac") &&
          (Character.isWhitespace(reader.readAhead(4).charAt(3)) || reader.readAhead(4).charAt(3) == ';')) {
        // no newline, but decrease indent before writing 'esac;'
        writer.indentDecrease();

        // ending a case statement
        writer.write(c);
        writer.write(reader.read(3));
       
        c = 'c';
       
      } else if (needsWhitespaceBefore(c, reader, writer, inLTL) && !Character.isWhitespace(writer.previous())) {
        // insert whitespace
View Full Code Here

TOP

Related Classes of org.openiaml.iacleaner.inline.InlineStringReader

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.