java.net.URLConnection.getDoInput()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(163)

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

URLConnection.getDoInput介绍

[英]Returns the value of the option doInput which specifies whether this connection allows to receive data.
[中]返回选项doInput的值,该选项指定此连接是否允许接收数据。

代码示例

代码示例来源:origin: square/okhttp

  1. /**
  2. * Creates an OkHttp Response.Body containing the supplied information.
  3. */
  4. private static ResponseBody createOkBody(final URLConnection urlConnection) throws IOException {
  5. if (!urlConnection.getDoInput()) {
  6. return null;
  7. }
  8. final BufferedSource body = Okio.buffer(Okio.source(urlConnection.getInputStream()));
  9. return new ResponseBody() {
  10. @Override public MediaType contentType() {
  11. String contentTypeHeader = urlConnection.getContentType();
  12. return contentTypeHeader == null ? null : MediaType.parse(contentTypeHeader);
  13. }
  14. @Override public long contentLength() {
  15. String s = urlConnection.getHeaderField("Content-Length");
  16. return stringToLong(s);
  17. }
  18. @Override public BufferedSource source() {
  19. return body;
  20. }
  21. };
  22. }

代码示例来源:origin: org.eclipse.jetty.osgi/jetty-osgi-boot-warurl

  1. @Override
  2. public boolean getDoInput()
  3. {
  4. return _conn.getDoInput();
  5. }

代码示例来源:origin: org.samba.jcifs/jcifs

  1. public boolean getDoInput() {
  2. return connection.getDoInput();
  3. }

代码示例来源:origin: org.jboss/jboss-common-core

  1. public boolean getDoInput() {
  2. return delegateConnection.getDoInput();
  3. }

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

  1. public boolean getDoInput() {
  2. return connection.getDoInput();
  3. }

代码示例来源:origin: igniterealtime/Spark

  1. /**
  2. * Tests whether the application can read the resource at the
  3. * specified {@link URL}.
  4. *
  5. * @return <CODE>true</CODE> if and only if the specified
  6. * {@link URL} points to a resource that exists <EM>and</EM> can be
  7. * read by the application; <CODE>false</CODE> otherwise.
  8. *
  9. * @param url URL to check if we can read from it.
  10. */
  11. public boolean canRead(URL url) {
  12. try {
  13. final URLConnection urlConnection = url.openConnection();
  14. return urlConnection.getDoInput();
  15. }
  16. catch (Exception e) {
  17. return false;
  18. }
  19. }

代码示例来源:origin: com.squareup.okhttp3/okhttp-android-support

  1. /**
  2. * Creates an OkHttp Response.Body containing the supplied information.
  3. */
  4. private static ResponseBody createOkBody(final URLConnection urlConnection) throws IOException {
  5. if (!urlConnection.getDoInput()) {
  6. return null;
  7. }
  8. final BufferedSource body = Okio.buffer(Okio.source(urlConnection.getInputStream()));
  9. return new ResponseBody() {
  10. @Override public MediaType contentType() {
  11. String contentTypeHeader = urlConnection.getContentType();
  12. return contentTypeHeader == null ? null : MediaType.parse(contentTypeHeader);
  13. }
  14. @Override public long contentLength() {
  15. String s = urlConnection.getHeaderField("Content-Length");
  16. return stringToLong(s);
  17. }
  18. @Override public BufferedSource source() {
  19. return body;
  20. }
  21. };
  22. }

代码示例来源:origin: org.apache.cocoon.pipeline/cocoon-pipeline

  1. if (urlConnection.getDoInput()) {
  2. InputStream inputStream = null;
  3. try {

代码示例来源:origin: org.apache.ace/org.apache.ace.gateway.log

  1. /**
  2. * Should be called when a <code>Connection</code> is used to do a POST (write to it's outputstream)
  3. * without reading it's inputstream (the response). Calling this will make sure the POST request is sent.
  4. * If no data was written to the connection nothing is done.
  5. */
  6. public void close() {
  7. if (m_connection.getDoOutput()) {
  8. try {
  9. m_connection.getOutputStream().close();
  10. }
  11. catch (IOException e) {
  12. // not much we can do
  13. }
  14. try {
  15. m_connection.getContent();
  16. }
  17. catch (IOException e) {
  18. // not much we can do
  19. }
  20. }
  21. if (m_connection.getDoInput()) {
  22. try {
  23. m_connection.getInputStream().close();
  24. }
  25. catch (IOException e) {
  26. // not much we can do
  27. }
  28. }
  29. }
  30. }

代码示例来源:origin: org.objectweb.celtix/celtix-rt

  1. void serviceRequest(final PipeResponse response) throws IOException {
  2. if (!response.getURLConnection().getDoInput()) {
  3. try {
  4. Definition def = EndpointReferenceUtils.getWSDLDefinition(bus.getWSDLManager(), reference);
  5. Map<String, List<String>> headers = new LinkedHashMap<String, List<String>>();
  6. headers.put("Content-Type", Arrays.asList(new String[] {"text/xml"}));
  7. OutputStream out = response.setResponse(headers);
  8. bus.getWSDLManager().getWSDLFactory().newWSDLWriter().writeWSDL(def, out);
  9. out.flush();
  10. out.close();
  11. return;
  12. } catch (WSDLException ex) {
  13. // TODO Auto-generated catch block
  14. ex.printStackTrace();
  15. }
  16. }
  17. HTTPServerInputStreamContext ctx = new HTTPServerInputStreamContext(this) {
  18. public void initContext() throws IOException {
  19. super.initContext();
  20. inStream = response.getRequestInputStream();
  21. origInputStream = inStream;
  22. }
  23. };
  24. ctx.put(PIPE_RESPONSE, response);
  25. ctx.initContext();
  26. callback.dispatch(ctx, this);
  27. }

代码示例来源:origin: Countly/countly-sdk-android

  1. public void testUrlConnectionForEventData() throws IOException {
  2. final String eventData = "blahblahblah";
  3. final URLConnection urlConnection = connectionProcessor.urlConnectionForEventData(eventData);
  4. assertEquals(30000, urlConnection.getConnectTimeout());
  5. assertEquals(30000, urlConnection.getReadTimeout());
  6. assertFalse(urlConnection.getUseCaches());
  7. assertTrue(urlConnection.getDoInput());
  8. assertFalse(urlConnection.getDoOutput());
  9. assertEquals(new URL(connectionProcessor.getServerURL() + "/i?" + eventData + "&checksum=" + sha1Hash(eventData + null)), urlConnection.getURL());
  10. }

相关文章

URLConnection类方法