/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Utility class for string encoding and decoding.
*/
class StringCoding {
private StringCoding() { }
/** The cached coders for each thread */
new ThreadLocal<>();
new ThreadLocal<>();
private static boolean warnUnsupportedCharset = true;
return null;
}
}
// Trim the given byte array to the given length
//
return ba;
else
}
// Trim the given char array to the given length
//
return ca;
else
}
// We need to perform double, not float, arithmetic; otherwise
// we lose low order bits when len is larger than 2**24.
return (int)(len * (double)expansionFactor);
}
try {
} catch (UnsupportedCharsetException x) {
throw new Error(x);
}
}
return null;
}
if (warnUnsupportedCharset) {
// Use sun.misc.MessageUtils rather than the Logging API or
// System.err since this method may be called during VM
// initialization before either is available.
" not supported, using ISO-8859-1 instead");
warnUnsupportedCharset = false;
}
}
// -- Decoding --
private static class StringDecoder {
private final boolean isTrusted;
this.requestedCharsetName = rcn;
}
if (cs instanceof HistoricallyNamedCharset)
}
return requestedCharsetName;
}
if (len == 0)
return ca;
if (cd instanceof ArrayDecoder) {
} else {
try {
if (!cr.isUnderflow())
cr.throwException();
if (!cr.isUnderflow())
cr.throwException();
} catch (CharacterCodingException x) {
// Substitution is always enabled,
// so this shouldn't happen
throw new Error(x);
}
}
}
}
throws UnsupportedEncodingException
{
try {
} catch (IllegalCharsetNameException x) {}
throw new UnsupportedEncodingException(csn);
}
}
// (1)We never cache the "external" cs, the only benefit of creating
// gc should be able to take care of them well. But the best approash
// is still not to generate them if not really necessary.
// optimization check of (sm==null && classLoader0==null) for both.
// (3)getClass().getClassLoader0() is expensive
// (4)There might be a timing gap in isTrusted setting. getClassLoader0()
// is only chcked (and then isTrusted gets set) when (SM==null). It is
// possible that the SM==null for now but then SM is NOT null later
// when safeTrim() is invoked...the "safe" way to do is to redundant
// check (... && (isTrusted || SM == null || getClassLoader0())) in trim
// but it then can be argued that the SM is null when the opertaion
// is started...
if (len == 0)
return ca;
boolean isTrusted = false;
off = 0;
}
}
.reset();
if (cd instanceof ArrayDecoder) {
} else {
try {
if (!cr.isUnderflow())
cr.throwException();
if (!cr.isUnderflow())
cr.throwException();
} catch (CharacterCodingException x) {
// Substitution is always enabled,
// so this shouldn't happen
throw new Error(x);
}
}
}
try {
// use charset name decode() variant which provides caching.
} catch (UnsupportedEncodingException x) {
}
try {
} catch (UnsupportedEncodingException x) {
// If this code is hit during VM initialization, MessageUtils is
// the only way we will be able to get any kind of error message.
+ x.toString());
// If we can not find ISO-8859-1 (a required encoding) then things
// are seriously wrong with the installation.
return null;
}
}
// -- Encoding --
private static class StringEncoder {
private final boolean isTrusted;
this.requestedCharsetName = rcn;
}
if (cs instanceof HistoricallyNamedCharset)
}
return requestedCharsetName;
}
if (len == 0)
return ba;
if (ce instanceof ArrayEncoder) {
} else {
try {
if (!cr.isUnderflow())
cr.throwException();
if (!cr.isUnderflow())
cr.throwException();
} catch (CharacterCodingException x) {
// Substitution is always enabled,
// so this shouldn't happen
throw new Error(x);
}
}
}
}
throws UnsupportedEncodingException
{
try {
} catch (IllegalCharsetNameException x) {}
throw new UnsupportedEncodingException (csn);
}
}
if (len == 0)
return ba;
boolean isTrusted = false;
off = 0;
}
}
.reset();
if (ce instanceof ArrayEncoder) {
} else {
try {
if (!cr.isUnderflow())
cr.throwException();
if (!cr.isUnderflow())
cr.throwException();
} catch (CharacterCodingException x) {
throw new Error(x);
}
}
}
try {
// use charset name encode() variant which provides caching.
} catch (UnsupportedEncodingException x) {
}
try {
} catch (UnsupportedEncodingException x) {
// If this code is hit during VM initialization, MessageUtils is
// the only way we will be able to get any kind of error message.
+ x.toString());
// If we can not find ISO-8859-1 (a required encoding) then things
// are seriously wrong with the installation.
return null;
}
}
}