langtools/test/tools/javac/4846262/Native2Ascii.java
author shade
Tue, 02 Feb 2016 18:15:15 +0300
changeset 35639 f34e7e8b4eac
parent 30844 a33cd63c54ef
permissions -rw-r--r--
8148787: StringConcatFactory exactness check produces bad bytecode when a non-arg concat is requested Reviewed-by: vlivanov, psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30844
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
     1
/*
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
     4
 *
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
     8
 *
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    13
 * accompanied this code).
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    14
 *
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    18
 *
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    21
 * questions.
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    22
 */
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    23
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    24
import java.io.BufferedReader;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    25
import java.io.BufferedWriter;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    26
import java.io.FilterReader;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    27
import java.io.FilterWriter;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    28
import java.io.IOException;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    29
import java.io.Reader;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    30
import java.io.Writer;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    31
import java.nio.charset.Charset;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    32
import java.nio.charset.CharsetEncoder;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    33
import java.nio.file.Files;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    34
import java.nio.file.Path;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    35
import static java.nio.charset.StandardCharsets.*;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    36
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    37
/**
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    38
 * Simple utility to convert from native encoding file to ascii or reverse
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    39
 * including \udddd Unicode notation.
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    40
 */
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    41
public class Native2Ascii {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    42
    final Charset cs;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    43
    final CharsetEncoder encoder;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    44
    public Native2Ascii(Charset cs) {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    45
        this.cs = cs;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    46
        this.encoder = cs.newEncoder();
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    47
    }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    48
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    49
    /**
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    50
     * ASCII to Native conversion
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    51
     */
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    52
    public void asciiToNative(Path infile, Path outfile) throws IOException {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    53
        try (BufferedReader in = Files.newBufferedReader(infile, US_ASCII);
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    54
             BufferedReader reader = new BufferedReader(new A2NFilter(in));
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    55
             BufferedWriter writer = Files.newBufferedWriter(outfile, cs)) {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    56
            String line;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    57
            while ((line = reader.readLine()) != null) {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    58
                writer.write(line.toCharArray());
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    59
                writer.newLine();
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    60
            }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    61
        }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    62
    }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    63
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    64
    /**
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    65
     * Native to ASCII conversion
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    66
     */
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    67
    public void nativeToAscii(Path infile, Path outfile) throws IOException {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    68
        try (BufferedReader reader = Files.newBufferedReader(infile, cs);
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    69
             BufferedWriter out = Files.newBufferedWriter(outfile, US_ASCII);
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    70
             BufferedWriter writer = new BufferedWriter(new N2AFilter(out))) {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    71
            String line;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    72
            while ((line = reader.readLine()) != null) {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    73
                writer.write(line.toCharArray());
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    74
                writer.newLine();
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    75
            }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    76
        }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    77
    }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    78
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    79
    // A copy of native2ascii N2AFilter
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    80
    class N2AFilter extends FilterWriter {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    81
        public N2AFilter(Writer out) { super(out); }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    82
        public void write(char b) throws IOException {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    83
            char[] buf = new char[1];
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    84
            buf[0] = b;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    85
            write(buf, 0, 1);
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    86
        }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    87
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    88
        public void write(char[] buf, int off, int len) throws IOException {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    89
            for (int i = 0; i < len; i++) {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    90
                if ((buf[i] > '\u007f')) {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    91
                    // write \udddd
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    92
                    out.write('\\');
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    93
                    out.write('u');
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    94
                    String hex = Integer.toHexString(buf[i]);
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    95
                    StringBuilder hex4 = new StringBuilder(hex);
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    96
                    hex4.reverse();
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    97
                    int length = 4 - hex4.length();
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    98
                    for (int j = 0; j < length; j++) {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
    99
                        hex4.append('0');
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   100
                    }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   101
                    for (int j = 0; j < 4; j++) {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   102
                        out.write(hex4.charAt(3 - j));
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   103
                    }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   104
                } else
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   105
                    out.write(buf[i]);
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   106
            }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   107
        }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   108
    }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   109
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   110
    // A copy of native2ascii A2NFilter
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   111
    class A2NFilter extends FilterReader {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   112
        // maintain a trailing buffer to hold any incompleted
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   113
        // unicode escaped sequences
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   114
        private char[] trailChars = null;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   115
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   116
        public A2NFilter(Reader in) {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   117
            super(in);
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   118
        }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   119
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   120
        public int read(char[] buf, int off, int len) throws IOException {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   121
            int numChars = 0;        // how many characters have been read
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   122
            int retChars = 0;        // how many characters we'll return
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   123
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   124
            char[] cBuf = new char[len];
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   125
            int cOffset = 0;         // offset at which we'll start reading
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   126
            boolean eof = false;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   127
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   128
            // copy trailing chars from previous invocation to input buffer
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   129
            if (trailChars != null) {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   130
                for (int i = 0; i < trailChars.length; i++)
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   131
                    cBuf[i] = trailChars[i];
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   132
                numChars = trailChars.length;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   133
                trailChars = null;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   134
            }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   135
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   136
            int n = in.read(cBuf, numChars, len - numChars);
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   137
            if (n < 0) {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   138
                eof = true;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   139
                if (numChars == 0)
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   140
                    return -1;              // EOF;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   141
            } else {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   142
                numChars += n;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   143
            }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   144
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   145
            for (int i = 0; i < numChars; ) {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   146
                char c = cBuf[i++];
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   147
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   148
                if (c != '\\' || (eof && numChars <= 5)) {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   149
                    // Not a backslash, so copy and continue
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   150
                    // Always pass non backslash chars straight thru
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   151
                    // for regular encoding. If backslash occurs in
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   152
                    // input stream at the final 5 chars then don't
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   153
                    // attempt to read-ahead and de-escape since these
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   154
                    // are literal occurrences of U+005C which need to
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   155
                    // be encoded verbatim in the target encoding.
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   156
                    buf[retChars++] = c;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   157
                    continue;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   158
                }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   159
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   160
                int remaining = numChars - i;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   161
                if (remaining < 5) {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   162
                    // Might be the first character of a unicode escape, but we
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   163
                    // don't have enough characters to tell, so save it and finish
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   164
                    trailChars = new char[1 + remaining];
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   165
                    trailChars[0] = c;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   166
                    for (int j = 0; j < remaining; j++)
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   167
                        trailChars[1 + j] = cBuf[i + j];
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   168
                    break;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   169
                }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   170
                // At this point we have at least five characters remaining
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   171
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   172
                c = cBuf[i++];
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   173
                if (c != 'u') {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   174
                    // Not a unicode escape, so copy and continue
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   175
                    buf[retChars++] = '\\';
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   176
                    buf[retChars++] = c;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   177
                    continue;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   178
                }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   179
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   180
                // The next four characters are the hex part of a unicode escape
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   181
                char rc = 0;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   182
                boolean isUE = true;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   183
                try {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   184
                    rc = (char) Integer.parseInt(new String(cBuf, i, 4), 16);
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   185
                } catch (NumberFormatException x) {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   186
                    isUE = false;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   187
                }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   188
                if (isUE && encoder.canEncode(rc)) {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   189
                    // We'll be able to convert this
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   190
                    buf[retChars++] = rc;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   191
                    i += 4; // Align beyond the current uXXXX sequence
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   192
                } else {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   193
                    // We won't, so just retain the original sequence
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   194
                    buf[retChars++] = '\\';
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   195
                    buf[retChars++] = 'u';
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   196
                    continue;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   197
                }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   198
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   199
            }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   200
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   201
            return retChars;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   202
        }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   203
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   204
        public int read() throws IOException {
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   205
            char[] buf = new char[1];
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   206
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   207
            if (read(buf, 0, 1) == -1)
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   208
                return -1;
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   209
            else
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   210
                return (int) buf[0];
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   211
        }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   212
    }
a33cd63c54ef 8074431: Remove native2ascii tool
mchung
parents:
diff changeset
   213
}