Here you can find the source of readError(HttpURLConnection conn)
Parameter | Description |
---|---|
conn | _more_ |
public static String readError(HttpURLConnection conn)
//package com.java2s; /*/*ww w. j a v a 2 s . c o m*/ * Copyright (c) 2008-2018 Geode Systems LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.*; import java.io.*; import java.net.*; public class Main { /** * _more_ * * @param conn _more_ * * @return _more_ */ public static String readError(HttpURLConnection conn) { try { return readString(new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"))); } catch (Exception exc) { return "No error message"; } } /** * _more_ * * @param input _more_ * * @return _more_ * * @throws Exception _more_ */ public static String readString(BufferedReader input) throws Exception { StringBuilder sb = new StringBuilder(); String line; while ((line = input.readLine()) != null) { sb.append(line); sb.append("\n"); } return sb.toString(); } /** * _more_ * * @param sb _more_ * @param s _more_ * * @return _more_ */ public static Appendable append(Appendable sb, String s) { try { sb.append(s); return sb; } catch (java.io.IOException ioe) { throw new RuntimeException(ioe); } } /** * _more_ * * @param o _more_ * * @return _more_ */ public static String toString(Object o) { if (o == null) { return ""; } return o.toString(); } }