org.apache.http.ParseException类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(11.9k)|赞(0)|评价(0)|浏览(706)

本文整理了Java中org.apache.http.ParseException类的一些代码示例,展示了ParseException类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ParseException类的具体详情如下:
包路径:org.apache.http.ParseException
类名称:ParseException

ParseException介绍

[英]Indicates a parse error. Parse errors when receiving a message will typically trigger ProtocolException. Parse errors that do not occur during protocol execution may be handled differently. This is an unchecked exceptions, since there are cases where the data to be parsed has been generated and is therefore known to be parseable.
[中]指示分析错误。接收消息时的分析错误通常会触发ProtocolException。协议执行期间未发生的解析错误可能会以不同的方式处理。这是一个未经检查的例外,因为在某些情况下,要分析的数据已经生成,因此已知是可分析的。

代码示例

代码示例来源:origin: robovm/robovm

for (;;) {
  if (current == null) {
    current = new CharArrayBuffer(64);
  } else {
    current.clear();
  if (l == -1 || current.length() < 1) {
    break;
    headers[i] = parser.parseHeader(buffer);
  } catch (ParseException ex) {
    throw new ProtocolException(ex.getMessage());

代码示例来源:origin: robovm/robovm

final int protolength  = protoname.length();
  throw new ParseException
    ("Not a valid protocol version: " +
     buffer.substring(indexFrom, indexTo));
  throw new ParseException
    ("Not a valid protocol version: " +
     buffer.substring(indexFrom, indexTo));
int period = buffer.indexOf('.', i, indexTo);
if (period == -1) {
  throw new ParseException
    ("Invalid protocol version number: " + 
     buffer.substring(indexFrom, indexTo));
  major = Integer.parseInt(buffer.substringTrimmed(i, period)); 
} catch (NumberFormatException e) {
  throw new ParseException
    ("Invalid protocol major version number: " + 
     buffer.substring(indexFrom, indexTo));
  minor = Integer.parseInt(buffer.substringTrimmed(i, blank)); 
} catch (NumberFormatException e) {
  throw new ParseException(
    "Invalid protocol minor version number: " + 
    buffer.substring(indexFrom, indexTo));

代码示例来源:origin: robovm/robovm

int indexFrom = cursor.getPos();
int indexTo = cursor.getUpperBound();
  int blank = buffer.indexOf(' ', i, indexTo);
  if (blank < 0) {
    throw new ParseException("Invalid request line: " + 
        buffer.substring(indexFrom, indexTo));
  blank = buffer.indexOf(' ', i, indexTo);
  if (blank < 0) {
    throw new ParseException("Invalid request line: " + 
        buffer.substring(indexFrom, indexTo));
  cursor.updatePos(blank);
  ProtocolVersion ver = parseProtocolVersion(buffer, cursor);
  skipWhitespace(buffer, cursor);
  if (!cursor.atEnd()) {
    throw new ParseException("Invalid request line: " + 
        buffer.substring(indexFrom, indexTo));
  return createRequestLine(method, uri, ver);
} catch (IndexOutOfBoundsException e) {
  throw new ParseException("Invalid request line: " + 
               buffer.substring(indexFrom, indexTo));

代码示例来源:origin: robovm/robovm

int indexFrom = cursor.getPos();
int indexTo = cursor.getUpperBound();
  ProtocolVersion ver = parseProtocolVersion(buffer, cursor);
  skipWhitespace(buffer, cursor);
  int i = cursor.getPos();
  int blank = buffer.indexOf(' ', i, indexTo);
  if (blank < 0) {
    blank = indexTo;
  try {
    statusCode =
      Integer.parseInt(buffer.substringTrimmed(i, blank));
  } catch (NumberFormatException e) {
    throw new ParseException(
      "Unable to parse status code from status line: " 
      + buffer.substring(indexFrom, indexTo));
    reasonPhrase = "";
  return createStatusLine(ver, statusCode, reasonPhrase);
  throw new ParseException("Invalid status line: " + 
               buffer.substring(indexFrom, indexTo));

代码示例来源:origin: org.apache.httpcomponents/httpclient-android

/**
 * Parses textual representation of <code>Content-Type</code> value.
 *
 * @param s text
 * @return content type
 * @throws ParseException if the given text does not represent a valid
 * <code>Content-Type</code> value.
 * @throws UnsupportedCharsetException Thrown when the named charset is not available in
 * this instance of the Java virtual machine
 */
public static ContentType parse(
    final String s) throws ParseException, UnsupportedCharsetException {
  Args.notNull(s, "Content type");
  final CharArrayBuffer buf = new CharArrayBuffer(s.length());
  buf.append(s);
  final ParserCursor cursor = new ParserCursor(0, s.length());
  final HeaderElement[] elements = BasicHeaderValueParserHC4.INSTANCE.parseElements(buf, cursor);
  if (elements.length > 0) {
    return create(elements[0]);
  } else {
    throw new ParseException("Invalid content type: " + s);
  }
}

代码示例来源:origin: robovm/robovm

/**
 * Creates a new header from a buffer.
 * The name of the header will be parsed immediately,
 * the value only if it is accessed.
 *
 * @param buffer    the buffer containing the header to represent
 *
 * @throws ParseException   in case of a parse error
 */
public BufferedHeader(final CharArrayBuffer buffer)
  throws ParseException {
  super();
  if (buffer == null) {
    throw new IllegalArgumentException
      ("Char array buffer may not be null");
  }
  int colon = buffer.indexOf(':');
  if (colon == -1) {
    throw new ParseException
      ("Invalid header: " + buffer.toString());
  }
  String s = buffer.substringTrimmed(0, colon);
  if (s.length() == 0) {
    throw new ParseException
      ("Invalid header: " + buffer.toString());
  }
  this.buffer = buffer;
  this.name = s;
  this.valuePos = colon + 1;
}

代码示例来源:origin: org.apache.httpcomponents/httpclient-android

public StatusLine parseStatusLine(final CharArrayBuffer buffer,
                 final ParserCursor cursor) throws ParseException {
  Args.notNull(buffer, "Char array buffer");
  Args.notNull(cursor, "Parser cursor");
  final int indexFrom = cursor.getPos();
  final int indexTo = cursor.getUpperBound();
    int i = cursor.getPos();
    int blank = buffer.indexOf(' ', i, indexTo);
    if (blank < 0) {
      blank = indexTo;
    final String s = buffer.substringTrimmed(i, blank);
    for (int j = 0; j < s.length(); j++) {
      if (!Character.isDigit(s.charAt(j))) {
        throw new ParseException(
            "Status line contains invalid status code: "
            + buffer.substring(indexFrom, indexTo));
      statusCode = Integer.parseInt(s);
    } catch (final NumberFormatException e) {
      throw new ParseException(
          "Status line contains invalid status code: "
          + buffer.substring(indexFrom, indexTo));
    throw new ParseException("Invalid status line: " +
                 buffer.substring(indexFrom, indexTo));

代码示例来源:origin: ibinti/bugvm

while (this.state != COMPLETED) {
  if (this.lineBuf == null) {
    this.lineBuf = new CharArrayBuffer(64);
  } else {
    this.lineBuf.clear();
      (this.lineBuf.length() > maxLineLen ||
          (!lineComplete && this.sessionBuffer.length() > maxLineLen))) {
    throw new MessageConstraintException("Maximum line length limit exceeded");
      parseHeadLine();
    } catch (final ParseException px) {
      throw new ProtocolException(px.getMessage(), px);
      this.message.addHeader(lineParser.parseHeader(buffer));
    } catch (final ParseException ex) {
      throw new ProtocolException(ex.getMessage(), ex);

代码示例来源:origin: robovm/robovm

public HttpMessage parse() throws IOException, HttpException {
  HttpMessage message = null;
  try {
    message = parseHead(this.sessionBuffer);
  } catch (ParseException px) {
    throw new ProtocolException(px.getMessage(), px);
  }
  Header[] headers = AbstractMessageParser.parseHeaders(
      this.sessionBuffer, 
      this.maxHeaderCount,
      this.maxLineLen,
      this.lineParser);
  message.setHeaders(headers);
  return message;
}

代码示例来源:origin: com.bugvm/bugvm-rt

int from = Args.notNegative(pos, "Search position");
boolean found = false;
final int to = this.currentHeader.length();
    from++;
  } else if (isTokenChar(ch)) {
    throw new ParseException
      ("Tokens without separator (pos " + from +
       "): " + this.currentHeader);
  } else {
    throw new ParseException
      ("Invalid character after token (pos " + from +
       "): " + this.currentHeader);

代码示例来源:origin: robovm/robovm

from++;
} else if (isTokenChar(ch)) {
  throw new ParseException
    ("Tokens without separator (pos " + from +
     "): " + this.currentHeader);
} else {
  throw new ParseException
    ("Invalid character after token (pos " + from +
     "): " + this.currentHeader);

代码示例来源:origin: net.mingsoft/ms-proxy

/**
 * 返回页面内容
 * 
 * @return 字符串。如果异常返回null
 */
public String getContent() {
  try {
    return EntityUtils.toString(httpEntity);
  } catch (ParseException e) {
    e.printStackTrace();
  } catch (IOException e) {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: ibinti/bugvm

final ParserCursor cursor) throws ParseException {
  skipWhitespace(buffer, cursor);
  int i = cursor.getPos();
  int blank = buffer.indexOf(' ', i, indexTo);
  if (blank < 0) {
    throw new ParseException("Invalid request line: " +
        buffer.substring(indexFrom, indexTo));
  blank = buffer.indexOf(' ', i, indexTo);
  if (blank < 0) {
    throw new ParseException("Invalid request line: " +
        buffer.substring(indexFrom, indexTo));
  cursor.updatePos(blank);
  final ProtocolVersion ver = parseProtocolVersion(buffer, cursor);
  skipWhitespace(buffer, cursor);
  if (!cursor.atEnd()) {
    throw new ParseException("Invalid request line: " +
        buffer.substring(indexFrom, indexTo));
  return createRequestLine(method, uri, ver);
} catch (final IndexOutOfBoundsException e) {
  throw new ParseException("Invalid request line: " +
               buffer.substring(indexFrom, indexTo));

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.apache.httpcomponents.httpcore

final ProtocolVersion ver = parseProtocolVersion(buffer, cursor);
skipWhitespace(buffer, cursor);
int i = cursor.getPos();
int blank = buffer.indexOf(' ', i, indexTo);
if (blank < 0) {
  blank = indexTo;
final String s = buffer.substringTrimmed(i, blank);
for (int j = 0; j < s.length(); j++) {
  if (!Character.isDigit(s.charAt(j))) {
    throw new ParseException(
        "Status line contains invalid status code: "
        + buffer.substring(indexFrom, indexTo));
  statusCode = Integer.parseInt(s);
} catch (final NumberFormatException e) {
  throw new ParseException(
      "Status line contains invalid status code: "
      + buffer.substring(indexFrom, indexTo));
  reasonPhrase = "";
return createStatusLine(ver, statusCode, reasonPhrase);
throw new ParseException("Invalid status line: " +
             buffer.substring(indexFrom, indexTo));

代码示例来源:origin: ibinti/bugvm

/**
 * Parses textual representation of {@code Content-Type} value.
 *
 * @param s text
 * @return content type
 * @throws ParseException if the given text does not represent a valid
 * {@code Content-Type} value.
 * @throws UnsupportedCharsetException Thrown when the named charset is not available in
 * this instance of the Java virtual machine
 */
public static ContentType parse(
    final String s) throws ParseException, UnsupportedCharsetException {
  Args.notNull(s, "Content type");
  final CharArrayBuffer buf = new CharArrayBuffer(s.length());
  buf.append(s);
  final ParserCursor cursor = new ParserCursor(0, s.length());
  final HeaderElement[] elements = BasicHeaderValueParser.INSTANCE.parseElements(buf, cursor);
  if (elements.length > 0) {
    return create(elements[0], true);
  } else {
    throw new ParseException("Invalid content type: " + s);
  }
}

代码示例来源:origin: ibinti/bugvm

/**
 * Creates a new header from a buffer.
 * The name of the header will be parsed immediately,
 * the value only if it is accessed.
 *
 * @param buffer    the buffer containing the header to represent
 *
 * @throws ParseException   in case of a parse error
 */
public BufferedHeader(final CharArrayBuffer buffer)
  throws ParseException {
  super();
  Args.notNull(buffer, "Char array buffer");
  final int colon = buffer.indexOf(':');
  if (colon == -1) {
    throw new ParseException
      ("Invalid header: " + buffer.toString());
  }
  final String s = buffer.substringTrimmed(0, colon);
  if (s.length() == 0) {
    throw new ParseException
      ("Invalid header: " + buffer.toString());
  }
  this.buffer = buffer;
  this.name = s;
  this.valuePos = colon + 1;
}

代码示例来源:origin: com.bugvm/bugvm-rt

while (this.state != COMPLETED) {
  if (this.lineBuf == null) {
    this.lineBuf = new CharArrayBuffer(64);
  } else {
    this.lineBuf.clear();
      (this.lineBuf.length() > maxLineLen ||
          (!lineComplete && this.sessionBuffer.length() > maxLineLen))) {
    throw new MessageConstraintException("Maximum line length limit exceeded");
      parseHeadLine();
    } catch (final ParseException px) {
      throw new ProtocolException(px.getMessage(), px);
      this.message.addHeader(lineParser.parseHeader(buffer));
    } catch (final ParseException ex) {
      throw new ProtocolException(ex.getMessage(), ex);

代码示例来源:origin: com.myjeeva.digitalocean/digitalocean-api-client

private String httpResponseToString(HttpResponse httpResponse) {
 String response = StringUtils.EMPTY;
 if (null != httpResponse.getEntity()) {
  try {
   response = EntityUtils.toString(httpResponse.getEntity(), UTF_8);
  } catch (ParseException pe) {
   log.error(pe.getMessage(), pe);
  } catch (IOException ioe) {
   log.error(ioe.getMessage(), ioe);
  }
 }
 return response;
}

代码示例来源:origin: ibinti/bugvm

int from = Args.notNegative(pos, "Search position");
boolean found = false;
final int to = this.currentHeader.length();
    from++;
  } else if (isTokenChar(ch)) {
    throw new ParseException
      ("Tokens without separator (pos " + from +
       "): " + this.currentHeader);
  } else {
    throw new ParseException
      ("Invalid character after token (pos " + from +
       "): " + this.currentHeader);

代码示例来源:origin: robovm/robovm

throw new ParseException
  ("Invalid character before token (pos " + from +
   "): " + this.currentHeader);

相关文章