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);
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; } }
// 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();
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; } }
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; } }
/** * 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; } }
/** * 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 ""; } }
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; } }
HttpRequest httpRequest = requestFactory.buildGetRequest(new GenericUrl(url)); HttpResponse httpResponse = httpRequest.execute(); inputStream = httpResponse.getContent();
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();
HttpResponse response = httpRequestFactory.buildPostRequest( SubmitUrl, content).execute(); System.out.println(IOUtils.toString(response.getContent())); } catch (IOException e) { ...
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(); }
@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(); } }
System.out.println("CHUNKED CONTENT {"); } else { ChannelBuffer content = response.getContent(); if (content.readable()) { System.out.println("CONTENT {");
System.out.println("CHUNKED CONTENT {"); } else { ChannelBuffer content = response.getContent(); if (content.readable()) { System.out.println("CONTENT {");
System.out.println(new String(response.getContent().slice(0, 50).array())); System.out.println("End -------------------\n");
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); } }
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); } }
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); } }
response.setHeader(CONTENT_LENGTH, response.getContent().readableBytes());