diff --git a/README.md b/README.md index 4a53f78..697a9be 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,14 @@ FileUtils.writeToFile(pathString, contents); ``` +Write to File input steam + +```java +InputStream inputStream = ... +FileUtils.writeToFile(path, inputStream); +FileUtils.writeToFile(pathString, inputStream); +``` + Append to File ```java @@ -214,9 +222,3 @@ ```java String humanReadableSize = FileUtils.getHumanReadableSize(file); ``` - -Input Stream to File - -```java -FileUtils.copyInputStreamToFile(source, destination); -``` diff --git a/src/main/java/io/ljunggren/file/utils/FileUtils.java b/src/main/java/io/ljunggren/file/utils/FileUtils.java index 13547bc..578eaff 100644 --- a/src/main/java/io/ljunggren/file/utils/FileUtils.java +++ b/src/main/java/io/ljunggren/file/utils/FileUtils.java @@ -99,8 +99,8 @@ return Files.write(path, bytes, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); } - public static String writeToFile(String path, String content) throws IOException { - return writeToFile(path == null ? null : Paths.get(path), content).toString(); + public static Path writeToFile(String path, String content) throws IOException { + return writeToFile(path == null ? null : Paths.get(path), content); } public static Path writeToFile(Path path, String content) throws IOException { @@ -119,6 +119,15 @@ return writeToFile(path, contents == null ? null : String.join(NEW_LINE, contents)); } + public static Path writeToFile(InputStream inputStream, String path) throws IOException { + return writeToFile(inputStream, Paths.get(path)); + } + + public static Path writeToFile(InputStream inputStream, Path path) throws IOException { + Files.copy(inputStream, path, StandardCopyOption.REPLACE_EXISTING); + return path; + } + public static String appendToFile(String path, String content) throws IOException { return appendToFile(path, content, false); } @@ -340,8 +349,8 @@ return org.apache.commons.io.FileUtils.byteCountToDisplaySize(file.length()); } - public static void inputStreamToFile(InputStream source, File destination) throws IOException { - org.apache.commons.io.FileUtils.copyInputStreamToFile(source, destination); - } +// public static void inputStreamToFile(InputStream source, File destination) throws IOException { +// org.apache.commons.io.FileUtils.copyInputStreamToFile(source, destination); +// } }