io.netty.handler.codec.http.HttpResponse.getContent()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(152)

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

HttpResponse.getContent介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

File file = service.files().get(files[i]).execute();

HttpResponse resp = service.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl())).execute();
InputStream is = resp.getContent();
BufferedInputStream bufferedInputStream = new BufferedInputStream(is);

Bitmap bmp = BitmapFactory.decodeStream(bufferedInputStream);

代码示例来源:origin: stackoverflow.com

private static InputStream downloadFile(Drive service, File file) {
 if (file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) {
  try {
   HttpResponse resp =
     service.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl()))
       .execute();
   return resp.getContent();
  } catch (IOException e) {
   // An error occurred.
   e.printStackTrace();
   return null;
  }
 } else {
  // The file doesn't have any content stored on Drive.
  return null;
 }
}

代码示例来源:origin: stackoverflow.com

// download contents a
GenericUrl url = new GenericUrl(file.getDownloadUrl());
HttpResponse response = drive.getRequestFactory().buildGetRequest(url).execute();
String contents = new Scanner(response.getContent()).useDelimiter("\\A").next();

代码示例来源:origin: stackoverflow.com

private static InputStream downloadFile(Drive service, File file) { 
if (file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) { 
try { 
HttpResponse resp = 
service.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl())) 
.execute(); 
return resp.getContent(); 
} catch (IOException e) { 
// An error occurred. 
e.printStackTrace(); 
return null; 
} 
} else { 
// The file doesn't have any content stored on Drive. 
return null; 
} 
}

代码示例来源:origin: stackoverflow.com

private static InputStream downloadFile(Drive service, File file) {
 if (file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) {
  try {
   HttpResponse resp =
     service.getRequestFactory()
       .buildGetRequest(new GenericUrl(file.getDownloadUrl()))
       .execute();
   return resp.getContent();
  } catch (IOException e) {
   // An error occurred.
   e.printStackTrace();
   return null;
  }
 } else {
  // The file doesn't have any content stored on Drive.
  return null;
 }
}

代码示例来源:origin: stackoverflow.com

/**
* Download a file's content.
*
* @param service Drive API service instance.
* @param file Drive File instance.
* @return InputStream containing the file's content if successful,
* {@code null} otherwise.
*/
private static InputStream downloadFile(Drive service, File file) {
  if (file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) {
    try {
      HttpResponse resp =
      service.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl()))
      .execute();
      return resp.getContent();
    } catch (IOException e) {
      // An error occurred.
      e.printStackTrace();
      return null;
    }
  } else {
    // The file doesn't have any content stored on Drive.
    return null;
  }
}

代码示例来源:origin: stackoverflow.com

/**
 * Download the content of the given file.
 *
 * @param service Drive service to use for downloading.
 * @param file File metadata object whose content to download.
 * @return String representation of file content.  String is returned here
 *         because this app is setup for text/plain files.
 * @throws IOException Thrown if the request fails for whatever reason.
 */
private String downloadFileContent(Drive service, File file)
  throws IOException {
 GenericUrl url = new GenericUrl(file.getDownloadUrl());
 HttpResponse response = service.getRequestFactory().buildGetRequest(url)
   .execute();
 try {
  return new Scanner(response.getContent()).useDelimiter("\\A").next();
 } catch (java.util.NoSuchElementException e) {
  return "";
 }
}

代码示例来源:origin: stackoverflow.com

private static InputStream downloadFile(Drive service, String exportUrl) {
 try {
  HttpResponse resp =
    service.getRequestFactory()
      .buildGetRequest(new GenericUrl(exportUrl))
      .execute();
  return resp.getContent();
 } catch (IOException e) {
  // An error occurred.
  e.printStackTrace();
  return null;
 }
}

代码示例来源:origin: stackoverflow.com

HttpRequest httpRequest = requestFactory.buildGetRequest(new GenericUrl(url));
HttpResponse httpResponse = httpRequest.execute();
inputStream = httpResponse.getContent();

代码示例来源:origin: stackoverflow.com

HttpResponse resp = service.getRequestFactory().
     buildGetRequest(new GenericUrl(file.getDownloadUrl())).execute();
     Detector detector = new DefaultDetector();
     Parser parser = new AutoDetectParser(detector);
     Metadata metadata = new Metadata();
     InputStream input = TikaInputStream.get(resp.getContent());
     ContentHandler handler2 = new BodyContentHandler(
         Integer.MAX_VALUE);
     parser.parse(input, handler2, metadata, new ParseContext());
     String text = handler2.toString();

