当前位置: 首页>>代码示例>>Java>>正文


Java HttpURLConnection.getErrorStream方法代码示例

本文整理汇总了Java中java.net.HttpURLConnection.getErrorStream方法的典型用法代码示例。如果您正苦于以下问题:Java HttpURLConnection.getErrorStream方法的具体用法?Java HttpURLConnection.getErrorStream怎么用?Java HttpURLConnection.getErrorStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.HttpURLConnection的用法示例。


在下文中一共展示了HttpURLConnection.getErrorStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readAscii

import java.net.HttpURLConnection; //导入方法依赖的package包/类
/**
 * Reads {@code count} characters from the stream. If the stream is exhausted before {@code count}
 * characters can be read, the remaining characters are returned and the stream is closed.
 */
private String readAscii(URLConnection connection, int count) throws IOException {
  HttpURLConnection httpConnection = (HttpURLConnection) connection;
  InputStream in = httpConnection.getResponseCode() < HttpURLConnection.HTTP_BAD_REQUEST
      ? connection.getInputStream()
      : httpConnection.getErrorStream();
  StringBuilder result = new StringBuilder();
  for (int i = 0; i < count; i++) {
    int value = in.read();
    if (value == -1) {
      in.close();
      break;
    }
    result.append((char) value);
  }
  return result.toString();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:UrlConnectionCacheTest.java

示例2: processResponseOutput

import java.net.HttpURLConnection; //导入方法依赖的package包/类
private void processResponseOutput(HttpURLConnection con, Response response) throws IOException {
  InputStream in = con.getErrorStream();
  try {
    if (in == null) {
      in = con.getInputStream();
    }
    ByteArrayOutputStream result = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];
    int length;
    while ((length = in.read(buffer)) != -1) {
      result.write(buffer, 0, length);
    }
    response.output = result.toString();
  } finally {
    if (in != null) {
      in.close();
    }
  }
}
 
开发者ID:symphonyoss,项目名称:JCurl,代码行数:20,代码来源:JCurl.java

示例3: getResponseAsResponseEntity

