Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
public static InputStream httpGET(String inURL) throws IOException { URLConnection conn = null; URL url = new URL(inURL); conn = url.openConnection(); return conn.getInputStream(); } public static void writeToFile(InputStream input, File inFile) throws IOException { // Throw an exception if there is a problem with the parameters if (input == null) { throw new IOException("Could not write to file due to null InputStream"); } if (inFile.exists()) { input.close(); throw new IOException("Could not write to file because the following file already existed:" + "\n" + inFile.getCanonicalPath()); } // write the file BufferedOutputStream output = null; try { output = new BufferedOutputStream(new FileOutputStream(inFile)); byte[] buffer = new byte[1024]; int numRead; long numWritten = 0; while ((numRead = input.read(buffer)) != -1) { output.write(buffer, 0, numRead); numWritten += numRead; } } finally { // close the streams if (output != null) { output.close(); } input.close(); } }
This paste will be private.
From the Design Piracy series on my blog: