FileIOUtils { public static void copyInputStreamToFile(final InputStream source, final File destination) throws IOException { boolean success = false; try { FileUtils.copyInputStreamToFile(source, destination); success = true; } finally { if (!success) { forceDelete(destination); } } } private  FileIOUtils(); static void sort(File file); static void sort(File file, Comparator<String> comparator); static void merge(List<File> files, File output); static void merge(List<File> files, File output, Comparator<String> comparator); static File copy(InputStream stream); static void append(List<File> files, File appendTo, boolean delete); static void writeAsLine(BufferedWriter writer, String str, boolean escape); static int writeStrings(Iterator<String> iterator, File f, boolean escape); static int writeStrings(Iterator<String> iterator, File f, boolean escape,
        @Nullable Logger logger, @Nullable String message); static int writeStrings(Iterator<String> iterator, File f, boolean escape,
        @NotNull java.util.function.Function<String, String> transformer, @Nullable Logger logger, @Nullable String message); @Deprecated static int writeStrings(Iterator<String> iterator, File f, boolean escape,
            @NotNull Function<String, String> transformer, @Nullable Logger logger, @Nullable String message); static Set<String> readStringsAsSet(InputStream stream, boolean unescape); static Comparator<String> lineBreakAwareComparator(Comparator<String> delegate); static void copyInputStreamToFile(final InputStream source, final File destination); final static Comparator<String> lexComparator; @Deprecated final static Function<String, String> passThruTransformer; }
@Test public void copyStreamToFileNoPartialCreation() throws Exception { File f = folder.newFile(); FileIOUtils.copyInputStreamToFile(randomStream(12, 8192), f); File f2 = folder.newFile(); try { FileIOUtils.copyInputStreamToFile(new ErrorInputStream(f, 4096), f2); Assert.fail("Should have failed with IOException"); } catch (Exception e) {} assertTrue(f.exists()); assertTrue(!f2.exists()); }