import java.net.HttpURLConnection; //导入方法依赖的package包/类
private static HttpResponseEntity getResponseAsResponseEntity(HttpURLConnection conn) throws IOException {
    HttpResponseEntity responseEntity = new HttpResponseEntity();
    String charset = getResponseCharset(conn.getContentType());
    InputStream es = conn.getErrorStream();

    responseEntity.setStatusCode(conn.getResponseCode());
    if (es == null) {
        String contentEncoding = conn.getContentEncoding();
        if (CONTENT_ENCODING_GZIP.equalsIgnoreCase(contentEncoding)) {
            responseEntity.setBody(getStreamAsString(new GZIPInputStream(conn.getInputStream()), charset));
        } else {
            responseEntity.setBody(getStreamAsString(conn.getInputStream(), charset));
        }
    } else {
        String msg = getStreamAsString(es, charset);
        if (StringUtils.isEmpty(msg)) {
            responseEntity.setBody(conn.getResponseCode() + ":" + conn.getResponseMessage());
        } else {
            responseEntity.setBody(msg);
        }
    }

    return responseEntity;
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:25,代码来源:HttpUtils.java

示例4: entityFromConnection

import java.net.HttpURLConnection; //导入方法依赖的package包/类
/**
 * Initializes an {@link HttpEntity} from the given {@link HttpURLConnection}.
 * @param connection
 * @return an HttpEntity populated with data from <code>connection</code>.
 */
private static HttpEntity entityFromConnection(HttpURLConnection connection) {
    BasicHttpEntity entity = new BasicHttpEntity();
    InputStream inputStream;
    try {
        inputStream = connection.getInputStream();
    } catch (IOException ioe) {
        inputStream = connection.getErrorStream();
    }
    entity.setContent(inputStream);
    entity.setContentLength(connection.getContentLength());
    entity.setContentEncoding(connection.getContentEncoding());
    entity.setContentType(connection.getContentType());
    return entity;
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:20,代码来源:HurlStack.java

示例5: getResponseAsString

import java.net.HttpURLConnection; //导入方法依赖的package包/类
protected static String getResponseAsString(HttpURLConnection conn) throws IOException {
    String charset = getResponseCharset(conn.getContentType());
    InputStream es = conn.getErrorStream();
    if (es == null) {
        return getStreamAsString(conn.getInputStream(), charset);
    } else {
        String msg = getStreamAsString(es, charset);
        if (StringUtils.isEmpty(msg)) {
            throw new IOException(conn.getResponseCode() + ":" + conn.getResponseMessage());
        } else {
            throw new IOException(msg);
        }
    }
}
 
开发者ID:1991wangliang,项目名称:pay,代码行数:15,代码来源:AlipayMobilePublicMultiMediaClient.java

示例6: GetJSON

import java.net.HttpURLConnection; //导入方法依赖的package包/类
private static JSONObject GetJSON(URL url) {
    try {
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setRequestProperty("Accept", "application/json");
        urlConnection.setRequestProperty("Client-ID", "zdol60x6sxbx0phk60ci6mki79qhrf");
        urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0");
        urlConnection.setUseCaches(false);

        InputStream inputStream;
        int status = urlConnection.getResponseCode();

        if (status != HttpURLConnection.HTTP_OK)
            inputStream = urlConnection.getErrorStream();
        else
            inputStream = urlConnection.getInputStream();

        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
            String inputLine = br.readLine();

            br.close();

            return new JSONObject(inputLine);
        } finally {
            urlConnection.disconnect();
        }
    } catch(Exception e) {
        e.printStackTrace();
    }

    return null;
}
 
开发者ID:invghost,项目名称:NeoStream,代码行数:33,代码来源:TwitchAPI.java

示例7: readErrorFromConnection

import java.net.HttpURLConnection; //导入方法依赖的package包/类
private static NexusError readErrorFromConnection(HttpURLConnection connection) throws NexusCommunicationException {
    try {
        InputStream e = connection == null?null:connection.getErrorStream();
        if(e == null) {
            LogService.getRoot().log(Level.WARNING, "com.rapidminer.tools.account.RapidMinerAccount.error_parse_failure", "No available error stream.");
            throw new NexusCommunicationException(500);
        } else {
            return (NexusError)NexusUtilities.parseJacksonString(Tools.parseInputStreamToString(e), NexusError.class);
        }
    } catch (IOException var2) {
        LogService.getRoot().log(Level.WARNING, "com.rapidminer.tools.account.RapidMinerAccount.error_parse_failure", var2.getMessage());
        throw new NexusCommunicationException(500);
    }
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:15,代码来源:RapidMinerAccount.java

示例8: manageError

import java.net.HttpURLConnection; //导入方法依赖的package包/类
private void manageError(Exception e, HttpURLConnection urlConnection) {
    if (SimpleNetworkUtils.isNetworkAvailable(context)) {
        if (urlConnection != null) {
            try {
                code = urlConnection.getResponseCode();
                if (urlConnection.getErrorStream() != null) {
                    InputStream is = urlConnection.getErrorStream();
                    StringBuilder buffer = new StringBuilder();
                    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                    String line;
                    while ((line = reader.readLine()) != null) {
                        buffer.append(line).append("\n");
                    }
                    message = buffer.toString();
                } else {
                    message = urlConnection.getResponseMessage();
                }
                error = urlConnection.getErrorStream().toString();
                Log.e(LOG_TAG, "Error: " + message + ", code: " + code);
            } catch (IOException e1) {
                e1.printStackTrace();
                Log.e(LOG_TAG, "Error: " + e1.getMessage());
            }
        } else {
            code = 105;
            error = e.getMessage();
            message = "Error: No internet connection";
            Log.e(LOG_TAG, "code: " + code + ", " + message);
        }
    } else {
        code = 105;
        error = e.getMessage();
        message = "Error: No internet connection";
        Log.e(LOG_TAG, "code: " + code + ", " + message);
    }
}
 
开发者ID:ahmed-adel-said,项目名称:SimpleNetworkLibrary,代码行数:37,代码来源:NetworkRequestAsyncTask.java

示例9: entityFromConnection

import java.net.HttpURLConnection; //导入方法依赖的package包/类
private static HttpEntity entityFromConnection(HttpURLConnection connection) {
    InputStream inputStream;
    BasicHttpEntity entity = new BasicHttpEntity();
    try {
        inputStream = connection.getInputStream();
    } catch (IOException e) {
        inputStream = connection.getErrorStream();
    }
    entity.setContent(inputStream);
    entity.setContentLength((long) connection.getContentLength());
    entity.setContentEncoding(connection.getContentEncoding());
    entity.setContentType(connection.getContentType());
    return entity;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:15,代码来源:OkHttpStack.java

示例10: getResponseStream

import java.net.HttpURLConnection; //导入方法依赖的package包/类
private InputStream getResponseStream(HttpURLConnection connection) {
    InputStream input = null;
    try {
        input = connection.getInputStream();
    } catch (IOException ioEx) {
        input = connection.getErrorStream();
    }
    return input;
}
 
开发者ID:nongfenqi,项目名称:dingtalk-incoming-webhoot-plugin,代码行数:10,代码来源:DingtalkNotificationPlugin.java

示例11: getErrorStream

import java.net.HttpURLConnection; //导入方法依赖的package包/类
private InputStream getErrorStream(HttpURLConnection connection)
		throws IOException {
	if ("gzip".equalsIgnoreCase(connection.getContentEncoding())) {
		return new GZIPInputStream(connection.getErrorStream());
	}

	if ("deflate".equals(connection.getContentEncoding())) {
		return new InflaterInputStream(connection.getErrorStream());
	}
	return connection.getErrorStream();
}
 
开发者ID:RayTW,项目名称:8ComicSDK-JAVA,代码行数:12,代码来源:EasyHttp.java

示例12: entityFromConnection

import java.net.HttpURLConnection; //导入方法依赖的package包/类
private static HttpEntity entityFromConnection(HttpURLConnection connection) {
    BasicHttpEntity entity = new BasicHttpEntity();
    InputStream inputStream;
    try {
        inputStream = connection.getInputStream();
    } catch (IOException ioe) {
        inputStream = connection.getErrorStream();
    }
    entity.setContent(inputStream);
    entity.setContentLength(connection.getContentLength());
    entity.setContentEncoding(connection.getContentEncoding());
    entity.setContentType(connection.getContentType());
    return entity;
}
 
开发者ID:DLKanth,项目名称:Stetho-Volley,代码行数:15,代码来源:StethoVolleyStack.java

示例13: open

import java.net.HttpURLConnection; //导入方法依赖的package包/类
private static int open(String str) {
    InputStream inputStream = null;
    try {
        int i;
        HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
        httpURLConnection.setRequestMethod("GET");
        httpURLConnection.setConnectTimeout(5000);
        httpURLConnection.setReadTimeout(5000);
        httpURLConnection.setUseCaches(false);
        if (200 == httpURLConnection.getResponseCode()) {
            inputStream = httpURLConnection.getInputStream();
            StreamToString(inputStream);
            i = 1;
        } else {
            inputStream = httpURLConnection.getErrorStream();
            StreamToString(inputStream);
            i = 0;
        }
        String.valueOf(i);
        if (inputStream == null) {
            return i;
        }
        try {
            inputStream.close();
            return i;
        } catch (IOException e) {
            e.printStackTrace();
            return i;
        }
    } catch (Exception e2) {
        e2.printStackTrace();
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e3) {
                e3.printStackTrace();
            }
        }
        return 0;
    } catch (Throwable th) {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e4) {
                e4.printStackTrace();
            }
        }
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:50,代码来源:a.java

示例14: GetStreamURI

import java.net.HttpURLConnection; //导入方法依赖的package包/类
static String GetStreamURI(String username, String quality) {
    try {
        //FIXME: HTTP is bad!
        URL url = new URL("http://usher.twitch.tv/api/channel/hls/" + URLEncoder.encode(username, "UTF-8") + ".m3u8?player=twitchweb&token=" +
                URLEncoder.encode(GetAccessToken(username), "UTF-8") + "&sig=" + URLEncoder.encode(GetSignature(username), "UTF-8") + "&allow_source=true&allow_audio_only=true");

        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setRequestProperty("Client-ID", "zdol60x6sxbx0phk60ci6mki79qhrf");
        urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36");
        urlConnection.setUseCaches(false);

        InputStream inputStream;
        int status = urlConnection.getResponseCode();

        if (status != HttpURLConnection.HTTP_OK)
            inputStream = urlConnection.getErrorStream();
        else
            inputStream = urlConnection.getInputStream();

        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));

            boolean nextURL = false;

            String line = br.readLine();
            while(line != null)
            {
                if(nextURL) {
                    return line;
                } else {
                    final Pattern pattern = Pattern.compile("^#EXT-X-STREAM-INF:.*VIDEO=\"(?<value>[^\"]*)");

                    Matcher matcher = pattern.matcher(line);
                    if (matcher.find()) {
                        String streamQuality = matcher.group(1);

                        //this is it!!
                        if (streamQuality.equals(quality)) {
                            nextURL = true;
                        }
                    }
                }

                line = br.readLine();
            }

            br.close();
        } finally {
            urlConnection.disconnect();
        }
    } catch(Exception e) {
        e.printStackTrace();
    }

    return "undefined";
}
 
开发者ID:invghost,项目名称:NeoStream,代码行数:57,代码来源:TwitchAPI.java

示例15: getResponse

import java.net.HttpURLConnection; //导入方法依赖的package包/类
public static HttpResponse getResponse(HttpRequest request) throws IOException {
	OutputStream out= null;
	InputStream content = null;
	HttpResponse response = null;
	HttpURLConnection httpConn = request.getHttpConnection();

	try {
		httpConn.connect();
		if (null != request.getContent()) {
			out = httpConn.getOutputStream();
			out.write(request.getContent());
		}
		content = httpConn.getInputStream();
		response = new HttpResponse(httpConn.getURL().toString());
		pasrseHttpConn(response, httpConn, content);
		return response;
	} catch (IOException e) {
		content = httpConn.getErrorStream();
		response = new HttpResponse(httpConn.getURL().toString());
		pasrseHttpConn(response, httpConn, content);
		return response;
	} finally {
		if (content != null) 
			content.close();
           httpConn.disconnect();
       }
}
 
开发者ID:readen,项目名称:Relay,代码行数:28,代码来源:HttpResponse.java


注:本文中的java.net.HttpURLConnection.getErrorStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。