| 31 | } |
| 32 | |
| 33 | private static String readStream(InputStream stream) throws IOException { |
| 34 | // No real need to close the BufferedReader/InputStreamReader |
| 35 | // as they're only wrapping the stream |
| 36 | try { |
| 37 | Reader reader = new BufferedReader(new InputStreamReader(stream)); |
| 38 | StringBuilder builder = new StringBuilder(); |
| 39 | char[] buffer = new char[4096]; |
| 40 | int read; |
| 41 | while ((read = reader.read(buffer, 0, buffer.length)) > 0) { |
| 42 | builder.append(buffer, 0, read); |
| 43 | } |
| 44 | return builder.toString(); |
| 45 | } finally { |
| 46 | // Potential issue here: if this throws an IOException, |
| 47 | // it will mask any others. Normally I'd use a utility |
| 48 | // method which would log exceptions and swallow them |
| 49 | stream.close(); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | public static void main(String[] args) throws IOException, Client.ConfigError, Client.CredsUnspecifiedError { |
| 54 | if (args.length >= 1) |