Skip to content

Commit

Permalink
Added a BufferedReader.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Cover jdcove2 committed Nov 1, 2024
1 parent 110f82b commit 5201952
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/main/java/emissary/core/IBaseDataObjectXmlCodecs.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -843,17 +844,19 @@ public static boolean requiresEncoding(final byte[] utf8Bytes) {

// https://stackoverflow.com/questions/3770117/what-is-the-range-of-unicode-printable-characters
public static boolean requiresEncoding(final Reader reader) throws IOException {
int c;
while ((c = reader.read()) >= 0) {
if (('\u0000' <= c && c <= '\u0008') ||
('\u000E' <= c && c <= '\u001F') ||
('\u007F' <= c && c <= '\u009F') ||
('\u2000' <= c && c <= '\u200F') ||
('\u2028' <= c && c <= '\u202F') ||
('\u205F' <= c && c <= '\u206F') ||
c == '\u3000' || c == '\uFEFF' ||
c == '\uFFFD') { // UTF-8 Error Replacement Character
return true;
try (BufferedReader bufferedReader = new BufferedReader(reader)) {
int c;
while ((c = bufferedReader.read()) >= 0) {
if (('\u0000' <= c && c <= '\u0008') ||
('\u000E' <= c && c <= '\u001F') ||
('\u007F' <= c && c <= '\u009F') ||
('\u2000' <= c && c <= '\u200F') ||
('\u2028' <= c && c <= '\u202F') ||
('\u205F' <= c && c <= '\u206F') ||
c == '\u3000' || c == '\uFEFF' ||
c == '\uFFFD') { // UTF-8 Error Replacement Character
return true;
}
}
}

Expand Down

0 comments on commit 5201952

Please sign in to comment.