Moves the request line reader to end of the line, checking that no non-space
character are found.

@throws ProtocolException If more non-space tokens are found in this line,
or the end-of-file is reached.
162119
public void eol() throws ProtocolException {
        char next = nextChar();

        // Ignore trailing spaces.
        while (next == ' ') {
            consume();
            next = nextChar();
        }

        // handle DOS and unix end-of-lines
        if (next == '\r') {
            consume();
            next = nextChar();
        }

        // Check if we found extra characters.
        if (next != '\n') {
            throw new ProtocolException("Expected end-of-line, found more character(s): "+next);
        }
        dumpLine();
    }
1042657
private void endWithMessage(ServerHttpExchange http, ByteBuffer data) {
      endedWithMessage.set(true);
      http.setHeader("content-type", "application/octet-stream").end(data);
    }
891590
void endOffering(IOException exception) {
    if (closed) {
      return;
    }

    // closed should never be set by this method--only the polling side should do it, as it means
    // that the CLOSED marker has been encountered.

    if (this.exception == null) {
      this.exception = exception;
    }

    // Since this is an unbounded queue, offer() always succeeds.
    queue.offer(CLOSED);
  }
237477
final protected char next(final ByteBuffer buffer, boolean allow8859) throws BaseExceptions.BadMessage {

        if (!buffer.hasRemaining()) return HttpTokens.EMPTY_BUFF;

        if (_segmentByteLimit <= _segmentBytePosition) {
            shutdownParser();
            throw new BaseExceptions.BadMessage("Request length limit exceeded: " + _segmentByteLimit);
        }

        final byte b = buffer.get();
        _segmentBytePosition++;

        // If we ended on a CR, make sure we are
        if (_cr) {
            if (b != HttpTokens.LF) {
                throw new BadCharacter("Invalid sequence: LF didn't follow CR: " + b);
            }
            _cr = false;
            return (char)b;  // must be LF
        }

        // Make sure its a valid character
        if (b < HttpTokens.SPACE) {
            if (b == HttpTokens.CR) {   // Set the flag to check for _cr and just run again
                _cr = true;
                return next(buffer, allow8859);
            }
            else if (b == HttpTokens.TAB || allow8859 && b < 0) {
                return (char)(b & 0xff);
            }
            else if (b == HttpTokens.LF) {
                return (char)b; // A backend should accept a bare linefeed. http://tools.ietf.org/html/rfc2616#section-19.3
            }
            else if (isLenient()) {
                return HttpTokens.REPLACEMENT;
            }
            else {
                shutdownParser();
                throw new BadCharacter("Invalid char: '" + (char)(b & 0xff) + "', 0x" + Integer.toHexString(b));
            }
        }

        // valid ascii char
        return (char)b;
    }
905420
public void finish() throws IOException {
    writer.append("--" + boundary + "--").append(LINE_BREAK);
    writer.flush();
    writer.close();
    outputStream.flush();
    outputStream.close();
  }
1340518
public void endError() throws IOException {
        ResponseWriter writer = getWrapped();
        writer.endCDATA();
        writer.endElement("error-message");
        writer.endElement("error");
    }
551122
protected final int nextStringEndPos(byte[] bytes, int startPos, int limit, byte[] delimiter) {
		int endPos = startPos;

		final int delimLimit = limit - delimiter.length + 1;

		while (endPos < limit) {
			if (endPos < delimLimit && delimiterNext(bytes, endPos, delimiter)) {
				break;
			}
			endPos++;
		}

		if (endPos == startPos) {
			setErrorState(ParseErrorState.EMPTY_COLUMN);
			return -1;
		}
		return endPos;
	}
3221
protected void consumeChar(ImapRequestLineReader request, char expected)
            throws ProtocolException {
        char consumed = request.consume();
        if (consumed != expected) {
            throw new ProtocolException("Expected:'" + expected + "' found:'" + consumed + '\'');
        }
    }
174990
private void skipToEndOfLine() throws IOException {
    while (pos < limit || fillBuffer(1)) {
      char c = buffer[pos++];
      if (c == '\n') {
        lineNumber++;
        lineStart = pos;
        break;
      } else if (c == '\r') {
        break;
      }
    }
  }
