1 /*
   2  * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25    @bug 4626545 4879522 4913711 4119445 8211382
  26    @summary Check full coverage encode/decode for ISO-2022-JP
  27  */
  28 
  29 /*
  30  * Tests the NIO converter for J2RE >= 1.4.1
  31  * since the default converter used by String
  32  * API is the NIO converter sun.nio.cs.ext.ISO2022_JP
  33  */
  34 
  35 import java.io.*;
  36 public class TestISO2022JP {
  37 
  38     private final static String US_ASCII =
  39         "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007" +
  40         "\b\t\n\u000B\f\r" +
  41         "\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017" +
  42         "\u0018\u0019\u001A\u001C\u001D\u001E\u001F" +
  43         "\u0020\u0021\"\u0023\u0024\u0025\u0026\'" +
  44         "\u0028\u0029\u002A\u002B\u002C\u002D\u002E\u002F" +
  45         "\u0030\u0031\u0032\u0033\u0034\u0035\u0036\u0037" +
  46         "\u0038\u0039\u003A\u003B\u003C\u003D\u003E\u003F" +
  47         "\u0040\u0041\u0042\u0043\u0044\u0045\u0046\u0047" +
  48         "\u0048\u0049\u004A\u004B\u004C\u004D\u004E\u004F" +
  49         "\u0050\u0051\u0052\u0053\u0054\u0055\u0056\u0057" +
  50         "\u0058\u0059\u005A\u005B\\\u005D\u005E\u005F" +
  51         "\u0060\u0061\u0062\u0063\u0064\u0065\u0066\u0067" +
  52         "\u0068\u0069\u006A\u006B\u006C\u006D\u006E\u006F" +
  53         "\u0070\u0071\u0072\u0073\u0074\u0075\u0076\u0077" +
  54         "\u0078\u0079\u007A\u007B\u007C\u007D\u007E\u00A5\u203E";
  55 
  56      // Subset of chars sourced from JISX0208:1983
  57 
  58      private final static String JISX0208SUBSET =
  59         "u3000\u3001\u3002\uFF0C\uFF0E\u30FB\uFF1A" +
  60         "\uFF1B\uFF1F\uFF01\u309B\u309C\u00B4\uFF40\u00A8" +
  61         "\uFF3E\uFFE3\uFF3F\u30FD\u30FE\u309D\u309E\u3003" +
  62         "\u4EDD\u3005\u3006\u3007\u30FC\u2014\u2010\uFF0F" +
  63         "\uFF3C\u301C\u2016\uFF5C\u2026\u2025\u2018\u2019" +
  64         "\u5C05\u5C07\u5C08\u5C0D\u5C13\u5C20\u5C22\u5C28" +
  65         "\u5C38\u5C39\u5C41\u5C46\u5C4E\u5C53\u5C50\u5C4F" +
  66         "\u5B71\u5C6C\u5C6E\u4E62\u5C76\u5C79\u5C8C\u5C91" +
  67         "\u5C94\u599B\u5CAB\u5CBB\u5CB6\u5CBC\u5CB7\u5CC5" +
  68         "\u5CBE\u5CC7\u5CD9\u5CE9\u5CFD\u5CFA\u5CED\u5D8C" +
  69         "\u5CEA\u5D0B\u5D15\u5D17\u5D5C\u5D1F\u5D1B\u5D11" +
  70         "\u5D14\u5D22\u5D1A\u5D19\u5D18\u5D4C\u5D52\u5D4E" +
  71         "\u5D4B\u5D6C\u5D73\u5D76\u5D87\u5D84\u5D82\u5DA2" +
  72         "\u5D9D\u5DAC\u5DAE\u5DBD\u5D90\u5DB7\u5DBC\u5DC9" +
  73         "\u5DCD\u5DD3\u5DD2\u5DD6\u5DDB\u5DEB\u5DF2\u5DF5" +
  74         "\u5E0B\u5E1A\u5E19\u5E11\u5E1B\u5E36\u5E37\u5E44" +
  75         "\u5E43\u5E40\u5E4E\u5E57\u5E54\u5E5F\u5E62\u5E64" +
  76         "\u5E47\u5E75\u5E76\u5E7A\u9EBC\u5E7F\u5EA0\u5EC1" +
  77         "\u5EC2\u5EC8\u5ED0\u5ECF\u5ED6\u5EE3\u5EDD\u5EDA" +
  78         "\u5EDB\u5EE2\u5EE1\u5EE8\u5EE9\u5EEC\u5EF1\u5EF3" +
  79         "\u5EF0\u5EF4\u5EF8\u5EFE\u5F03\u5F09\u5F5D\u5F5C" +
  80         "\u5F0B\u5F11\u5F16\u5F29\u5F2D\u5F38\u5F41\u5F48" +
  81         "\u5F4C\u5F4E\u5F2F\u5F51\u5F56\u5F57\u5F59\u5F61" +
  82         "\u5F6D\u5F73\u5F77\u5F83\u5F82\u5F7F\u5F8A\u5F88" +
  83         "\u5F91\u5F87\u5F9E\u5F99\u5F98\u5FA0\u5FA8\u5FAD" +
  84         "\u5FBC\u5FD6\u5FFB\u5FE4\u5FF8\u5FF1\u5FDD\u60B3" +
  85         "\u5FFF\u6021\u6060\u6019\u6010\u6029\u600E\u6031" +
  86         "\u62EE\u62F1\u6327\u6302\u6308\u62EF\u62F5\u6350" +
  87         "\u633E\u634D\u641C\u634F\u6396\u638E\u6380\u63AB" +
  88         "\u6376\u63A3\u638F\u6389\u639F\u63B5\u636B\u6369" +
  89         "\u63BE\u63E9\u63C0\u63C6\u63E3\u63C9\u63D2\u63F6" +
  90         "\u63C4\u6416\u6434\u6406\u6413\u6426\u6436\u651D" +
  91         "\u6417\u6428\u640F\u6467\u646F\u6476\u644E\u652A" +
  92         "\u6495\u6493\u64A5\u64A9\u6488\u64BC\u64DA\u64D2" +
  93         "\u64C5\u64C7\u64BB\u64D8\u64C2\u64F1\u64E7\u8209" +
  94         "\u64E0\u64E1\u62AC\u64E3\u64EF\u652C\u64F6\u64F4" +
  95         "\u64F2\u64FA\u6500\u64FD\u6518\u651C\u6505\u6524" +
  96         "\u6523\u652B\u6534\u6535\u6537\u6536\u6538\u754B" +
  97         "\u6741\u6738\u6737\u6746\u675E\u6760\u6759\u6763" +
  98         "\u6764\u6789\u6770\u67A9\u677C\u676A\u678C\u678B" +
  99         "\u67A6\u67A1\u6785\u67B7\u67EF\u67B4\u67EC\u67B3" +
 100         "\u67E9\u67B8\u67E4\u67DE\u67DD\u67E2\u67EE\u67B9" +
 101         "\u67CE\u67C6\u67E7\u6A9C\u681E\u6846\u6829\u6840" +
 102         "\u684D\u6832\u684E\u68B3\u682B\u6859\u6863\u6877" +
 103         "\u687F\u689F\u688F\u68AD\u6894\u689D\u689B\u6883" +
 104         "\u6AAE\u68B9\u6874\u68B5\u68A0\u68BA\u690F\u688D" +
 105         "\u687E\u6901\u68CA\u6908\u68D8\u6922\u6926\u68E1" +
 106         "\u690C\u68CD\u68D4\u68E7\u68D5\u6936\u6912\u6904" +
 107         "\u68D7\u68E3\u6925\u68F9\u68E0\u68EF\u6928\u692A" +
 108         "\u691A\u6923\u6921\u68C6\u6979\u6977\u695C\u6978" +
 109         "\u6CD7\u6CC5\u6CDD\u6CAE\u6CB1\u6CBE\u6CBA\u6CDB" +
 110         "\u6CEF\u6CD9\u6CEA\u6D1F\u884D\u6D36\u6D2B\u6D3D" +
 111         "\u6D38\u6D19\u6D35\u6D33\u6D12\u6D0C\u6D63\u6D93" +
 112         "\u6D64\u6D5A\u6D79\u6D59\u6D8E\u6D95\u6FE4\u6D85" +
 113         "\u6DF9\u6E15\u6E0A\u6DB5\u6DC7\u6DE6\u6DB8\u6DC6" +
 114         "\u6DEC\u6DDE\u6DCC\u6DE8\u6DD2\u6DC5\u6DFA\u6DD9" +
 115         "\u724B\u7258\u7274\u727E\u7282\u7281\u7287\u7292" +
 116         "\u7296\u72A2\u72A7\u72B9\u72B2\u72C3\u72C6\u72C4" +
 117         "\u9D59\u9D72\u9D89\u9D87\u9DAB\u9D6F\u9D7A\u9D9A" +
 118         "\u9DA4\u9DA9\u9DB2\u9DC4\u9DC1\u9DBB\u9DB8\u9DBA" +
 119         "\u9DC6\u9DCF\u9DC2\u9DD9\u9DD3\u9DF8\u9DE6\u9DED" +
 120         "\u9DEF\u9DFD\u9E1A\u9E1B\u9E1E\u9E75\u9E79\u9E7D" +
 121         "\u9E81\u9E88\u9E8B\u9E8C\u9E92\u9E95\u9E91\u9E9D" +
 122         "\u9EA5\u9EA9\u9EB8\u9EAA\u9EAD\u9761\u9ECC\u9ECE" +
 123         "\u9ECF\u9ED0\u9ED4\u9EDC\u9EDE\u9EDD\u9EE0\u9EE5" +
 124         "\u9EE8\u9EEF\u9EF4\u9EF6\u9EF7\u9EF9\u9EFB\u9EFC" +
 125         "\u9EFD\u9F07\u9F08\u76B7\u9F15\u9F21\u9F2C\u9F3E" +
 126         "\u9F4A\u9F52\u9F54\u9F63\u9F5F\u9F60\u9F61\u9F66" +
 127         "\u9F67\u9F6C\u9F6A\u9F77\u9F72\u9F76\u9F95\u9F9C" +
 128         "\u9FA0\u582F\u69C7\u9059\u7464\u51DC\u7199";
 129 
 130     final static String JISX0202KATAKANA =
 131         "\uFF61\uFF62\uFF63\uFF64" +
 132         "\uFF65\uFF66\uFF67\uFF68\uFF69\uFF6A\uFF6B\uFF6C" +
 133         "\uFF6D\uFF6E\uFF6F\uFF70\uFF71\uFF72\uFF73\uFF74" +
 134         "\uFF75\uFF76\uFF77\uFF78\uFF79\uFF7A\uFF7B\uFF7C" +
 135         "\uFF7D\uFF7E\uFF7F\uFF80\uFF81\uFF82\uFF83\uFF84" +
 136         "\uFF85\uFF86\uFF87\uFF88\uFF89\uFF8A\uFF8B\uFF8C" +
 137         "\uFF8D\uFF8E\uFF8F\uFF90\uFF91\uFF92\uFF93\uFF94" +
 138         "\uFF95\uFF96\uFF97\uFF98\uFF99\uFF9A\uFF9B\uFF9C" +
 139         "\uFF9D\uFF9E\uFF9F";
 140 
 141 
 142     final static byte[] expectedBytes1 = {
 143         (byte) 0x0, (byte) 0x1, (byte) 0x2, (byte) 0x3,
 144         (byte) 0x4, (byte) 0x5, (byte) 0x6, (byte) 0x7,
 145         (byte) 0x8, (byte) 0x9, (byte) 0xa, (byte) 0xb,
 146         (byte) 0xc, (byte) 0xd,
 147         (byte) 0x10, (byte) 0x11, (byte) 0x12, (byte) 0x13,
 148         (byte) 0x14, (byte) 0x15, (byte) 0x16, (byte) 0x17,
 149         (byte) 0x18, (byte) 0x19, (byte) 0x1a,
 150         (byte) 0x1c, (byte) 0x1d, (byte) 0x1e, (byte) 0x1f,
 151         (byte) 0x20, (byte) 0x21, (byte) 0x22, (byte) 0x23,
 152         (byte) 0x24, (byte) 0x25, (byte) 0x26, (byte) 0x27,
 153         (byte) 0x28, (byte) 0x29, (byte) 0x2a, (byte) 0x2b,
 154         (byte) 0x2c, (byte) 0x2d, (byte) 0x2e, (byte) 0x2f,
 155         (byte) 0x30, (byte) 0x31, (byte) 0x32, (byte) 0x33,
 156         (byte) 0x34, (byte) 0x35, (byte) 0x36, (byte) 0x37,
 157         (byte) 0x38, (byte) 0x39, (byte) 0x3a, (byte) 0x3b,
 158         (byte) 0x3c, (byte) 0x3d, (byte) 0x3e, (byte) 0x3f,
 159         (byte) 0x40, (byte) 0x41, (byte) 0x42, (byte) 0x43,
 160         (byte) 0x44, (byte) 0x45, (byte) 0x46, (byte) 0x47,
 161         (byte) 0x48, (byte) 0x49, (byte) 0x4a, (byte) 0x4b,
 162         (byte) 0x4c, (byte) 0x4d, (byte) 0x4e, (byte) 0x4f,
 163         (byte) 0x50, (byte) 0x51, (byte) 0x52, (byte) 0x53,
 164         (byte) 0x54, (byte) 0x55, (byte) 0x56, (byte) 0x57,
 165         (byte) 0x58, (byte) 0x59, (byte) 0x5a, (byte) 0x5b,
 166         (byte) 0x5c, (byte) 0x5d, (byte) 0x5e, (byte) 0x5f,
 167         (byte) 0x60, (byte) 0x61, (byte) 0x62, (byte) 0x63,
 168         (byte) 0x64, (byte) 0x65, (byte) 0x66, (byte) 0x67,
 169         (byte) 0x68, (byte) 0x69, (byte) 0x6a, (byte) 0x6b,
 170         (byte) 0x6c, (byte) 0x6d, (byte) 0x6e, (byte) 0x6f,
 171         (byte) 0x70, (byte) 0x71, (byte) 0x72, (byte) 0x73,
 172         (byte) 0x74, (byte) 0x75, (byte) 0x76, (byte) 0x77,
 173         (byte) 0x78, (byte) 0x79, (byte) 0x7a, (byte) 0x7b,
 174         (byte) 0x7c, (byte) 0x7d, (byte) 0x7e, (byte) 0x1b,
 175         (byte) 0x28, (byte) 0x4a, (byte) 0x5c, (byte) 0x7e,
 176         (byte) 0x1b, (byte) 0x28, (byte) 0x42, (byte) 0x75,
 177         (byte) 0x33, (byte) 0x30, (byte) 0x30, (byte) 0x30,
 178         (byte) 0x1b, (byte) 0x24, (byte) 0x42, (byte) 0x21,
 179         (byte) 0x22, (byte) 0x21, (byte) 0x23, (byte) 0x21,
 180         (byte) 0x24, (byte) 0x21, (byte) 0x25, (byte) 0x21,
 181         (byte) 0x26, (byte) 0x21, (byte) 0x27, (byte) 0x21,
 182         (byte) 0x28, (byte) 0x21, (byte) 0x29, (byte) 0x21,
 183         (byte) 0x2a, (byte) 0x21, (byte) 0x2b, (byte) 0x21,
 184         (byte) 0x2c, (byte) 0x21, (byte) 0x2d, (byte) 0x21,
 185         (byte) 0x2e, (byte) 0x21, (byte) 0x2f, (byte) 0x21,
 186         (byte) 0x30, (byte) 0x21, (byte) 0x31, (byte) 0x21,
 187         (byte) 0x32, (byte) 0x21, (byte) 0x33, (byte) 0x21,
 188         (byte) 0x34, (byte) 0x21, (byte) 0x35, (byte) 0x21,
 189         (byte) 0x36, (byte) 0x21, (byte) 0x37, (byte) 0x21,
 190         (byte) 0x38, (byte) 0x21, (byte) 0x39, (byte) 0x21,
 191         (byte) 0x3a, (byte) 0x21, (byte) 0x3b, (byte) 0x21,
 192         (byte) 0x3c, (byte) 0x21, (byte) 0x3d, (byte) 0x21,
 193         (byte) 0x3e, (byte) 0x21, (byte) 0x3f, (byte) 0x21,
 194         (byte) 0x40, (byte) 0x21, (byte) 0x41, (byte) 0x21,
 195         (byte) 0x42, (byte) 0x21, (byte) 0x43, (byte) 0x21,
 196         (byte) 0x44, (byte) 0x21, (byte) 0x45, (byte) 0x21,
 197         (byte) 0x46, (byte) 0x21, (byte) 0x47, (byte) 0x55,
 198         (byte) 0x71, (byte) 0x55, (byte) 0x72, (byte) 0x55,
 199         (byte) 0x73, (byte) 0x55, (byte) 0x74, (byte) 0x55,
 200         (byte) 0x75, (byte) 0x55, (byte) 0x76, (byte) 0x55,
 201         (byte) 0x77, (byte) 0x55, (byte) 0x78, (byte) 0x55,
 202         (byte) 0x79, (byte) 0x55, (byte) 0x7a, (byte) 0x55,
 203         (byte) 0x7b, (byte) 0x55, (byte) 0x7c, (byte) 0x55,
 204         (byte) 0x7d, (byte) 0x55, (byte) 0x7e, (byte) 0x56,
 205         (byte) 0x21, (byte) 0x56, (byte) 0x22, (byte) 0x56,
 206         (byte) 0x23, (byte) 0x56, (byte) 0x24, (byte) 0x56,
 207         (byte) 0x25, (byte) 0x56, (byte) 0x26, (byte) 0x56,
 208         (byte) 0x27, (byte) 0x56, (byte) 0x28, (byte) 0x56,
 209         (byte) 0x29, (byte) 0x56, (byte) 0x2a, (byte) 0x56,
 210         (byte) 0x2b, (byte) 0x56, (byte) 0x2c, (byte) 0x56,
 211         (byte) 0x2d, (byte) 0x56, (byte) 0x2e, (byte) 0x56,
 212         (byte) 0x2f, (byte) 0x56, (byte) 0x30, (byte) 0x56,
 213         (byte) 0x31, (byte) 0x56, (byte) 0x32, (byte) 0x56,
 214         (byte) 0x33, (byte) 0x56, (byte) 0x34, (byte) 0x56,
 215         (byte) 0x35, (byte) 0x56, (byte) 0x36, (byte) 0x56,
 216         (byte) 0x37, (byte) 0x56, (byte) 0x38, (byte) 0x56,
 217         (byte) 0x39, (byte) 0x56, (byte) 0x3a, (byte) 0x56,
 218         (byte) 0x3b, (byte) 0x56, (byte) 0x3c, (byte) 0x56,
 219         (byte) 0x3d, (byte) 0x56, (byte) 0x3e, (byte) 0x56,
 220         (byte) 0x3f, (byte) 0x56, (byte) 0x40, (byte) 0x56,
 221         (byte) 0x41, (byte) 0x56, (byte) 0x42, (byte) 0x56,
 222         (byte) 0x43, (byte) 0x56, (byte) 0x44, (byte) 0x56,
 223         (byte) 0x45, (byte) 0x56, (byte) 0x46, (byte) 0x56,
 224         (byte) 0x47, (byte) 0x56, (byte) 0x48, (byte) 0x56,
 225         (byte) 0x49, (byte) 0x56, (byte) 0x4a, (byte) 0x56,
 226         (byte) 0x4b, (byte) 0x56, (byte) 0x4c, (byte) 0x56,
 227         (byte) 0x4d, (byte) 0x56, (byte) 0x4e, (byte) 0x56,
 228         (byte) 0x4f, (byte) 0x56, (byte) 0x50, (byte) 0x56,
 229         (byte) 0x51, (byte) 0x56, (byte) 0x52, (byte) 0x56,
 230         (byte) 0x53, (byte) 0x56, (byte) 0x54, (byte) 0x56,
 231         (byte) 0x55, (byte) 0x56, (byte) 0x56, (byte) 0x56,
 232         (byte) 0x57, (byte) 0x56, (byte) 0x58, (byte) 0x56,
 233         (byte) 0x59, (byte) 0x56, (byte) 0x5a, (byte) 0x56,
 234         (byte) 0x5b, (byte) 0x56, (byte) 0x5c, (byte) 0x56,
 235         (byte) 0x5d, (byte) 0x56, (byte) 0x5e, (byte) 0x56,
 236         (byte) 0x5f, (byte) 0x56, (byte) 0x60, (byte) 0x56,
 237         (byte) 0x61, (byte) 0x56, (byte) 0x62, (byte) 0x56,
 238         (byte) 0x63, (byte) 0x56, (byte) 0x64, (byte) 0x56,
 239         (byte) 0x65, (byte) 0x56, (byte) 0x66, (byte) 0x56,
 240         (byte) 0x67, (byte) 0x56, (byte) 0x68, (byte) 0x56,
 241         (byte) 0x69, (byte) 0x56, (byte) 0x6a, (byte) 0x56,
 242         (byte) 0x6b, (byte) 0x56, (byte) 0x6c, (byte) 0x56,
 243         (byte) 0x6d, (byte) 0x56, (byte) 0x6e, (byte) 0x56,
 244         (byte) 0x6f, (byte) 0x56, (byte) 0x70, (byte) 0x56,
 245         (byte) 0x71, (byte) 0x56, (byte) 0x72, (byte) 0x56,
 246         (byte) 0x73, (byte) 0x56, (byte) 0x74, (byte) 0x56,
 247         (byte) 0x75, (byte) 0x56, (byte) 0x76, (byte) 0x56,
 248         (byte) 0x77, (byte) 0x56, (byte) 0x78, (byte) 0x56,
 249         (byte) 0x79, (byte) 0x56, (byte) 0x7a, (byte) 0x56,
 250         (byte) 0x7b, (byte) 0x56, (byte) 0x7c, (byte) 0x56,
 251         (byte) 0x7d, (byte) 0x56, (byte) 0x7e, (byte) 0x57,
 252         (byte) 0x21, (byte) 0x57, (byte) 0x22, (byte) 0x57,
 253         (byte) 0x23, (byte) 0x57, (byte) 0x24, (byte) 0x57,
 254         (byte) 0x25, (byte) 0x57, (byte) 0x26, (byte) 0x57,
 255         (byte) 0x27, (byte) 0x57, (byte) 0x28, (byte) 0x57,
 256         (byte) 0x29, (byte) 0x57, (byte) 0x2a, (byte) 0x57,
 257         (byte) 0x2b, (byte) 0x57, (byte) 0x2c, (byte) 0x57,
 258         (byte) 0x2d, (byte) 0x57, (byte) 0x2e, (byte) 0x57,
 259         (byte) 0x2f, (byte) 0x57, (byte) 0x30, (byte) 0x57,
 260         (byte) 0x31, (byte) 0x57, (byte) 0x32, (byte) 0x57,
 261         (byte) 0x33, (byte) 0x57, (byte) 0x34, (byte) 0x57,
 262         (byte) 0x35, (byte) 0x57, (byte) 0x36, (byte) 0x57,
 263         (byte) 0x37, (byte) 0x57, (byte) 0x38, (byte) 0x57,
 264         (byte) 0x39, (byte) 0x57, (byte) 0x3a, (byte) 0x57,
 265         (byte) 0x3b, (byte) 0x57, (byte) 0x3c, (byte) 0x57,
 266         (byte) 0x3d, (byte) 0x57, (byte) 0x3e, (byte) 0x57,
 267         (byte) 0x3f, (byte) 0x57, (byte) 0x40, (byte) 0x57,
 268         (byte) 0x41, (byte) 0x57, (byte) 0x42, (byte) 0x57,
 269         (byte) 0x43, (byte) 0x57, (byte) 0x44, (byte) 0x57,
 270         (byte) 0x45, (byte) 0x57, (byte) 0x46, (byte) 0x57,
 271         (byte) 0x47, (byte) 0x57, (byte) 0x48, (byte) 0x57,
 272         (byte) 0x49, (byte) 0x57, (byte) 0x4a, (byte) 0x57,
 273         (byte) 0x4b, (byte) 0x57, (byte) 0x4c, (byte) 0x57,
 274         (byte) 0x4d, (byte) 0x57, (byte) 0x4e, (byte) 0x57,
 275         (byte) 0x4f, (byte) 0x57, (byte) 0x50, (byte) 0x57,
 276         (byte) 0x51, (byte) 0x57, (byte) 0x52, (byte) 0x57,
 277         (byte) 0x53, (byte) 0x57, (byte) 0x54, (byte) 0x57,
 278         (byte) 0x55, (byte) 0x57, (byte) 0x56, (byte) 0x57,
 279         (byte) 0x57, (byte) 0x57, (byte) 0x58, (byte) 0x57,
 280         (byte) 0x59, (byte) 0x57, (byte) 0x5a, (byte) 0x57,
 281         (byte) 0x5b, (byte) 0x57, (byte) 0x5c, (byte) 0x57,
 282         (byte) 0x5d, (byte) 0x57, (byte) 0x5e, (byte) 0x57,
 283         (byte) 0x5f, (byte) 0x57, (byte) 0x60, (byte) 0x57,
 284         (byte) 0x61, (byte) 0x57, (byte) 0x62, (byte) 0x57,
 285         (byte) 0x63, (byte) 0x57, (byte) 0x64, (byte) 0x59,
 286         (byte) 0x49, (byte) 0x59, (byte) 0x4a, (byte) 0x59,
 287         (byte) 0x4b, (byte) 0x59, (byte) 0x4c, (byte) 0x59,
 288         (byte) 0x4d, (byte) 0x59, (byte) 0x4e, (byte) 0x59,
 289         (byte) 0x4f, (byte) 0x59, (byte) 0x50, (byte) 0x59,
 290         (byte) 0x51, (byte) 0x59, (byte) 0x52, (byte) 0x59,
 291         (byte) 0x53, (byte) 0x59, (byte) 0x54, (byte) 0x59,
 292         (byte) 0x55, (byte) 0x59, (byte) 0x56, (byte) 0x59,
 293         (byte) 0x57, (byte) 0x59, (byte) 0x58, (byte) 0x59,
 294         (byte) 0x59, (byte) 0x59, (byte) 0x5a, (byte) 0x59,
 295         (byte) 0x5b, (byte) 0x59, (byte) 0x5c, (byte) 0x59,
 296         (byte) 0x5d, (byte) 0x59, (byte) 0x5e, (byte) 0x59,
 297         (byte) 0x5f, (byte) 0x59, (byte) 0x60, (byte) 0x59,
 298         (byte) 0x61, (byte) 0x59, (byte) 0x62, (byte) 0x59,
 299         (byte) 0x63, (byte) 0x59, (byte) 0x64, (byte) 0x59,
 300         (byte) 0x65, (byte) 0x59, (byte) 0x66, (byte) 0x59,
 301         (byte) 0x67, (byte) 0x59, (byte) 0x68, (byte) 0x59,
 302         (byte) 0x69, (byte) 0x59, (byte) 0x6a, (byte) 0x59,
 303         (byte) 0x6b, (byte) 0x59, (byte) 0x6c, (byte) 0x59,
 304         (byte) 0x6d, (byte) 0x59, (byte) 0x6e, (byte) 0x59,
 305         (byte) 0x6f, (byte) 0x59, (byte) 0x70, (byte) 0x59,
 306         (byte) 0x71, (byte) 0x59, (byte) 0x72, (byte) 0x59,
 307         (byte) 0x73, (byte) 0x59, (byte) 0x74, (byte) 0x59,
 308         (byte) 0x75, (byte) 0x59, (byte) 0x76, (byte) 0x59,
 309         (byte) 0x77, (byte) 0x59, (byte) 0x78, (byte) 0x59,
 310         (byte) 0x79, (byte) 0x59, (byte) 0x7a, (byte) 0x59,
 311         (byte) 0x7b, (byte) 0x59, (byte) 0x7c, (byte) 0x59,
 312         (byte) 0x7d, (byte) 0x59, (byte) 0x7e, (byte) 0x5a,
 313         (byte) 0x21, (byte) 0x5a, (byte) 0x22, (byte) 0x5a,
 314         (byte) 0x23, (byte) 0x5a, (byte) 0x24, (byte) 0x5a,
 315         (byte) 0x25, (byte) 0x5a, (byte) 0x26, (byte) 0x5a,
 316         (byte) 0x27, (byte) 0x5a, (byte) 0x28, (byte) 0x5a,
 317         (byte) 0x29, (byte) 0x5a, (byte) 0x2a, (byte) 0x5a,
 318         (byte) 0x2b, (byte) 0x5a, (byte) 0x2c, (byte) 0x5a,
 319         (byte) 0x2d, (byte) 0x5a, (byte) 0x2e, (byte) 0x5a,
 320         (byte) 0x2f, (byte) 0x5a, (byte) 0x30, (byte) 0x5a,
 321         (byte) 0x31, (byte) 0x5a, (byte) 0x32, (byte) 0x5a,
 322         (byte) 0x33, (byte) 0x5a, (byte) 0x34, (byte) 0x5a,
 323         (byte) 0x35, (byte) 0x5a, (byte) 0x36, (byte) 0x5a,
 324         (byte) 0x37, (byte) 0x5a, (byte) 0x38, (byte) 0x5a,
 325         (byte) 0x39, (byte) 0x5a, (byte) 0x3a, (byte) 0x5a,
 326         (byte) 0x3b, (byte) 0x5a, (byte) 0x3c, (byte) 0x5a,
 327         (byte) 0x3d, (byte) 0x5a, (byte) 0x3e, (byte) 0x5a,
 328         (byte) 0x3f, (byte) 0x5a, (byte) 0x40, (byte) 0x5a,
 329         (byte) 0x41, (byte) 0x5a, (byte) 0x42, (byte) 0x5b,
 330         (byte) 0x35, (byte) 0x5b, (byte) 0x36, (byte) 0x5b,
 331         (byte) 0x37, (byte) 0x5b, (byte) 0x38, (byte) 0x5b,
 332         (byte) 0x39, (byte) 0x5b, (byte) 0x3a, (byte) 0x5b,
 333         (byte) 0x3b, (byte) 0x5b, (byte) 0x3c, (byte) 0x5b,
 334         (byte) 0x3d, (byte) 0x5b, (byte) 0x3e, (byte) 0x5b,
 335         (byte) 0x3f, (byte) 0x5b, (byte) 0x40, (byte) 0x5b,
 336         (byte) 0x41, (byte) 0x5b, (byte) 0x42, (byte) 0x5b,
 337         (byte) 0x43, (byte) 0x5b, (byte) 0x44, (byte) 0x5b,
 338         (byte) 0x45, (byte) 0x5b, (byte) 0x46, (byte) 0x5b,
 339         (byte) 0x47, (byte) 0x5b, (byte) 0x48, (byte) 0x5b,
 340         (byte) 0x49, (byte) 0x5b, (byte) 0x4a, (byte) 0x5b,
 341         (byte) 0x4b, (byte) 0x5b, (byte) 0x4c, (byte) 0x5b,
 342         (byte) 0x4d, (byte) 0x5b, (byte) 0x4e, (byte) 0x5b,
 343         (byte) 0x4f, (byte) 0x5b, (byte) 0x50, (byte) 0x5b,
 344         (byte) 0x51, (byte) 0x5b, (byte) 0x52, (byte) 0x5b,
 345         (byte) 0x53, (byte) 0x5b, (byte) 0x54, (byte) 0x5b,
 346         (byte) 0x55, (byte) 0x5b, (byte) 0x56, (byte) 0x5b,
 347         (byte) 0x57, (byte) 0x5b, (byte) 0x58, (byte) 0x5b,
 348         (byte) 0x59, (byte) 0x5b, (byte) 0x5a, (byte) 0x5b,
 349         (byte) 0x5b, (byte) 0x5b, (byte) 0x5c, (byte) 0x5b,
 350         (byte) 0x5d, (byte) 0x5b, (byte) 0x5e, (byte) 0x5b,
 351         (byte) 0x5f, (byte) 0x5b, (byte) 0x60, (byte) 0x5b,
 352         (byte) 0x61, (byte) 0x5b, (byte) 0x62, (byte) 0x5b,
 353         (byte) 0x63, (byte) 0x5b, (byte) 0x64, (byte) 0x5b,
 354         (byte) 0x65, (byte) 0x5b, (byte) 0x66, (byte) 0x5b,
 355         (byte) 0x67, (byte) 0x5b, (byte) 0x68, (byte) 0x5b,
 356         (byte) 0x69, (byte) 0x5b, (byte) 0x6a, (byte) 0x5b,
 357         (byte) 0x6b, (byte) 0x5b, (byte) 0x6c, (byte) 0x5b,
 358         (byte) 0x6d, (byte) 0x5b, (byte) 0x6e, (byte) 0x5b,
 359         (byte) 0x6f, (byte) 0x5b, (byte) 0x70, (byte) 0x5b,
 360         (byte) 0x71, (byte) 0x5b, (byte) 0x72, (byte) 0x5b,
 361         (byte) 0x73, (byte) 0x5b, (byte) 0x74, (byte) 0x5b,
 362         (byte) 0x75, (byte) 0x5b, (byte) 0x76, (byte) 0x5b,
 363         (byte) 0x77, (byte) 0x5b, (byte) 0x78, (byte) 0x5b,
 364         (byte) 0x79, (byte) 0x5b, (byte) 0x7a, (byte) 0x5b,
 365         (byte) 0x7b, (byte) 0x5b, (byte) 0x7c, (byte) 0x5b,
 366         (byte) 0x7d, (byte) 0x5b, (byte) 0x7e, (byte) 0x5c,
 367         (byte) 0x21, (byte) 0x5c, (byte) 0x22, (byte) 0x5c,
 368         (byte) 0x23, (byte) 0x5c, (byte) 0x24, (byte) 0x5c,
 369         (byte) 0x25, (byte) 0x5c, (byte) 0x26, (byte) 0x5c,
 370         (byte) 0x27, (byte) 0x5c, (byte) 0x28, (byte) 0x5c,
 371         (byte) 0x29, (byte) 0x5c, (byte) 0x2a, (byte) 0x5c,
 372         (byte) 0x2b, (byte) 0x5c, (byte) 0x2c, (byte) 0x5c,
 373         (byte) 0x2d, (byte) 0x5c, (byte) 0x2e, (byte) 0x5c,
 374         (byte) 0x2f, (byte) 0x5c, (byte) 0x30, (byte) 0x5c,
 375         (byte) 0x31, (byte) 0x5c, (byte) 0x32, (byte) 0x5c,
 376         (byte) 0x33, (byte) 0x5c, (byte) 0x34, (byte) 0x5c,
 377         (byte) 0x35, (byte) 0x5c, (byte) 0x36, (byte) 0x5d,
 378         (byte) 0x79, (byte) 0x5d, (byte) 0x7a, (byte) 0x5d,
 379         (byte) 0x7b, (byte) 0x5d, (byte) 0x7c, (byte) 0x5d,
 380         (byte) 0x7d, (byte) 0x5d, (byte) 0x7e, (byte) 0x5e,
 381         (byte) 0x21, (byte) 0x5e, (byte) 0x22, (byte) 0x5e,
 382         (byte) 0x23, (byte) 0x5e, (byte) 0x24, (byte) 0x5e,
 383         (byte) 0x25, (byte) 0x5e, (byte) 0x26, (byte) 0x5e,
 384         (byte) 0x27, (byte) 0x5e, (byte) 0x28, (byte) 0x5e,
 385         (byte) 0x29, (byte) 0x5e, (byte) 0x2a, (byte) 0x5e,
 386         (byte) 0x2b, (byte) 0x5e, (byte) 0x2c, (byte) 0x5e,
 387         (byte) 0x2d, (byte) 0x5e, (byte) 0x2e, (byte) 0x5e,
 388         (byte) 0x2f, (byte) 0x5e, (byte) 0x30, (byte) 0x5e,
 389         (byte) 0x31, (byte) 0x5e, (byte) 0x32, (byte) 0x5e,
 390         (byte) 0x33, (byte) 0x5e, (byte) 0x34, (byte) 0x5e,
 391         (byte) 0x35, (byte) 0x5e, (byte) 0x36, (byte) 0x5e,
 392         (byte) 0x37, (byte) 0x5e, (byte) 0x38, (byte) 0x5e,
 393         (byte) 0x39, (byte) 0x5e, (byte) 0x3a, (byte) 0x5e,
 394         (byte) 0x3b, (byte) 0x5e, (byte) 0x3c, (byte) 0x5e,
 395         (byte) 0x3d, (byte) 0x5e, (byte) 0x3e, (byte) 0x5e,
 396         (byte) 0x3f, (byte) 0x5e, (byte) 0x40, (byte) 0x5e,
 397         (byte) 0x41, (byte) 0x5e, (byte) 0x42, (byte) 0x5e,
 398         (byte) 0x43, (byte) 0x5e, (byte) 0x44, (byte) 0x5e,
 399         (byte) 0x45, (byte) 0x5e, (byte) 0x46, (byte) 0x5e,
 400         (byte) 0x47, (byte) 0x5e, (byte) 0x48, (byte) 0x5e,
 401         (byte) 0x49, (byte) 0x5e, (byte) 0x4a, (byte) 0x60,
 402         (byte) 0x30, (byte) 0x60, (byte) 0x31, (byte) 0x60,
 403         (byte) 0x32, (byte) 0x60, (byte) 0x33, (byte) 0x60,
 404         (byte) 0x34, (byte) 0x60, (byte) 0x35, (byte) 0x60,
 405         (byte) 0x36, (byte) 0x60, (byte) 0x37, (byte) 0x60,
 406         (byte) 0x38, (byte) 0x60, (byte) 0x39, (byte) 0x60,
 407         (byte) 0x3a, (byte) 0x60, (byte) 0x3b, (byte) 0x60,
 408         (byte) 0x3c, (byte) 0x60, (byte) 0x3d, (byte) 0x60,
 409         (byte) 0x3e, (byte) 0x60, (byte) 0x3f, (byte) 0x73,
 410         (byte) 0x26, (byte) 0x73, (byte) 0x27, (byte) 0x73,
 411         (byte) 0x28, (byte) 0x73, (byte) 0x29, (byte) 0x73,
 412         (byte) 0x2a, (byte) 0x73, (byte) 0x2b, (byte) 0x73,
 413         (byte) 0x2c, (byte) 0x73, (byte) 0x2d, (byte) 0x73,
 414         (byte) 0x2e, (byte) 0x73, (byte) 0x2f, (byte) 0x73,
 415         (byte) 0x30, (byte) 0x73, (byte) 0x31, (byte) 0x73,
 416         (byte) 0x32, (byte) 0x73, (byte) 0x33, (byte) 0x73,
 417         (byte) 0x34, (byte) 0x73, (byte) 0x35, (byte) 0x73,
 418         (byte) 0x36, (byte) 0x73, (byte) 0x37, (byte) 0x73,
 419         (byte) 0x38, (byte) 0x73, (byte) 0x39, (byte) 0x73,
 420         (byte) 0x3a, (byte) 0x73, (byte) 0x3b, (byte) 0x73,
 421         (byte) 0x3c, (byte) 0x73, (byte) 0x3d, (byte) 0x73,
 422         (byte) 0x3e, (byte) 0x73, (byte) 0x3f, (byte) 0x73,
 423         (byte) 0x40, (byte) 0x73, (byte) 0x41, (byte) 0x73,
 424         (byte) 0x42, (byte) 0x73, (byte) 0x43, (byte) 0x73,
 425         (byte) 0x44, (byte) 0x73, (byte) 0x45, (byte) 0x73,
 426         (byte) 0x46, (byte) 0x73, (byte) 0x47, (byte) 0x73,
 427         (byte) 0x48, (byte) 0x73, (byte) 0x49, (byte) 0x73,
 428         (byte) 0x4a, (byte) 0x73, (byte) 0x4b, (byte) 0x73,
 429         (byte) 0x4c, (byte) 0x73, (byte) 0x4d, (byte) 0x73,
 430         (byte) 0x4e, (byte) 0x73, (byte) 0x4f, (byte) 0x73,
 431         (byte) 0x50, (byte) 0x73, (byte) 0x51, (byte) 0x73,
 432         (byte) 0x52, (byte) 0x73, (byte) 0x53, (byte) 0x73,
 433         (byte) 0x54, (byte) 0x73, (byte) 0x55, (byte) 0x73,
 434         (byte) 0x56, (byte) 0x73, (byte) 0x57, (byte) 0x73,
 435         (byte) 0x58, (byte) 0x73, (byte) 0x59, (byte) 0x73,
 436         (byte) 0x5a, (byte) 0x73, (byte) 0x5b, (byte) 0x73,
 437         (byte) 0x5c, (byte) 0x73, (byte) 0x5d, (byte) 0x73,
 438         (byte) 0x5e, (byte) 0x73, (byte) 0x5f, (byte) 0x73,
 439         (byte) 0x60, (byte) 0x73, (byte) 0x61, (byte) 0x73,
 440         (byte) 0x62, (byte) 0x73, (byte) 0x63, (byte) 0x73,
 441         (byte) 0x64, (byte) 0x73, (byte) 0x65, (byte) 0x73,
 442         (byte) 0x66, (byte) 0x73, (byte) 0x67, (byte) 0x73,
 443         (byte) 0x68, (byte) 0x73, (byte) 0x69, (byte) 0x73,
 444         (byte) 0x6a, (byte) 0x73, (byte) 0x6b, (byte) 0x73,
 445         (byte) 0x6c, (byte) 0x73, (byte) 0x6d, (byte) 0x73,
 446         (byte) 0x6e, (byte) 0x73, (byte) 0x6f, (byte) 0x73,
 447         (byte) 0x70, (byte) 0x73, (byte) 0x71, (byte) 0x73,
 448         (byte) 0x72, (byte) 0x73, (byte) 0x73, (byte) 0x73,
 449         (byte) 0x74, (byte) 0x73, (byte) 0x75, (byte) 0x73,
 450         (byte) 0x76, (byte) 0x73, (byte) 0x77, (byte) 0x73,
 451         (byte) 0x78, (byte) 0x73, (byte) 0x79, (byte) 0x73,
 452         (byte) 0x7a, (byte) 0x73, (byte) 0x7b, (byte) 0x73,
 453         (byte) 0x7c, (byte) 0x73, (byte) 0x7d, (byte) 0x73,
 454         (byte) 0x7e, (byte) 0x74, (byte) 0x21, (byte) 0x74,
 455         (byte) 0x22, (byte) 0x74, (byte) 0x23, (byte) 0x74,
 456         (byte) 0x24, (byte) 0x74, (byte) 0x25, (byte) 0x74,
 457         (byte) 0x26, (byte) 0x1b, (byte) 0x28, (byte) 0x49,
 458         (byte) 0x21, (byte) 0x22, (byte) 0x23, (byte) 0x24,
 459         (byte) 0x25, (byte) 0x26, (byte) 0x27, (byte) 0x28,
 460         (byte) 0x29, (byte) 0x2a, (byte) 0x2b, (byte) 0x2c,
 461         (byte) 0x2d, (byte) 0x2e, (byte) 0x2f, (byte) 0x30,
 462         (byte) 0x31, (byte) 0x32, (byte) 0x33, (byte) 0x34,
 463         (byte) 0x35, (byte) 0x36, (byte) 0x37, (byte) 0x38,
 464         (byte) 0x39, (byte) 0x3a, (byte) 0x3b, (byte) 0x3c,
 465         (byte) 0x3d, (byte) 0x3e, (byte) 0x3f, (byte) 0x40,
 466         (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44,
 467         (byte) 0x45, (byte) 0x46, (byte) 0x47, (byte) 0x48,
 468         (byte) 0x49, (byte) 0x4a, (byte) 0x4b, (byte) 0x4c,
 469         (byte) 0x4d, (byte) 0x4e, (byte) 0x4f, (byte) 0x50,
 470         (byte) 0x51, (byte) 0x52, (byte) 0x53, (byte) 0x54,
 471         (byte) 0x55, (byte) 0x56, (byte) 0x57, (byte) 0x58,
 472         (byte) 0x59, (byte) 0x5a, (byte) 0x5b, (byte) 0x5c,
 473         (byte) 0x5d, (byte) 0x5e, (byte) 0x5f, (byte) 0x1b,
 474         (byte) 0x28, (byte) 0x42 };
 475 
 476     private final static String MIXEDCONTENT =
 477         "JA\u3000\u3002\u0062\uFF64PAN" +
 478         "\uFF0C\uFF0E\u00A5\uFF65\uFF66X\u203E" +
 479         "\u30FB\uFF67\u203E";
 480 
 481     static byte[] mixedBytesExpected = {
 482         (byte) 0x4a, (byte) 0x41, (byte) 0x1b, (byte) 0x24,
 483         (byte) 0x42, (byte) 0x21, (byte) 0x21, (byte) 0x21,
 484         (byte) 0x23, (byte) 0x1b, (byte) 0x28, (byte) 0x42,
 485         (byte) 0x62, (byte) 0x1b, (byte) 0x28, (byte) 0x49,
 486         (byte) 0x24, (byte) 0x1b, (byte) 0x28, (byte) 0x42,
 487         (byte) 0x50, (byte) 0x41, (byte) 0x4e, (byte) 0x1b,
 488         (byte) 0x24, (byte) 0x42, (byte) 0x21, (byte) 0x24,
 489         (byte) 0x21, (byte) 0x25, (byte) 0x1b, (byte) 0x28,
 490         (byte) 0x4a, (byte) 0x5c, (byte) 0x1b, (byte) 0x28,
 491         (byte) 0x49, (byte) 0x25, (byte) 0x26, (byte) 0x1b,
 492         (byte) 0x28, (byte) 0x42, (byte) 0x58, (byte) 0x1b,
 493         (byte) 0x28, (byte) 0x4a, (byte) 0x7e, (byte) 0x1b,
 494         (byte) 0x24, (byte) 0x42, (byte) 0x21, (byte) 0x26,
 495         (byte) 0x1b, (byte) 0x28, (byte) 0x49, (byte) 0x27,
 496         (byte) 0x1b, (byte) 0x28, (byte) 0x4a, (byte) 0x7e,
 497         (byte) 0x1b, (byte) 0x28, (byte) 0x42  };
 498 
 499     static byte[] repeatingEscapes = {
 500         (byte) 0x4a, (byte) 0x41, (byte) 0x1b, (byte) 0x24,
 501         (byte) 0x42, (byte)0x1b, (byte)0x24, (byte)0x42,
 502         (byte) 0x21, (byte) 0x21, (byte) 0x21,
 503         (byte) 0x23, (byte) 0x1b, (byte) 0x28, (byte) 0x42,
 504         // embedded repeated iso-2022 escapes (see bugID 4879522)
 505         (byte)0x1b, (byte)0x28, (byte)0x42,
 506         (byte) 0x62, (byte) 0x1b, (byte) 0x28, (byte) 0x49,
 507         (byte)0x0f, (byte)0x0e, (byte)0x0f,
 508         (byte)0x1b, (byte)0x28, (byte)0x49,
 509         (byte) 0x24, (byte) 0x1b, (byte) 0x28, (byte) 0x42,
 510         (byte) 0x50, (byte) 0x41, (byte) 0x4e,
 511         // embedded shift chars (see bugID 4879522)
 512         (byte)0x0e, (byte)0x0f,
 513         (byte) 0x1b,
 514         (byte) 0x24, (byte) 0x42, (byte) 0x21, (byte) 0x24,
 515         (byte) 0x21, (byte) 0x25, (byte) 0x1b, (byte) 0x28,
 516         (byte) 0x4a, (byte) 0x5c, (byte) 0x1b, (byte) 0x28,
 517         (byte) 0x49, (byte) 0x25, (byte) 0x26, (byte) 0x1b,
 518         (byte) 0x28, (byte) 0x42, (byte) 0x58, (byte) 0x1b,
 519         (byte) 0x28, (byte) 0x4a, (byte) 0x7e, (byte) 0x1b,
 520         (byte) 0x24, (byte) 0x42, (byte) 0x21, (byte) 0x26,
 521         (byte) 0x1b, (byte) 0x28, (byte) 0x49, (byte) 0x27,
 522         (byte) 0x1b, (byte) 0x28, (byte) 0x4a, (byte) 0x7e,
 523         (byte) 0x1b, (byte) 0x28, (byte) 0x42  };
 524 
 525 
 526     private static String JISX0212 =
 527         "\u02d8\u6896\u9fa5";
 528 
 529     private static byte[] expectedBytes_JISX0212 = {
 530         (byte)0x1b, (byte)0x24, (byte)0x28, (byte)0x44,
 531         (byte)0x22, (byte)0x2f, (byte)0x43, (byte)0x6f,
 532         (byte)0x6d, (byte)0x63,
 533         (byte)0x1b, (byte)0x28, (byte)0x42
 534     };
 535 
 536     /*
 537      * Tests the roundtrip integrity and expected encoding
 538      * correctness for a String containing a substantial
 539      * subset of ISO-2022-JP/ISO-2022-JP-2 encodeable chars
 540      */
 541 
 542     private static void roundTrip(String testStr, byte[] expectBytes,
 543                                   String csName)
 544     throws Exception {
 545         byte[] encodedBytes = testStr.getBytes(csName);
 546 
 547         if (encodedBytes.length != expectBytes.length) {
 548             throw new Exception(csName + " Encoder error");
 549         }
 550 
 551         for (int i = 0; i < expectBytes.length; i++) {
 552             if (encodedBytes[i] != expectBytes[i])  {
 553                 throw new Exception(csName + " Encoder error");
 554             }
 555         }
 556         String decoded = new String(encodedBytes, csName);
 557 
 558         if (!decoded.equals(testStr)) {
 559             throw new Exception(csName + " Decoder error");
 560         }
 561         String decoded2 = new String(repeatingEscapes, csName);
 562         if (!decoded2.equals(MIXEDCONTENT)) {
 563             throw new Exception(csName + " Decoder error");
 564         }
 565      }
 566 
 567     public static void main(String[] args) throws Exception {
 568 
 569         // Long String containing sequential chars
 570         // ASCII/yen/tilde/jisx0208 chars/katakana chars
 571 
 572         String testStr1 = US_ASCII +
 573                         JISX0208SUBSET + JISX0202KATAKANA;
 574         roundTrip(testStr1, expectedBytes1, "ISO-2022-JP");
 575         roundTrip(testStr1, expectedBytes1, "ISO-2022-JP-2");
 576         roundTrip(JISX0212, expectedBytes_JISX0212, "ISO-2022-JP-2");
 577 
 578         // mixed chars which encode to the supported codesets
 579         // of ISO-2022-JP/ISO-2022-JP-2
 580 
 581         String testStr2 = MIXEDCONTENT;
 582         roundTrip(testStr2 , mixedBytesExpected, "ISO-2022-JP");
 583         roundTrip(testStr2 , mixedBytesExpected, "ISO-2022-JP-2");
 584 
 585         String decoded2 = new String(repeatingEscapes, "ISO-2022-JP");
 586         if (!decoded2.equals(MIXEDCONTENT)) {
 587             throw new Exception("ISO-2022-JP Decoder error");
 588         }
 589 
 590         decoded2 = new String(repeatingEscapes, "ISO-2022-JP-2");
 591         if (!decoded2.equals(MIXEDCONTENT)) {
 592             throw new Exception("ISO-2022-JP-2 Decoder error");
 593         }
 594 
 595         // Test for bugID 4913711
 596         // ISO-2022-JP encoding of a single input char yields
 597         // 8 output bytes. Prior to fix for 4913711 the
 598         // max bytes per char value was underspecified as 5.0
 599         // and the code below would have thrown a BufferOverflow
 600         // exception. This test validates the fix for 4913711
 601 
 602         String testStr3 = "\u3042";
 603         byte[] expected = { (byte)0x1b, (byte)0x24, (byte)0x42,
 604                             (byte)0x24, (byte)0x22, (byte)0x1b,
 605                             (byte)0x28, (byte)0x42 };
 606         byte[] encoded = testStr3.getBytes("ISO-2022-JP");
 607         for (int i = 0; i < expected.length; i++) {
 608             if (encoded[i] != expected[i])
 609                throw new Exception("ISO-2022-JP Decoder error");
 610         }
 611 
 612         // Test for 11 iso2022jp decoder
 613         encoded = new byte[] {
 614             (byte)0x1B, (byte)0x28, (byte)0x49, (byte)0x60,
 615             (byte)0x1B, (byte)0x28, (byte)0x42,
 616         };
 617         String unexpectedStr = "\uffa0";
 618         String expectedStr = "\ufffd";
 619         if (new String(encoded, "ISO2022JP").equals(unexpectedStr)) {
 620                throw new Exception("ISO2022JP Decoder error: \\uFFA0");
 621         } else if (!new String(encoded, "ISO2022JP").equals(expectedStr)) {
 622                throw new Exception("ISO2022JP Decoder error: \\uFFFD");
 623         }
 624     }
 625 }