Skip to content

Commit 4ab417e

Browse files
Merge pull request Keysight#71 from Keysight/bugfix/1-utf8decoder-is-shared
Keysight#1: The UTF8Decoder should not be a static final
2 parents 953014d + 9fab245 commit 4ab417e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/main/java/com/riscure/trs/TraceSet.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public class TraceSet implements AutoCloseable {
3636
private static final String UNKNOWN_SAMPLE_CODING = "Error reading TRS file: unknown sample coding '%d'";
3737
private static final long MAX_BUFFER_SIZE = Integer.MAX_VALUE;
3838
private static final String PARAMETER_NOT_DEFINED = "Parameter %s is saved in the trace, but was not found in the header definition";
39-
private static final CharsetDecoder UTF8_DECODER = StandardCharsets.UTF_8.newDecoder();
4039

4140
//Reading variables
4241
private int metaDataSize;
@@ -56,9 +55,11 @@ public class TraceSet implements AutoCloseable {
5655

5756
//Shared variables
5857
private final TRSMetaData metaData;
59-
private boolean open;
6058
private final boolean writing; //whether the trace is opened in write mode
6159
private final Path path;
60+
private final CharsetDecoder utf8Decoder = StandardCharsets.UTF_8.newDecoder();
61+
62+
private boolean open;
6263

6364
private TraceSet(String inputFileName) throws IOException, TRSFormatException {
6465
this.writing = false;
@@ -244,10 +245,10 @@ private String fitUtf8StringToByteLength(String s, int maxBytes) {
244245
ByteBuffer bb = ByteBuffer.wrap(sba, 0, maxBytes);
245246
CharBuffer cb = CharBuffer.allocate(maxBytes);
246247
// Ignore an incomplete character
247-
UTF8_DECODER.reset();
248-
UTF8_DECODER.onMalformedInput(CodingErrorAction.IGNORE);
249-
UTF8_DECODER.decode(bb, cb, true);
250-
UTF8_DECODER.flush(cb);
248+
utf8Decoder.reset();
249+
utf8Decoder.onMalformedInput(CodingErrorAction.IGNORE);
250+
utf8Decoder.decode(bb, cb, true);
251+
utf8Decoder.flush(cb);
251252
return new String(cb.array(), 0, cb.position());
252253
}
253254

0 commit comments

Comments
 (0)