Skip to content

Commit 5c3555d

Browse files
committed
stored decoder into thread local variable
1 parent 7d231a9 commit 5c3555d

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/main/java/org/msgpack/type/ByteArrayRawValueImpl.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,19 @@
2929

3030
class ByteArrayRawValueImpl extends AbstractRawValue {
3131
private static ByteArrayRawValueImpl emptyInstance = new ByteArrayRawValueImpl(new byte[0], true);
32-
32+
3333
public static RawValue getEmptyInstance() {
3434
return emptyInstance;
3535
}
36+
37+
private static final ThreadLocal<CharsetDecoder> decoderStore = new ThreadLocal<CharsetDecoder>() {
38+
@Override
39+
protected CharsetDecoder initialValue() {
40+
return Charset.forName("UTF-8").newDecoder()
41+
.onMalformedInput(CodingErrorAction.REPORT)
42+
.onUnmappableCharacter(CodingErrorAction.REPORT);
43+
}
44+
};
3645

3746
private byte[] bytes;
3847

@@ -58,9 +67,7 @@ public byte[] getByteArray() {
5867

5968
@Override
6069
public String getString() {
61-
CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder()
62-
.onMalformedInput(CodingErrorAction.REPORT)
63-
.onUnmappableCharacter(CodingErrorAction.REPORT);
70+
CharsetDecoder decoder = decoderStore.get();
6471
try {
6572
return decoder.decode(ByteBuffer.wrap(bytes)).toString();
6673
} catch (CharacterCodingException ex) {

0 commit comments

Comments
 (0)