8305902: (cs) Resolve default Charset only once in StreamEncoder and StreamDecoder

Reviewed-by: alanb, bpb
This commit is contained in:
Sergey Tsypanov 2023-04-14 06:21:39 +00:00 committed by Alan Bateman
parent 8a1639d49b
commit 287bb06def
2 changed files with 6 additions and 14 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -71,14 +71,10 @@ public class StreamDecoder extends Reader {
String charsetName)
throws UnsupportedEncodingException
{
String csn = charsetName;
if (csn == null) {
csn = Charset.defaultCharset().name();
}
try {
return new StreamDecoder(in, lock, Charset.forName(csn));
return new StreamDecoder(in, lock, Charset.forName(charsetName));
} catch (IllegalCharsetNameException | UnsupportedCharsetException x) {
throw new UnsupportedEncodingException (csn);
throw new UnsupportedEncodingException (charsetName);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -58,14 +58,10 @@ public final class StreamEncoder extends Writer {
String charsetName)
throws UnsupportedEncodingException
{
String csn = charsetName;
if (csn == null) {
csn = Charset.defaultCharset().name();
}
try {
return new StreamEncoder(out, lock, Charset.forName(csn));
return new StreamEncoder(out, lock, Charset.forName(charsetName));
} catch (IllegalCharsetNameException | UnsupportedCharsetException x) {
throw new UnsupportedEncodingException (csn);
throw new UnsupportedEncodingException (charsetName);
}
}