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

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

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

URLConnection.getDoOutput介绍

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

代码示例

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

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

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

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

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

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

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

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

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

  1. /**
  2. * Tests whether the application can modify 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 file that exists <EM>and</EM> the
  7. * application is allowed to write to the file; <CODE>false</CODE>
  8. * otherwise.
  9. *
  10. * @param url URL to check if we can write to.
  11. */
  12. public boolean canWrite(URL url) {
  13. try {
  14. final URLConnection urlConnection = url.openConnection();
  15. return urlConnection.getDoOutput();
  16. }
  17. catch (Exception e) {
  18. return false;
  19. }
  20. }

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

  1. public void makeXMLRequest() {
  2. try {
  3. URL url = new URL("http://api.androidhive.info/pizza/?format=xml");
  4. HttpURLConnection con = (HttpURLConnection) url.openConnection();
  5. con.setRequestMethod("GET");
  6. con.getDoOutput();
  7. String readStream = readStream(con.getInputStream());
  8. // Give output for the command line
  9. System.out.println(readStream);
  10. } catch (Exception e) {
  11. e.printStackTrace();
  12. }
  13. }

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

  1. public void PutImageToS3(String signedUrl, Bitmap image) throws WampNetworkException, IOException {
  2. try{
  3. URL url = new URL(signedUrl);
  4. HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  5. conn.getDoOutput();
  6. conn.setUseCaches(false);
  7. conn.setRequestMethod("PUT");
  8. conn.addRequestProperty("Content-Type", "image/jpeg");
  9. conn.addRequestProperty("Connection", "close");
  10. OutputStream out = new BufferedOutputStream(conn.getOutputStream());
  11. image.compress(Bitmap.CompressFormat.JPEG, 100, out);
  12. if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
  13. throw new IOException("Failed to upload image to S3: "
  14. + conn.getResponseCode() + conn.getResponseMessage() + "\r\n");
  15. }
  16. }
  17. finally{
  18. out.flush();
  19. out.close();
  20. conn.disconnect();
  21. }
  22. }

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

  1. private void openConnection(HttpURLConnection connection, HttpRequest request) throws IOException {
  2. if (request.getHttpBody() != null) {
  3. connection.setDoOutput(true);
  4. }
  5. connection.setRequestMethod(request.getMethod());
  6. Map<String, String> map = request.getHeaders();
  7. for (Map.Entry<String, String> entry : map.entrySet()) {
  8. String key = entry.getKey();
  9. String value = entry.getValue();
  10. Logger.i("prepare headers with key = " + key + " value = " + value);
  11. connection.setRequestProperty(entry.getKey(), entry.getValue());
  12. }
  13. connection.setReadTimeout((int) mReadTimeout);
  14. connection.setConnectTimeout((int) mConnectionTimeout);
  15. if (connection.getDoOutput()) {
  16. connection.connect();
  17. }
  18. }

代码示例来源:origin: com.senseidb/sensei-core

  1. if (!conn.getDoOutput()) {
  2. conn.setDoOutput(true);
  3. os = conn.getOutputStream();

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

  1. if (urlConnection.getDoOutput()) {
  2. OutputStream outputStream = 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: graphstream/gs-algo

  1. if (conn.getDoOutput())
  2. conn.getOutputStream().close();
  3. reader.close();

代码示例来源:origin: org.graphstream/gs-algo

  1. if (conn.getDoOutput())
  2. conn.getOutputStream().close();
  3. reader.close();

代码示例来源: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类方法