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