/** * @param pos the position to check * @return true if the character at position 'pos' is a valid URL character */ private boolean isValidURLChar(int pos) { byte b = buffer.get(pos); char ch = (char) b; // Valid URL characters as defined here: http://tools.ietf.org/html/rfc3986#section-2 return Character.isDigit(ch) || Character.isLetter(ch) || ch == '-' || ch == '.' || ch == '_' || ch == '~' || ch == ':' || ch == '/' || ch == '?' || ch == '#' || ch == '[' || ch == ']' || ch == '@' || ch == '!' || ch == '$' || ch == '&' || ch == '\'' || ch == '(' || ch == ')' || ch == '*' || ch == '+' || ch == ',' || ch == ';' || ch == '='; }
/** * Returns true if the index points to an XML preamble of the following example form: * * <pre> * <?xml version="1.0"?> * </pre> * @param index */ private boolean isPreamble(int index) { if (index <= buffer.length() - 6) { if ( buffer.get(index) == '<' && buffer.get(index + 1) == '?' && buffer.get(index + 2) == 'x' && buffer.get(index + 3) == 'm' && buffer.get(index + 4) == 'l' && buffer.get(index + 5) == ' ' ) { return true; } } return false; }
/** * Returns true if the index points to an XML preamble of the following example form: * * <pre> * <?xml version="1.0"?> * </pre> * @param index */ private boolean isPreamble(int index) { if (index <= buffer.length() - 6) { if ( buffer.get(index) == '<' && buffer.get(index + 1) == '?' && buffer.get(index + 2) == 'x' && buffer.get(index + 3) == 'm' && buffer.get(index + 4) == 'l' && buffer.get(index + 5) == ' ' ) { return true; } } return false; }
/** * Search for the given character in the buffer, starting at the * given index. If not found, return -1. If found, return the * index of the character. * @param c * @param index */ private int findFrom(char c, int index) { int currentIdx = index; while (currentIdx < buffer.length()) { if (buffer.get(currentIdx) == c) { return currentIdx; } currentIdx++; } return -1; }
/** * Search for the given character in the buffer, starting at the * given index. If not found, return -1. If found, return the * index of the character. * @param c * @param index */ private int findFrom(char c, int index) { int currentIdx = index; while (currentIdx < buffer.length()) { if (buffer.get(currentIdx) == c) { return currentIdx; } currentIdx++; } return -1; }
isStart &= buffer.get(pos) == (byte) 't' || buffer.get(pos) == (byte) 'T'; isStart &= buffer.get(pos) == (byte) 't' || buffer.get(pos) == (byte) 'T'; isStart &= buffer.get(pos) == (byte) 'p' || buffer.get(pos) == (byte) 'P'; boolean isSecure = buffer.get(pos) == (byte) 's' || buffer.get(pos) == (byte) 'S'; if (isSecure) { pos++; isStart &= buffer.get(pos) == (byte) ':'; isStart &= buffer.get(pos) == (byte) '/'; isStart &= buffer.get(pos) == (byte) '/';
byte currentByte = buffer.get(currentIdx); if (currentByte == (byte) '<') { if (xmlPreamble.startIdx == -1 && isPreamble(currentIdx)) {
byte currentByte = buffer.get(currentIdx); if (currentByte == (byte) '<') { if (xmlPreamble.startIdx == -1 && isPreamble(currentIdx)) {