|
|
@@ -19,6 +19,8 @@ import java.io.OutputStreamWriter;
|
|
|
import java.io.Reader;
|
|
|
import java.io.Writer;
|
|
|
import java.nio.charset.Charset;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
@@ -32,10 +34,18 @@ public final class IOStrings {
|
|
|
|
|
|
private IOStrings() { }
|
|
|
|
|
|
+ public static Reader reader(Path path, Charset cs) throws IOException {
|
|
|
+ return reader(path.toFile(), cs);
|
|
|
+ }
|
|
|
+
|
|
|
public static Reader reader(File file, Charset cs) throws IOException {
|
|
|
return new InputStreamReader(new FileInputStream(file), cs);
|
|
|
}
|
|
|
|
|
|
+ public static Writer writer(Path path, Charset cs) throws IOException {
|
|
|
+ return writer(path.toFile(), cs);
|
|
|
+ }
|
|
|
+
|
|
|
public static Writer writer(File file, Charset cs) throws IOException {
|
|
|
return new OutputStreamWriter(new FileOutputStream(file), cs);
|
|
|
}
|
|
|
@@ -56,6 +66,10 @@ public final class IOStrings {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static void write(Path path, String content, Charset charset) throws IOException {
|
|
|
+ write(path.toFile(), content, charset);
|
|
|
+ }
|
|
|
+
|
|
|
public static void write(File file, String content, Charset charset) throws IOException {
|
|
|
write(new FileOutputStream(file), content, charset);
|
|
|
}
|
|
|
@@ -82,6 +96,10 @@ public final class IOStrings {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static String read(Path path, Charset charset) throws IOException {
|
|
|
+ return read(path.toFile(), charset);
|
|
|
+ }
|
|
|
+
|
|
|
public static String read(File file, Charset charset) throws IOException {
|
|
|
return read( new FileInputStream(file), charset );
|
|
|
}
|
|
|
@@ -102,6 +120,10 @@ public final class IOStrings {
|
|
|
return readLines(new BufferedReader(new InputStreamReader(istream, charset)));
|
|
|
}
|
|
|
|
|
|
+ public static List<String> readLines(Path path, Charset charset) throws IOException {
|
|
|
+ return Files.readAllLines(path, charset);
|
|
|
+ }
|
|
|
+
|
|
|
public static List<String> readLines(File file, Charset charset) throws IOException {
|
|
|
return readLines(new FileInputStream(file), charset);
|
|
|
}
|
|
|
@@ -119,6 +141,10 @@ public final class IOStrings {
|
|
|
writeLines(new OutputStreamWriter(ostream, charset), content);
|
|
|
}
|
|
|
|
|
|
+ public static void writeLines(Path path, Charset charset, Iterator<String> content) throws IOException {
|
|
|
+ writeLines(path.toFile(), charset, content);
|
|
|
+ }
|
|
|
+
|
|
|
public static void writeLines(File file, Charset charset, Iterator<String> content) throws IOException {
|
|
|
writeLines(new FileOutputStream(file), charset, content);
|
|
|
}
|
|
|
@@ -131,6 +157,10 @@ public final class IOStrings {
|
|
|
writeLines(ostream, charset, content.iterator());
|
|
|
}
|
|
|
|
|
|
+ public static void writeLines(Path path, Charset charset, Iterable<String> content) throws IOException {
|
|
|
+ writeLines(path.toFile(), charset, content);
|
|
|
+ }
|
|
|
+
|
|
|
public static void writeLines(File file, Charset charset, Iterable<String> content) throws IOException {
|
|
|
writeLines(file, charset, content.iterator());
|
|
|
}
|