jdk/src/java.base/share/classes/java/lang/StringCoding.java
author simonis
Fri, 14 Aug 2015 10:35:45 +0200
changeset 32209 24bb680a1609
parent 25991 e48157b42439
child 32649 2ee9017c7597
permissions -rw-r--r--
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX Reviewed-by: rriggs, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 12858
diff changeset
     2
 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2294
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2294
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2294
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2294
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2294
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.UnsupportedEncodingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.lang.ref.SoftReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.nio.ByteBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.nio.CharBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.nio.charset.Charset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.nio.charset.CharsetDecoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.nio.charset.CharsetEncoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.nio.charset.CharacterCodingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.nio.charset.CoderResult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.nio.charset.CodingErrorAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.nio.charset.IllegalCharsetNameException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.nio.charset.UnsupportedCharsetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.misc.MessageUtils;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.nio.cs.HistoricallyNamedCharset;
2294
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
    43
import sun.nio.cs.ArrayDecoder;
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
    44
import sun.nio.cs.ArrayEncoder;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Utility class for string encoding and decoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
class StringCoding {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private StringCoding() { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
41
dfebd2609e77 6671834: (str) Eliminate StringCoding.java compile warnings
martin
parents: 2
diff changeset
    54
    /** The cached coders for each thread */
dfebd2609e77 6671834: (str) Eliminate StringCoding.java compile warnings
martin
parents: 2
diff changeset
    55
    private final static ThreadLocal<SoftReference<StringDecoder>> decoder =
7803
56bc97d69d93 6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents: 5506
diff changeset
    56
        new ThreadLocal<>();
41
dfebd2609e77 6671834: (str) Eliminate StringCoding.java compile warnings
martin
parents: 2
diff changeset
    57
    private final static ThreadLocal<SoftReference<StringEncoder>> encoder =
7803
56bc97d69d93 6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents: 5506
diff changeset
    58
        new ThreadLocal<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static boolean warnUnsupportedCharset = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
41
dfebd2609e77 6671834: (str) Eliminate StringCoding.java compile warnings
martin
parents: 2
diff changeset
    62
    private static <T> T deref(ThreadLocal<SoftReference<T>> tl) {
dfebd2609e77 6671834: (str) Eliminate StringCoding.java compile warnings
martin
parents: 2
diff changeset
    63
        SoftReference<T> sr = tl.get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        if (sr == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        return sr.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
41
dfebd2609e77 6671834: (str) Eliminate StringCoding.java compile warnings
martin
parents: 2
diff changeset
    69
    private static <T> void set(ThreadLocal<SoftReference<T>> tl, T ob) {
22581
e868cde95050 8032779: Update code in java.lang to use newer language features
psandoz
parents: 14342
diff changeset
    70
        tl.set(new SoftReference<>(ob));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    // Trim the given byte array to the given length
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    //
2294
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
    75
    private static byte[] safeTrim(byte[] ba, int len, Charset cs, boolean isTrusted) {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
    76
        if (len == ba.length && (isTrusted || System.getSecurityManager() == null))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            return ba;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            return Arrays.copyOf(ba, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    // Trim the given char array to the given length
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    //
2294
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
    84
    private static char[] safeTrim(char[] ca, int len,
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
    85
                                   Charset cs, boolean isTrusted) {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
    86
        if (len == ca.length && (isTrusted || System.getSecurityManager() == null))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            return ca;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            return Arrays.copyOf(ca, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private static int scale(int len, float expansionFactor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        // We need to perform double, not float, arithmetic; otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        // we lose low order bits when len is larger than 2**24.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        return (int)(len * (double)expansionFactor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private static Charset lookupCharset(String csn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        if (Charset.isSupported(csn)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                return Charset.forName(csn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            } catch (UnsupportedCharsetException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                throw new Error(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private static void warnUnsupportedCharset(String csn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (warnUnsupportedCharset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            // Use sun.misc.MessageUtils rather than the Logging API or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            // System.err since this method may be called during VM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            // initialization before either is available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            MessageUtils.err("WARNING: Default charset " + csn +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                             " not supported, using ISO-8859-1 instead");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            warnUnsupportedCharset = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    // -- Decoding --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private static class StringDecoder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        private final String requestedCharsetName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        private final Charset cs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        private final CharsetDecoder cd;
2294
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   126
        private final boolean isTrusted;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        private StringDecoder(Charset cs, String rcn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            this.requestedCharsetName = rcn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            this.cs = cs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            this.cd = cs.newDecoder()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                .onMalformedInput(CodingErrorAction.REPLACE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                .onUnmappableCharacter(CodingErrorAction.REPLACE);
2294
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   134
            this.isTrusted = (cs.getClass().getClassLoader0() == null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        String charsetName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            if (cs instanceof HistoricallyNamedCharset)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                return ((HistoricallyNamedCharset)cs).historicalName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            return cs.name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        final String requestedCharsetName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            return requestedCharsetName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        char[] decode(byte[] ba, int off, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            int en = scale(len, cd.maxCharsPerByte());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            char[] ca = new char[en];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            if (len == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                return ca;
2294
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   152
            if (cd instanceof ArrayDecoder) {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   153
                int clen = ((ArrayDecoder)cd).decode(ba, off, len, ca);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   154
                return safeTrim(ca, clen, cs, isTrusted);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   155
            } else {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   156
                cd.reset();
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   157
                ByteBuffer bb = ByteBuffer.wrap(ba, off, len);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   158
                CharBuffer cb = CharBuffer.wrap(ca);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   159
                try {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   160
                    CoderResult cr = cd.decode(bb, cb, true);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   161
                    if (!cr.isUnderflow())
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   162
                        cr.throwException();
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   163
                    cr = cd.flush(cb);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   164
                    if (!cr.isUnderflow())
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   165
                        cr.throwException();
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   166
                } catch (CharacterCodingException x) {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   167
                    // Substitution is always enabled,
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   168
                    // so this shouldn't happen
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   169
                    throw new Error(x);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   170
                }
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   171
                return safeTrim(ca, cb.position(), cs, isTrusted);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    static char[] decode(String charsetName, byte[] ba, int off, int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        throws UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    {
41
dfebd2609e77 6671834: (str) Eliminate StringCoding.java compile warnings
martin
parents: 2
diff changeset
   179
        StringDecoder sd = deref(decoder);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        String csn = (charsetName == null) ? "ISO-8859-1" : charsetName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if ((sd == null) || !(csn.equals(sd.requestedCharsetName())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                              || csn.equals(sd.charsetName()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            sd = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                Charset cs = lookupCharset(csn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                if (cs != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                    sd = new StringDecoder(cs, csn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            } catch (IllegalCharsetNameException x) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            if (sd == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                throw new UnsupportedEncodingException(csn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            set(decoder, sd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return sd.decode(ba, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    static char[] decode(Charset cs, byte[] ba, int off, int len) {
2294
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   197
        // (1)We never cache the "external" cs, the only benefit of creating
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   198
        // an additional StringDe/Encoder object to wrap it is to share the
25979
42e5d9f8087e 8054857: Fix typos in java.lang.** packages
prappo
parents: 22581
diff changeset
   199
        // de/encode() method. These SD/E objects are short-lived, the young-gen
42e5d9f8087e 8054857: Fix typos in java.lang.** packages
prappo
parents: 22581
diff changeset
   200
        // gc should be able to take care of them well. But the best approach
2294
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   201
        // is still not to generate them if not really necessary.
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   202
        // (2)The defensive copy of the input byte/char[] has a big performance
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   203
        // impact, as well as the outgoing result byte/char[]. Need to do the
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   204
        // optimization check of (sm==null && classLoader0==null) for both.
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   205
        // (3)getClass().getClassLoader0() is expensive
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   206
        // (4)There might be a timing gap in isTrusted setting. getClassLoader0()
25979
42e5d9f8087e 8054857: Fix typos in java.lang.** packages
prappo
parents: 22581
diff changeset
   207
        // is only checked (and then isTrusted gets set) when (SM==null). It is
2294
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   208
        // possible that the SM==null for now but then SM is NOT null later
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   209
        // when safeTrim() is invoked...the "safe" way to do is to redundant
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   210
        // check (... && (isTrusted || SM == null || getClassLoader0())) in trim
25979
42e5d9f8087e 8054857: Fix typos in java.lang.** packages
prappo
parents: 22581
diff changeset
   211
        // but it then can be argued that the SM is null when the operation
2294
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   212
        // is started...
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   213
        CharsetDecoder cd = cs.newDecoder();
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   214
        int en = scale(len, cd.maxCharsPerByte());
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   215
        char[] ca = new char[en];
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   216
        if (len == 0)
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   217
            return ca;
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   218
        boolean isTrusted = false;
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   219
        if (System.getSecurityManager() != null) {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   220
            if (!(isTrusted = (cs.getClass().getClassLoader0() == null))) {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   221
                ba =  Arrays.copyOfRange(ba, off, off + len);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   222
                off = 0;
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   223
            }
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   224
        }
9547
454881baaca0 7040220: java/char_encodin Optimize UTF-8 charset for String.getBytes()/new String(byte[])
sherman
parents: 9035
diff changeset
   225
        cd.onMalformedInput(CodingErrorAction.REPLACE)
454881baaca0 7040220: java/char_encodin Optimize UTF-8 charset for String.getBytes()/new String(byte[])
sherman
parents: 9035
diff changeset
   226
          .onUnmappableCharacter(CodingErrorAction.REPLACE)
454881baaca0 7040220: java/char_encodin Optimize UTF-8 charset for String.getBytes()/new String(byte[])
sherman
parents: 9035
diff changeset
   227
          .reset();
2294
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   228
        if (cd instanceof ArrayDecoder) {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   229
            int clen = ((ArrayDecoder)cd).decode(ba, off, len, ca);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   230
            return safeTrim(ca, clen, cs, isTrusted);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   231
        } else {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   232
            ByteBuffer bb = ByteBuffer.wrap(ba, off, len);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   233
            CharBuffer cb = CharBuffer.wrap(ca);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   234
            try {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   235
                CoderResult cr = cd.decode(bb, cb, true);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   236
                if (!cr.isUnderflow())
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   237
                    cr.throwException();
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   238
                cr = cd.flush(cb);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   239
                if (!cr.isUnderflow())
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   240
                    cr.throwException();
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   241
            } catch (CharacterCodingException x) {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   242
                // Substitution is always enabled,
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   243
                // so this shouldn't happen
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   244
                throw new Error(x);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   245
            }
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   246
            return safeTrim(ca, cb.position(), cs, isTrusted);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   247
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    static char[] decode(byte[] ba, int off, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        String csn = Charset.defaultCharset().name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        try {
12858
97e3f3f77254 6924259: Remove offset and count fields from java.lang.String
mduigou
parents: 9547
diff changeset
   253
            // use charset name decode() variant which provides caching.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            return decode(csn, ba, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        } catch (UnsupportedEncodingException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            warnUnsupportedCharset(csn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            return decode("ISO-8859-1", ba, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        } catch (UnsupportedEncodingException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            // If this code is hit during VM initialization, MessageUtils is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            // the only way we will be able to get any kind of error message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            MessageUtils.err("ISO-8859-1 charset not available: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                             + x.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            // If we can not find ISO-8859-1 (a required encoding) then things
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            // are seriously wrong with the installation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    // -- Encoding --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    private static class StringEncoder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        private Charset cs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        private CharsetEncoder ce;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        private final String requestedCharsetName;
2294
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   277
        private final boolean isTrusted;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        private StringEncoder(Charset cs, String rcn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            this.requestedCharsetName = rcn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            this.cs = cs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            this.ce = cs.newEncoder()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                .onMalformedInput(CodingErrorAction.REPLACE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                .onUnmappableCharacter(CodingErrorAction.REPLACE);
2294
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   285
            this.isTrusted = (cs.getClass().getClassLoader0() == null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        String charsetName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            if (cs instanceof HistoricallyNamedCharset)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                return ((HistoricallyNamedCharset)cs).historicalName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            return cs.name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        final String requestedCharsetName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            return requestedCharsetName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        byte[] encode(char[] ca, int off, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            int en = scale(len, ce.maxBytesPerChar());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            byte[] ba = new byte[en];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            if (len == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                return ba;
2294
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   303
            if (ce instanceof ArrayEncoder) {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   304
                int blen = ((ArrayEncoder)ce).encode(ca, off, len, ba);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   305
                return safeTrim(ba, blen, cs, isTrusted);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   306
            } else {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   307
                ce.reset();
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   308
                ByteBuffer bb = ByteBuffer.wrap(ba);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   309
                CharBuffer cb = CharBuffer.wrap(ca, off, len);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   310
                try {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   311
                    CoderResult cr = ce.encode(cb, bb, true);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   312
                    if (!cr.isUnderflow())
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   313
                        cr.throwException();
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   314
                    cr = ce.flush(bb);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   315
                    if (!cr.isUnderflow())
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   316
                        cr.throwException();
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   317
                } catch (CharacterCodingException x) {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   318
                    // Substitution is always enabled,
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   319
                    // so this shouldn't happen
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   320
                    throw new Error(x);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   321
                }
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   322
                return safeTrim(ba, bb.position(), cs, isTrusted);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    static byte[] encode(String charsetName, char[] ca, int off, int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        throws UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    {
41
dfebd2609e77 6671834: (str) Eliminate StringCoding.java compile warnings
martin
parents: 2
diff changeset
   330
        StringEncoder se = deref(encoder);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        String csn = (charsetName == null) ? "ISO-8859-1" : charsetName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if ((se == null) || !(csn.equals(se.requestedCharsetName())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                              || csn.equals(se.charsetName()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            se = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                Charset cs = lookupCharset(csn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                if (cs != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                    se = new StringEncoder(cs, csn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            } catch (IllegalCharsetNameException x) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            if (se == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                throw new UnsupportedEncodingException (csn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            set(encoder, se);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        return se.encode(ca, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    static byte[] encode(Charset cs, char[] ca, int off, int len) {
2294
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   348
        CharsetEncoder ce = cs.newEncoder();
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   349
        int en = scale(len, ce.maxBytesPerChar());
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   350
        byte[] ba = new byte[en];
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   351
        if (len == 0)
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   352
            return ba;
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   353
        boolean isTrusted = false;
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   354
        if (System.getSecurityManager() != null) {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   355
            if (!(isTrusted = (cs.getClass().getClassLoader0() == null))) {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   356
                ca =  Arrays.copyOfRange(ca, off, off + len);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   357
                off = 0;
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   358
            }
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   359
        }
9547
454881baaca0 7040220: java/char_encodin Optimize UTF-8 charset for String.getBytes()/new String(byte[])
sherman
parents: 9035
diff changeset
   360
        ce.onMalformedInput(CodingErrorAction.REPLACE)
454881baaca0 7040220: java/char_encodin Optimize UTF-8 charset for String.getBytes()/new String(byte[])
sherman
parents: 9035
diff changeset
   361
          .onUnmappableCharacter(CodingErrorAction.REPLACE)
454881baaca0 7040220: java/char_encodin Optimize UTF-8 charset for String.getBytes()/new String(byte[])
sherman
parents: 9035
diff changeset
   362
          .reset();
2294
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   363
        if (ce instanceof ArrayEncoder) {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   364
            int blen = ((ArrayEncoder)ce).encode(ca, off, len, ba);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   365
            return safeTrim(ba, blen, cs, isTrusted);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   366
        } else {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   367
            ByteBuffer bb = ByteBuffer.wrap(ba);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   368
            CharBuffer cb = CharBuffer.wrap(ca, off, len);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   369
            try {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   370
                CoderResult cr = ce.encode(cb, bb, true);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   371
                if (!cr.isUnderflow())
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   372
                    cr.throwException();
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   373
                cr = ce.flush(bb);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   374
                if (!cr.isUnderflow())
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   375
                    cr.throwException();
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   376
            } catch (CharacterCodingException x) {
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   377
                throw new Error(x);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   378
            }
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   379
            return safeTrim(ba, bb.position(), cs, isTrusted);
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 715
diff changeset
   380
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    static byte[] encode(char[] ca, int off, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        String csn = Charset.defaultCharset().name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        try {
12858
97e3f3f77254 6924259: Remove offset and count fields from java.lang.String
mduigou
parents: 9547
diff changeset
   386
            // use charset name encode() variant which provides caching.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            return encode(csn, ca, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        } catch (UnsupportedEncodingException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            warnUnsupportedCharset(csn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            return encode("ISO-8859-1", ca, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        } catch (UnsupportedEncodingException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            // If this code is hit during VM initialization, MessageUtils is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            // the only way we will be able to get any kind of error message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            MessageUtils.err("ISO-8859-1 charset not available: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                             + x.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            // If we can not find ISO-8859-1 (a required encoding) then things
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            // are seriously wrong with the installation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
}