org.apache.http.message.ParserCursor#getPos ( )源码实例Demo

下面列出了org.apache.http.message.ParserCursor#getPos ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: lavaplayer   文件: ExtendedHttpClientBuilder.java
@Override
public ProtocolVersion parseProtocolVersion(CharArrayBuffer buffer, ParserCursor cursor) {
  int index = cursor.getPos();
  int bound = cursor.getUpperBound();

  if (bound >= index + 4 && "ICY ".equals(buffer.substring(index, index + 4))) {
    cursor.updatePos(index + 4);
    return ICY_PROTOCOL;
  }

  return super.parseProtocolVersion(buffer, cursor);
}
 
源代码2 项目: lavaplayer   文件: ExtendedHttpClientBuilder.java
@Override
public boolean hasProtocolVersion(CharArrayBuffer buffer, ParserCursor cursor) {
  int index = cursor.getPos();
  int bound = cursor.getUpperBound();

  if (bound >= index + 4 && "ICY ".equals(buffer.substring(index, index + 4))) {
    return true;
  }

  return super.hasProtocolVersion(buffer, cursor);
}
 
源代码3 项目: MediaPlayerProxy   文件: HttpUtils.java
@Override
public boolean hasProtocolVersion(CharArrayBuffer buffer, ParserCursor cursor) {
	boolean superFound = super.hasProtocolVersion(buffer, cursor);
	if (superFound) {
		return true;
	}
	int index = cursor.getPos();

	final int protolength = ICY_PROTOCOL_NAME.length();

	if (buffer.length() < protolength)
		return false; // not long enough for "HTTP/1.1"

	if (index < 0) {
		// end of line, no tolerance for trailing whitespace
		// this works only for single-digit major and minor version
		index = buffer.length() - protolength;
	} else if (index == 0) {
		// beginning of line, tolerate leading whitespace
		while ((index < buffer.length()) && HTTP.isWhitespace(buffer.charAt(index))) {
			index++;
		}
	} // else within line, don't tolerate whitespace

	return index + protolength <= buffer.length()
			&& buffer.substring(index, index + protolength).equals(ICY_PROTOCOL_NAME);

}
 
源代码4 项目: MediaPlayerProxy   文件: HttpUtils.java
@Override
public ProtocolVersion parseProtocolVersion(CharArrayBuffer buffer, ParserCursor cursor) throws ParseException {

	if (buffer == null) {
		throw new IllegalArgumentException("Char array buffer may not be null");
	}
	if (cursor == null) {
		throw new IllegalArgumentException("Parser cursor may not be null");
	}

	final int protolength = ICY_PROTOCOL_NAME.length();

	int indexFrom = cursor.getPos();
	int indexTo = cursor.getUpperBound();

	skipWhitespace(buffer, cursor);

	int i = cursor.getPos();

	// long enough for "HTTP/1.1"?
	if (i + protolength + 4 > indexTo) {
		throw new ParseException("Not a valid protocol version: " + buffer.substring(indexFrom, indexTo));
	}

	// check the protocol name and slash
	if (!buffer.substring(i, i + protolength).equals(ICY_PROTOCOL_NAME)) {
		return super.parseProtocolVersion(buffer, cursor);
	}

	cursor.updatePos(i + protolength);

	return createProtocolVersion(1, 0);
}
 
 同类方法