IoSupport { public static void writeUTF8File(URL file, String contents) throws IOException { try { writeUTF8File(new File(file.toURI()), contents); } catch (URISyntaxException e) { throw new IOException("Couldn't parse the URL", e); } } private  IoSupport(); static String getSystemTmpDir(); static boolean closeQuietly(final Closeable s); static boolean closeQuietly(final StreamHelper s); static boolean closeQuietly(final Process process); static void writeUTF8File(URL file, String contents); static void writeUTF8File(File file, String contents); static void writeUTF8File(String filename, String contents); @Deprecated static String readFileFromURL(URL url); @Deprecated static String readFileFromURL(URL url, TrustedHttpClient trustedClient); static Properties loadPropertiesFromUrl(final URL url); static Properties loadPropertiesFromStream(final InputStream stream); static Option<String> loadTxtFromClassPath(final String resource, final Class<?> clazz); @Deprecated static A withStream(InputStream s, Function<InputStream, A> f); static A withResource(B b, Function<B, A> f); static A withResource(B b, Fn<? super B, ? extends A> f); static Option<InputStream> openClassPathResource(String resource, Class<?> clazz); static Option<InputStream> openClassPathResource(String resource); static Option<File> classPathResourceAsFile(String resource); static Option<String> loadFileFromClassPathAsString(String resource, Class<?> clazz); static Option<String> loadFileFromClassPathAsString(String resource); static Option<A> withFile(File file, Function2<InputStream, File, A> f); @Deprecated static Either<Err, A> withStream(Function0<InputStream> s, Function<Exception, Err> toErr,
          Function<InputStream, A> f); static Either<Err, A> withResource(Function0<B> r,
          Function<Exception, Err> toErr, Function<B, A> f); @Deprecated static A withStream(OutputStream s, Function<OutputStream, A> f); static Function0<InputStream> fileInputStream(final File a); static File file(String... pathElems); static synchronized A locked(File file, Function<File, A> f); static A serializeDeserialize(final A a); static final Function<InputStream, String> readToString; }
@Test public void testWriteUTF8FileURLString() throws IOException { IoSupport.writeUTF8File(spacesFileURL, sampleText); Assert.assertTrue("File " + spacesFile.getAbsolutePath() + " was not created or is not valid", spacesFile.isFile()); String line = null; StringBuilder sb = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(spacesFileURL.openStream())); while ((line = br.readLine()) != null) sb.append(line).append('\n'); } catch (IOException ioe) { throw ioe; } finally { if (br != null) br.close(); } Assert.assertEquals("File contents comparison", sampleText, sb.toString()); }
@Test public void testWriteUTF8FileFileString() throws IOException { IoSupport.writeUTF8File(spacesFile, sampleText); Assert.assertTrue("File " + spacesFile.getAbsolutePath() + " was not created or is not valid", spacesFile.isFile()); String line = null; StringBuilder sb = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(spacesFileURL.openStream())); while ((line = br.readLine()) != null) sb.append(line).append('\n'); } catch (IOException ioe) { throw ioe; } finally { if (br != null) br.close(); } Assert.assertEquals("File contents comparison", sampleText, sb.toString()); }