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

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

本文整理了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

/**
 * Creates an OkHttp Response.Body containing the supplied information.
 */
private static ResponseBody createOkBody(final URLConnection urlConnection) throws IOException {
 if (!urlConnection.getDoInput()) {
  return null;
 }
 final BufferedSource body = Okio.buffer(Okio.source(urlConnection.getInputStream()));
 return new ResponseBody() {
  @Override public MediaType contentType() {
   String contentTypeHeader = urlConnection.getContentType();
   return contentTypeHeader == null ? null : MediaType.parse(contentTypeHeader);
  }
  @Override public long contentLength() {
   String s = urlConnection.getHeaderField("Content-Length");
   return stringToLong(s);
  }
  @Override public BufferedSource source() {
   return body;
  }
 };
}

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

@Override
public boolean getDoInput()
{
  return _conn.getDoInput();
}

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

public boolean getDoInput() {
  return connection.getDoInput();
}

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

public boolean getDoInput() {
 return delegateConnection.getDoInput();
}

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

public boolean getDoInput() {
  return connection.getDoInput();
}

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

/**
 * Tests whether the application can read the resource at the
 * specified {@link URL}.
 *
 * @return <CODE>true</CODE> if and only if the specified
 *         {@link URL} points to a resource that exists <EM>and</EM> can be
 *         read by the application; <CODE>false</CODE> otherwise.
 *
 * @param url URL to check if we can read from it.
 */
public boolean canRead(URL url) {
  try {
    final URLConnection urlConnection = url.openConnection();
    return urlConnection.getDoInput();
  }
  catch (Exception e) {
    return false;
  }
}

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

/**
 * Creates an OkHttp Response.Body containing the supplied information.
 */
private static ResponseBody createOkBody(final URLConnection urlConnection) throws IOException {
 if (!urlConnection.getDoInput()) {
  return null;
 }
 final BufferedSource body = Okio.buffer(Okio.source(urlConnection.getInputStream()));
 return new ResponseBody() {
  @Override public MediaType contentType() {
   String contentTypeHeader = urlConnection.getContentType();
   return contentTypeHeader == null ? null : MediaType.parse(contentTypeHeader);
  }
  @Override public long contentLength() {
   String s = urlConnection.getHeaderField("Content-Length");
   return stringToLong(s);
  }
  @Override public BufferedSource source() {
   return body;
  }
 };
}

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

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

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

/**
   * Should be called when a <code>Connection</code> is used to do a POST (write to it's outputstream)
   * without reading it's inputstream (the response). Calling this will make sure the POST request is sent.
   * If no data was written to the connection nothing is done.
   */
  public void close() {
    if (m_connection.getDoOutput()) {
      try {
        m_connection.getOutputStream().close();
      }
      catch (IOException e) {
        // not much we can do
      }
      try {
        m_connection.getContent();
      }
      catch (IOException e) {
        // not much we can do
      }
    }
    if (m_connection.getDoInput()) {
      try {
        m_connection.getInputStream().close();
      }
      catch (IOException e) {
        // not much we can do
      }
    }
  }
}

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

void serviceRequest(final PipeResponse response) throws IOException {
  if (!response.getURLConnection().getDoInput()) {
    try {
      Definition def = EndpointReferenceUtils.getWSDLDefinition(bus.getWSDLManager(), reference);
      Map<String, List<String>> headers = new LinkedHashMap<String, List<String>>();
      headers.put("Content-Type", Arrays.asList(new String[] {"text/xml"}));
      OutputStream out = response.setResponse(headers);
      bus.getWSDLManager().getWSDLFactory().newWSDLWriter().writeWSDL(def, out);
      out.flush();
      out.close();
      return;
    } catch (WSDLException ex) {
      // TODO Auto-generated catch block
      ex.printStackTrace();
    }
  }
      
  HTTPServerInputStreamContext ctx = new HTTPServerInputStreamContext(this) {
    public void initContext() throws IOException {
      super.initContext();
      inStream = response.getRequestInputStream();
      origInputStream = inStream;
    }
  };
  ctx.put(PIPE_RESPONSE, response);
  ctx.initContext();
  
  callback.dispatch(ctx, this);
}

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

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

相关文章

URLConnection类方法