Skip to content

Commit 391d4e3

Browse files
committed
Avoid reading char by char by using a 4k buffer
This also removes the need for BufferedReader.
1 parent 58fc76f commit 391d4e3

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

core/src/main/java/com/github/jsonldjava/utils/JSONUtils.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,10 @@ public static Object fromString(String jsonString) throws JsonParseException,
129129

130130
public static Object fromReader(Reader r) throws IOException {
131131
final StringBuffer sb = new StringBuffer();
132+
char[] buffer = new char[4096];
132133
int b;
133-
while ((b = r.read()) != -1) {
134-
sb.append((char) b);
134+
while ((b = r.read(buffer)) != -1) {
135+
sb.append(buffer, 0, b);
135136
}
136137
return fromString(sb.toString());
137138
}
@@ -159,7 +160,7 @@ public static Object fromInputStream(InputStream content) throws IOException {
159160
}
160161

161162
public static Object fromInputStream(InputStream content, String enc) throws IOException {
162-
return fromReader(new BufferedReader(new InputStreamReader(content, enc)));
163+
return fromReader(new InputStreamReader(content, enc));
163164
}
164165

165166
public static String toPrettyString(Object obj) {

0 commit comments

Comments
 (0)