60785
public boolean nextLine() throws IOException {
    while(reader.readLine(buf.delete(0, buf.length()))) {
      ++lineNumber;
      if(lengthWithoutLinefeed(buf) > 0) {
        return true;
      }
    }
    return false;
  }
840804
public void processStencilSet() throws IOException {
        StringBuilder stencilSetFileContents = new StringBuilder();

        Scanner scanner = null;
        try {
            scanner = new Scanner(new File(ssInFile),
                                  "UTF-8");
            String currentLine = "";
            String prevLine = "";
            while (scanner.hasNextLine()) {
                prevLine = currentLine;
                currentLine = scanner.nextLine();

                String trimmedPrevLine = prevLine.trim();
                String trimmedCurrentLine = currentLine.trim();

                // First time processing - replace view="<file>.svg" with _view_file="<file>.svg" + view="<svg_xml>"
                if (trimmedCurrentLine.matches(VIEW_PROPERTY_NAME_PATTERN) && trimmedCurrentLine.endsWith(VIEW_PROPERTY_VALUE_SUFFIX)) {
                    String newLines = processViewPropertySvgReference(currentLine);
                    stencilSetFileContents.append(newLines);
                }
                // Second time processing - replace view="<svg_xml>" with refreshed contents of file referenced by previous line
                else if (trimmedPrevLine.matches(VIEW_FILE_PROPERTY_NAME_PATTERN) && trimmedPrevLine.endsWith(VIEW_PROPERTY_VALUE_SUFFIX)
                        && trimmedCurrentLine.matches(VIEW_PROPERTY_NAME_PATTERN)) {
                    String newLines = processViewFilePropertySvgReference(prevLine,
                                                                          currentLine);
                    stencilSetFileContents.append(newLines);
                } else {
                    stencilSetFileContents.append(currentLine + LINE_SEPARATOR);
                }
            }
        } finally {
            if (scanner != null) {
                scanner.close();
            }
        }

        Writer out = null;
        try {
            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(ssOutFile),
                                                            "UTF-8"));
            out.write(stencilSetFileContents.toString());
        } catch (FileNotFoundException e) {

        } catch (UnsupportedEncodingException e) {
        } catch (IOException e) {
        } finally {
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                }
            }
        }

        System.out.println("SVG files referenced more than once:");
        for (Map.Entry<String, Integer> stringIntegerEntry : mapSVGCounts.entrySet()) {
            if (stringIntegerEntry.getValue() > 1) {
                System.out.println("\t" + stringIntegerEntry.getKey() + "\t = " + stringIntegerEntry.getValue());
            }
        }
    }
15101
public void moveToEnd() throws IOException {
    int bytes;
    while (remaining > 0) {
      bytes = (int) inner.skip(remaining);
      if (bytes < 0) {
        break;
      }
      remaining -= bytes;
    }
  }
567769
String readNonEscaped() throws IOException {
		StringBuilder s = new StringBuilder();
		do {
			int c = reader.read();
			if (c < 0) {
				return s.toString().trim();
			}
			if (c == SEPARATOR || c == '\n') {
				reader.unread(c);
				return s.toString().trim();
			} else {
				s.append((char) c);
			}
		} while (true);
	}
