/** * Get the contents of a <code>Reader</code> as a String. */ public static String toString(Reader input) throws IOException { StringWriter sw = new StringWriter(); copyLarge(input, sw); return sw.toString(); }
private void remoteContentToFile(String path, File toFile) { InputStream input = null; FileOutputStream output = null; String fullUrl = serverUrl + path; try { HttpURLConnection connection = newHttpConnection(new URL(fullUrl)); output = new FileOutputStream(toFile, false); input = connection.getInputStream(); BootstrapperIOUtils.copyLarge(input, output); } catch (IOException e) { BootstrapperIOUtils.closeQuietly(output); BootstrapperIOUtils.deleteFileQuietly(toFile); throw new BootstrapException("Fail to download the file: " + fullUrl, e); } finally { BootstrapperIOUtils.closeQuietly(input); BootstrapperIOUtils.closeQuietly(output); } }