Skip to content

Commit 4a5ced5

Browse files
committed
add file shorthands
1 parent 22205e7 commit 4a5ced5

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

json/src/main/java/alpine/json/Json.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package alpine.json;
22

3-
import java.io.IOException;
3+
import java.io.*;
44
import java.nio.file.Files;
55
import java.nio.file.Path;
66
import java.util.Map;
@@ -73,6 +73,10 @@ public static Element read(Path path) throws ParsingException {
7373
}
7474
}
7575

76+
public static Element read(File file) throws ParsingException {
77+
return read(file.toPath());
78+
}
79+
7680
public static String write(Element element, Formatting formatting) {
7781
return WRITER.write(element, formatting);
7882
}
@@ -85,6 +89,10 @@ public static void write(Path path, Element element, Formatting formatting) {
8589
}
8690
}
8791

92+
public static void write(File file, Element element, Formatting formatting) {
93+
write(file.toPath(), element, formatting);
94+
}
95+
8896
static boolean isControl(char character) {
8997
return character <= 0x1F;
9098
}
@@ -99,13 +107,13 @@ static boolean isWhitespace(char character) {
99107
public record Formatting(String indentation, String newLine, String comma, String colon) {
100108
public static final Formatting COMPACT = new Formatting(
101109
"",
102-
String.valueOf(LINE_FEED),
110+
System.lineSeparator(),
103111
String.valueOf(COMMA),
104112
String.valueOf(COLON));
105113

106114
public static final Formatting PRETTY = new Formatting(
107115
String.valueOf(SPACE).repeat(4),
108-
String.valueOf(LINE_FEED),
116+
System.lineSeparator(),
109117
COMPACT.comma + SPACE,
110118
COMPACT.colon + SPACE);
111119
}

0 commit comments

Comments
 (0)