StringCoding.java revision 3386
2362N/A * Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * Utility class for string encoding and decoding. 18N/A /** The cached coders for each thread */ 0N/A // Trim the given byte array to the given length 0N/A // Trim the given char array to the given length 0N/A // We need to perform double, not float, arithmetic; otherwise 0N/A // we lose low order bits when len is larger than 2**24. 0N/A // Use sun.misc.MessageUtils rather than the Logging API or 0N/A // System.err since this method may be called during VM 0N/A // initialization before either is available. 0N/A " not supported, using ISO-8859-1 instead");
964N/A // Substitution is always enabled, 964N/A // so this shouldn't happen 964N/A // (1)We never cache the "external" cs, the only benefit of creating 964N/A // de/encode() method. These SD/E objects are short-lifed, the young-gen 964N/A // gc should be able to take care of them well. But the best approash 964N/A // is still not to generate them if not really necessary. 964N/A // (2)The defensive copy of the input byte/char[] has a big performance 964N/A // impact, as well as the outgoing result byte/char[]. Need to do the 964N/A // optimization check of (sm==null && classLoader0==null) for both. 964N/A // (3)getClass().getClassLoader0() is expensive 964N/A // (4)There might be a timing gap in isTrusted setting. getClassLoader0() 964N/A // is only chcked (and then isTrusted gets set) when (SM==null). It is 964N/A // possible that the SM==null for now but then SM is NOT null later 964N/A // when safeTrim() is invoked...the "safe" way to do is to redundant 964N/A // check (... && (isTrusted || SM == null || getClassLoader0())) in trim 964N/A // but it then can be argued that the SM is null when the opertaion 964N/A // Substitution is always enabled, 964N/A // so this shouldn't happen 0N/A // If this code is hit during VM initialization, MessageUtils is 0N/A // the only way we will be able to get any kind of error message. 0N/A // If we can not find ISO-8859-1 (a required encoding) then things 0N/A // are seriously wrong with the installation. 964N/A // Substitution is always enabled, 964N/A // so this shouldn't happen 0N/A // If this code is hit during VM initialization, MessageUtils is 0N/A // the only way we will be able to get any kind of error message. 0N/A // If we can not find ISO-8859-1 (a required encoding) then things 0N/A // are seriously wrong with the installation.