代码示例来源:origin: stackoverflow.com

HttpResponse response = httpRequestFactory.buildPostRequest(
      SubmitUrl, content).execute();
  System.out.println(IOUtils.toString(response.getContent()));
} catch (IOException e) {
  ...

代码示例来源:origin: stackoverflow.com

HttpTransport transport = new ApacheHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory();
HttpRequest request = requestFactory.buildGetRequest(url);
HttpResponse response = request.execute();
   try {
    // process the HTTP response object
      InputStream is = response.getContent();
      try {
        // Process the input stream..
      } finally {
        is.close();
      }
   } finally {
    response.disconnect();
   }

代码示例来源:origin: org.jboss.errai.io.netty/netty-example

@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
  Channel ch = ctx.getChannel();
  if (!handshaker.isHandshakeComplete()) {
    handshaker.finishHandshake(ch, (HttpResponse) e.getMessage());
    System.out.println("WebSocket Client connected!");
    return;
  }
  if (e.getMessage() instanceof HttpResponse) {
    HttpResponse response = (HttpResponse) e.getMessage();
    throw new Exception("Unexpected HttpResponse (status=" + response.getStatus() + ", content="
        + response.getContent().toString(CharsetUtil.UTF_8) + ")");
  }
  WebSocketFrame frame = (WebSocketFrame) e.getMessage();
  if (frame instanceof TextWebSocketFrame) {
    TextWebSocketFrame textFrame = (TextWebSocketFrame) frame;
    System.out.println("WebSocket Client received message: " + textFrame.getText());
  } else if (frame instanceof PongWebSocketFrame) {
    System.out.println("WebSocket Client received pong");
  } else if (frame instanceof CloseWebSocketFrame) {
    System.out.println("WebSocket Client received closing");
    ch.close();
  }
}

代码示例来源:origin: org.jboss.errai.io.netty/netty-example

System.out.println("CHUNKED CONTENT {");
} else {
  ChannelBuffer content = response.getContent();
  if (content.readable()) {
    System.out.println("CONTENT {");

代码示例来源:origin: org.jboss.errai.io.netty/netty-example

System.out.println("CHUNKED CONTENT {");
} else {
  ChannelBuffer content = response.getContent();
  if (content.readable()) {
    System.out.println("CONTENT {");

代码示例来源:origin: stackoverflow.com

System.out.println(new String(response.getContent().slice(0, 50).array()));
System.out.println("End -------------------\n");

代码示例来源:origin: org.jboss.errai.io.netty/netty-example

private void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {
  // Generate an error page if response status code is not OK (200).
  if (res.getStatus().getCode() != 200) {
    res.setContent(ChannelBuffers.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8));
    setContentLength(res, res.getContent().readableBytes());
  }
  // Send the response and close the connection if necessary.
  ChannelFuture f = ctx.getChannel().write(res);
  if (!isKeepAlive(req) || res.getStatus().getCode() != 200) {
    f.addListener(ChannelFutureListener.CLOSE);
  }
}

代码示例来源:origin: org.jboss.errai.io.netty/netty-example

private void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {
  // Generate an error page if response status code is not OK (200).
  if (res.getStatus().getCode() != 200) {
    res.setContent(ChannelBuffers.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8));
    setContentLength(res, res.getContent().readableBytes());
  }
  // Send the response and close the connection if necessary.
  ChannelFuture f = ctx.getChannel().write(res);
  if (!isKeepAlive(req) || res.getStatus().getCode() != 200) {
    f.addListener(ChannelFutureListener.CLOSE);
  }
}

代码示例来源:origin: org.jboss.errai.io.netty/netty-example

private void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {
  // Generate an error page if response status code is not OK (200).
  if (res.getStatus().getCode() != 200) {
    res.setContent(ChannelBuffers.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8));
    setContentLength(res, res.getContent().readableBytes());
  }
  // Send the response and close the connection if necessary.
  ChannelFuture f = ctx.getChannel().write(res);
  if (!isKeepAlive(req) || res.getStatus().getCode() != 200) {
    f.addListener(ChannelFutureListener.CLOSE);
  }
}

代码示例来源:origin: org.jboss.errai.io.netty/netty-example

response.setHeader(CONTENT_LENGTH, response.getContent().readableBytes());

相关文章