diff --git a/src/org/omegat/util/TmxEscapingWriterFactory.java b/src/org/omegat/util/TmxEscapingWriterFactory.java index 19d152c413..985e9ecd28 100644 --- a/src/org/omegat/util/TmxEscapingWriterFactory.java +++ b/src/org/omegat/util/TmxEscapingWriterFactory.java @@ -28,7 +28,6 @@ import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; -import java.io.UnsupportedEncodingException; import java.io.Writer; import java.nio.charset.StandardCharsets; import java.util.Arrays; @@ -39,27 +38,25 @@ public class TmxEscapingWriterFactory implements EscapingWriterFactory { @Override - public Writer createEscapingWriterFor(final Writer writer, final String s) - throws UnsupportedEncodingException { + public Writer createEscapingWriterFor(@NotNull final Writer writer, final String s) { return new EscapeWriter(writer); } @Override - public Writer createEscapingWriterFor(final OutputStream outputStream, final String s) - throws UnsupportedEncodingException { + public Writer createEscapingWriterFor(@NotNull final OutputStream outputStream, final String s) { return new EscapeWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)); } public static class EscapeWriter extends Writer { // Copy from woodstox:com.ctc.wstx.sw.BufferingXmlWriter - private static final int[] QUOTABLE_TEXT_CHARS; + private static final byte[] QUOTABLE_TEXT_CHARS; private static final int HIGH_ENC = 0xFFFE; static { - int[] q = new int[4096]; - Arrays.fill(q, 0, 32, 1); - Arrays.fill(q, 127, 160, 1); + byte[] q = new byte[256]; + Arrays.fill(q, 0, 32, (byte) 1); + Arrays.fill(q, 127, 160, (byte) 1); q['\t'] = 0; q['\n'] = 0; q['<'] = 1; @@ -86,6 +83,7 @@ public EscapeWriter(@NotNull Writer delegate) { * @param len * Number of characters to write * @throws IOException + * when underlying writer object raises. */ @Override public void write(@NotNull final char[] cbuf, final int off, final int len) throws IOException { @@ -96,7 +94,7 @@ public void write(@NotNull final char[] cbuf, final int off, final int len) thro String ent = null; for (; offset < end; offset++) { int c = cbuf[offset]; - if (c < 4096 && QUOTABLE_TEXT_CHARS[c] != 0) { + if (c < 256 && QUOTABLE_TEXT_CHARS[c] != 0) { if (c == '<') { ent = "<"; break;