177927
private void go(Reader r) throws IOException {
        BufferedReader reader;
        if (r instanceof BufferedReader)
            reader = (BufferedReader)r;
        else
            reader = new BufferedReader(r);
        doc.startDocument();
        while(true) {
			// read a new character
			if (previousCharacter == -1) {
				character = reader.read();
			}
			// or re-examine the previous character
			else {
				character = previousCharacter;
				previousCharacter = -1;
			}
			
			// the end of the file was reached
			if (character == -1) {
				if (html) {
					if (html && state == TEXT)
						flush();
					doc.endDocument();
				} else {
					throwException("Missing end tag");
				}
				return;
			}
            
			// dealing with  \n and \r
			if (character == '\n' && eol) {
				eol = false;
				continue;
			} else if (eol) {
				eol = false;
			} else if (character == '\n') {
				lines++;
				columns = 0;
			} else if (character == '\r') {
				eol = true;
				character = '\n';
				lines++;
				columns = 0;
			} else {
				columns++;
			}
            
			switch(state) {
            // we are in an unknown state before there's actual content
			case UNKNOWN:
                if(character == '<') {
                    saveState(TEXT);
                    state = TAG_ENCOUNTERED;
                }
                break;
            // we can encounter any content
			case TEXT:
                if(character == '<') {
                    flush();
                    saveState(state);
                    state = TAG_ENCOUNTERED;
                } else if(character == '&') {
                    saveState(state);
                    entity.setLength(0);
                    state = ENTITY;
                    nowhite = true;
                } else if (Character.isWhitespace((char)character)) {
                	if (nowhite)
                		text.append((char)character);
                	nowhite = false;
                } else {
                    text.append((char)character);
                    nowhite = true;
                }
                break;
            // we have just seen a < and are wondering what we are looking at
            // <foo>, </foo>, <!-- ... --->, etc.
			case TAG_ENCOUNTERED:
                initTag();
                if(character == '/') {
                    state = IN_CLOSETAG;
                } else if (character == '?') {
                    restoreState();
                    state = PI;
                } else {
                    text.append((char)character);
                    state = EXAMIN_TAG;
                }
                break;
            // we are processing something like this <foo ... >.
            // It could still be a <!-- ... --> or something.
			case EXAMIN_TAG:
                if(character == '>') {
                    doTag();
                    processTag(true);
                    initTag();
                    state = restoreState();
                } else if(character == '/') {
                    state = SINGLE_TAG;
                } else if(character == '-' && text.toString().equals("!-")) {
                    flush();
                    state = COMMENT;
                } else if(character == '[' && text.toString().equals("![CDATA")) {
                    flush();
                    state = CDATA;
                } else if(character == 'E' && text.toString().equals("!DOCTYP")) {
                    flush();
                    state = PI;
                } else if(Character.isWhitespace((char)character)) {
                    doTag();
                    state = TAG_EXAMINED;
                } else {
                    text.append((char)character);
                }
                break;
            // we know the name of the tag now.
			case TAG_EXAMINED:
                if(character == '>') {
                    processTag(true);
                    initTag();
                    state = restoreState();
                } else if(character == '/') {
                    state = SINGLE_TAG;
                } else if(Character.isWhitespace((char)character)) {
                    // empty
                } else {
                    text.append((char)character);
                    state = ATTRIBUTE_KEY;
                }
                break;
                
                // we are processing a closing tag: e.g. </foo>
			case IN_CLOSETAG:
                if(character == '>') {
                    doTag();
                    processTag(false);
                    if(!html && nested==0) return;
                    state = restoreState();
                } else {
                    if (!Character.isWhitespace((char)character))
                        text.append((char)character);
                }
                break;
                
            // we have just seen something like this: <foo a="b"/
            // and are looking for the final >.
			case SINGLE_TAG:
                if(character != '>')
                    throwException("Expected > for tag: <"+tag+"/>");
				doTag();
                processTag(true);
                processTag(false);
                initTag();
                if(!html && nested==0) {
                    doc.endDocument();
                    return;
                }
                state = restoreState();
                break;
                
            // we are processing CDATA
			case CDATA:
                if(character == '>'
                && text.toString().endsWith("]]")) {
                    text.setLength(text.length()-2);
                    flush();
                    state = restoreState();
                } else
                    text.append((char)character);
                break;
                
            // we are processing a comment.  We are inside
            // the <!-- .... --> looking for the -->.
			case COMMENT:
                if(character == '>'
                && text.toString().endsWith("--")) {
                    text.setLength(text.length() - 2);
                    flush();
                    state = restoreState();
                } else
                    text.append((char)character);
                break;
                
            // We are inside one of these <? ... ?> or one of these <!DOCTYPE ... >
			case PI:
                if(character == '>') {
                    state = restoreState();
                    if(state == TEXT) state = UNKNOWN;
                }
                break;
                
            // we are processing an entity, e.g. &lt;, &#187;, etc.
			case ENTITY:
                if(character == ';') {
                    state = restoreState();
                    String cent = entity.toString();
                    entity.setLength(0);
                    char ce = EntitiesToUnicode.decodeEntity(cent);
                    if (ce == '\0')
                    	text.append('&').append(cent).append(';');
                    else
                    	text.append(ce);
                } else if ((character != '#' && (character < '0' || character > '9') && (character < 'a' || character > 'z')
                    && (character < 'A' || character > 'Z')) || entity.length() >= 7) {
                    state = restoreState();
                    previousCharacter = character;
                    text.append('&').append(entity.toString());
                    entity.setLength(0);
                }
                else {
                    entity.append((char)character);
                }
                break;
            // We are processing the quoted right-hand side of an element's attribute.
			case QUOTE:
                if (html && quoteCharacter == ' ' && character == '>') {
                    flush();
                    processTag(true);
                    initTag();
                    state = restoreState();
                }
                else if (html && quoteCharacter == ' ' && Character.isWhitespace((char)character)) {
                	flush();
                    state = TAG_EXAMINED;
                }
                else if (html && quoteCharacter == ' ') {
                    text.append((char)character);
                }
                else if(character == quoteCharacter) {
                	flush();
                    state = TAG_EXAMINED;
                } else if(" \r\n\u0009".indexOf(character)>=0) {
                    text.append(' ');
                } else if(character == '&') {
                    saveState(state);
                    state = ENTITY;
                    entity.setLength(0);
                } else {
                    text.append((char)character);
                }
                break;
                
			case ATTRIBUTE_KEY:
                if(Character.isWhitespace((char)character)) {
                    flush();
                    state = ATTRIBUTE_EQUAL;
                } else if(character == '=') {
                	flush();
                    state = ATTRIBUTE_VALUE;
                } else if (html && character == '>') {
                    text.setLength(0);
                    processTag(true);
                    initTag();
                    state = restoreState();
                } else {
                    text.append((char)character);
                }
                break;
                
			case ATTRIBUTE_EQUAL:
                if(character == '=') {
                    state = ATTRIBUTE_VALUE;
                } else if(Character.isWhitespace((char)character)) {
                    // empty
                } else if (html && character == '>') {
                    text.setLength(0);
                    processTag(true);
                    initTag();
                    state = restoreState();
                } else if (html && character == '/') {
                    flush();
                    state = SINGLE_TAG;
                } else if (html) {
                    flush();
                    text.append((char)character);
                    state = ATTRIBUTE_KEY;
                } else {
                    throwException("Error in attribute processing.");
                }
                break;
                
			case ATTRIBUTE_VALUE:
                if(character == '"' || character == '\'') {
                    quoteCharacter = character;
                    state = QUOTE;
                } else if(Character.isWhitespace((char)character)) {
                    // empty
                } else if (html && character == '>') {
                    flush();
                    processTag(true);
                    initTag();
                    state = restoreState();
                } else if (html) {
                    text.append((char)character);
                    quoteCharacter = ' ';
                    state = QUOTE;
                } else {
                    throwException("Error in attribute processing");
                }
                break;
            }
        }
    }
955808
private void skipEmptyLines() {
		int tmp = index;
		do {
			tmp = skipLineSpace(tmp);
			if (tmp < tokens.size() && tokens.get(tmp).kind != Token.Kind.NewLine) {
				return; // done
			} else if (tmp >= tokens.size()) {
				index = tmp;
				return; // end-of-file reached
			}
			// otherwise, skip newline and continue
			tmp = tmp + 1;
			index = tmp;
		} while (true);
		// deadcode
	}
65994
private String getNextLine(BufferedReader reader) throws Exception {
        String line = reader.readLine();
        if (line != null) {
            return line;
        } else {
            throw new Exception("Error parsing server status file (unexpectedly ended): "
                    + _file.getPath());
        }
    }
438006
@Override
    public void close() throws IOException {
        // Skip over the remaining bytes. Do not close the underlying InputStream.
        if (this.remaining > 0) {
            int toSkip = this.remaining;
            long skipped = skip(toSkip);
            if (skipped != toSkip) {
                throw new SerializationException(String.format("Read %d fewer byte(s) than expected only able to skip %d.", toSkip, skipped));
            }
        } else if (this.remaining < 0) {
            throw new SerializationException(String.format("Read more bytes than expected (%d).", -this.remaining));
        }
    }