Apache HttpCore, простой сервер для вывода полученных данных сообщений

Используя пример класса ElementalHttpServer, найденный здесь:

https://hc.apache.org/httpcomponents-core-4.3.x/httpcore/examples/org/apache/http/examples/ElementalHttpServer.java

Я могу успешно получить данные сообщения, моя цель - преобразовать полученные данные сообщения в строку, которую я могу распечатать. Я изменил HttpFileHandler следующим образом, используя eneity.getContent () для получения inputStream, но я не уверен, как я могу преобразовать inputStream в String.

static class HttpFileHandler implements HttpRequestHandler  {

  private final String docRoot;

  public HttpFileHandler(final String docRoot) {
    super();
    this.docRoot = docRoot;
  }

  public void handle(
        final HttpRequest request, 
        final HttpResponse response,
        final HttpContext context) throws HttpException, IOException {

    String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH);
    if (!method.equals("GET") && !method.equals("HEAD") && !method.equals("POST")) {
        throw new MethodNotSupportedException(method + " method not supported"); 
    }
    String target = request.getRequestLine().getUri();

    if (request instanceof HttpEntityEnclosingRequest) {
        HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
        byte[] entityContent = EntityUtils.toByteArray(entity);
        InputStream inputStream = entity.getContent();

        String str= inputStream.toString();
        byte[] b3=str.getBytes();
        String st = new String(b3);
        System.out.println(st);
        for(int i=0;i

}

Спасибо за любые идеи

8
задан Alireza Mohamadi 31 May 2016 в 17:31
поделиться