001/*
002 *  jDTAUS Banking Charset Providers
003 *  Copyright (C) 2005 Christian Schulte
004 *  <cs@schulte.it>
005 *
006 *  This library is free software; you can redistribute it and/or
007 *  modify it under the terms of the GNU Lesser General Public
008 *  License as published by the Free Software Foundation; either
009 *  version 2.1 of the License, or any later version.
010 *
011 *  This library is distributed in the hope that it will be useful,
012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 *  Lesser General Public License for more details.
015 *
016 *  You should have received a copy of the GNU Lesser General Public
017 *  License along with this library; if not, write to the Free Software
018 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
019 *
020 */
021package org.jdtaus.banking.charsets.spi;
022
023import java.nio.ByteBuffer;
024import java.nio.CharBuffer;
025import java.nio.charset.Charset;
026import java.nio.charset.CharsetDecoder;
027import java.nio.charset.CharsetEncoder;
028import java.nio.charset.CoderResult;
029import java.nio.charset.CodingErrorAction;
030import java.nio.charset.spi.CharsetProvider;
031import java.util.Iterator;
032import java.util.NoSuchElementException;
033
034/**
035 * {@code CharsetProvider} for IBM273 Charset.
036 * <p>
037 * Name: IBM273<br>
038 * MIBenum: 2030<br>
039 * Source: IBM NLS RM Vol2 SE09-8002-01, March 1990<br>
040 * Alias: CP273<br>
041 * Alias: csIBM273<br>
042 * See: RFC1345,KXS2<br>
043 *
044 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
045 * @version $JDTAUS: IBM273CharsetProvider.java 8661 2012-09-27 11:29:58Z schulte $
046 */
047public class IBM273CharsetProvider extends CharsetProvider
048{
049
050    /** Common name. */
051    static final String COMMON_NAME = "IBM273";
052
053    /** Alias names. */
054    static final String[] ALIAS_NAMES =
055    {
056        "cp273", "csIBM273"
057    };
058
059    /** Supported character set names. */
060    static final String[] SUPPORTED_NAMES =
061    {
062        COMMON_NAME.toLowerCase(), "cp273", "csIBM273"
063    };
064
065    static final char[] BYTE_TO_CHAR =
066    {
067        '\u0000', '\u0001', '\u0002', '\u0003', '\u009C', '\u0009', '\u0086', '\u007F', '\u0097', '\u008D', '\u008E',
068        '\u000B', '\u000C', 0xD, '\u000E', '\u000F', '\u0010', '\u0011', '\u0012', '\u0013', '\u009D', '\u0085',
069        '\u0008', '\u0087', '\u0018', '\u0019', '\u0092', '\u008F', '\u001C', '\u001D', '\u001E', '\u001F', '\u0080',
070        '\u0081', '\u0082', '\u0083', '\u0084', 0xA, '\u0017', '\u001B', '\u0088', '\u0089', '\u008A', '\u008B',
071        '\u008C', '\u0005', '\u0006', '\u0007', '\u0090', '\u0091', '\u0016', '\u0093', '\u0094', '\u0095', '\u0096',
072        '\u0004', '\u0098', '\u0099', '\u009A', '\u009B', '\u0014', '\u0015', '\u009E', '\u001A', '\u0020', '\u00A0',
073        '\u00E2', '\u007B', '\u00E0', '\u00E1', '\u00E3', '\u00E5', '\u00E7', '\u00F1', '\u00C4', '\u002E', '\u003C',
074        '\u0028', '\u002B', '\u0021', '\u0026', '\u00E9', '\u00EA', '\u00EB', '\u00E8', '\u00ED', '\u00EE', '\u00EF',
075        '\u00EC', '\u007E', '\u00DC', '\u0024', '\u002A', '\u0029', '\u003B', '\u005E', '\u002D', '\u002F', '\u00C2',
076        '\u005B', '\u00C0', '\u00C1', '\u00C3', '\u00C5', '\u00C7', '\u00D1', '\u00F6', '\u002C', '\u0025', '\u005F',
077        '\u003E', '\u003F', '\u00F8', '\u00C9', '\u00CA', '\u00CB', '\u00C8', '\u00CD', '\u00CE', '\u00CF', '\u00CC',
078        '\u0060', '\u003A', '\u0023', '\u00A7', 0x27, '\u003D', '\u0022', '\u00D8', '\u0061', '\u0062', '\u0063',
079        '\u0064', '\u0065', '\u0066', '\u0067', '\u0068', '\u0069', '\u00AB', '\u00BB', '\u00F0', '\u00FD', '\u00FE',
080        '\u00B1', '\u00B0', '\u006A', '\u006B', '\u006C', '\u006D', '\u006E', '\u006F', '\u0070', '\u0071', '\u0072',
081        '\u00AA', '\u00BA', '\u00E6', '\u00B8', '\u00C6', '\u00A4', '\u00B5', '\u00DF', '\u0073', '\u0074', '\u0075',
082        '\u0076', '\u0077', '\u0078', '\u0079', '\u007A', '\u00A1', '\u00BF', '\u00D0', '\u00DD', '\u00DE', '\u00AE',
083        '\u00A2', '\u00A3', '\u00A5', '\u00B7', '\u00A9', '\u0040', '\u00B6', '\u00BC', '\u00BD', '\u00BE', '\u00AC',
084        '\u007C', '\u203E', '\u00A8', '\u00B4', '\u00D7', '\u00E4', '\u0041', '\u0042', '\u0043', '\u0044', '\u0045',
085        '\u0046', '\u0047', '\u0048', '\u0049', '\u00AD', '\u00F4', '\u00A6', '\u00F2', '\u00F3', '\u00F5', '\u00FC',
086        '\u004A', '\u004B', '\u004C', '\u004D', '\u004E', '\u004F', '\u0050', '\u0051', '\u0052', '\u00B9', '\u00FB',
087        '\u007D', '\u00F9', '\u00FA', '\u00FF', '\u00D6', '\u00F7', '\u0053', '\u0054', '\u0055', '\u0056', '\u0057',
088        '\u0058', '\u0059', '\u005A', '\u00B2', '\u00D4', 0x5C, '\u00D2', '\u00D3', '\u00D5', '\u0030', '\u0031',
089        '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039', '\u00B3', '\u00DB', '\u005D',
090        '\u00D9', '\u00DA', '\u009F'
091    };
092
093    static final byte[] CHAR_TO_BYTE = new byte[ 0x203F ];
094
095    static
096    {
097        CHAR_TO_BYTE['\u0000'] = (byte) 0x00;
098        CHAR_TO_BYTE['\u0001'] = (byte) 0x01;
099        CHAR_TO_BYTE['\u0002'] = (byte) 0x02;
100        CHAR_TO_BYTE['\u0003'] = (byte) 0x03;
101        CHAR_TO_BYTE['\u009C'] = (byte) 0x04;
102        CHAR_TO_BYTE['\u0009'] = (byte) 0x05;
103        CHAR_TO_BYTE['\u0086'] = (byte) 0x06;
104        CHAR_TO_BYTE['\u007F'] = (byte) 0x07;
105        CHAR_TO_BYTE['\u0097'] = (byte) 0x08;
106        CHAR_TO_BYTE['\u008D'] = (byte) 0x09;
107        CHAR_TO_BYTE['\u008E'] = (byte) 0x0A;
108        CHAR_TO_BYTE['\u000B'] = (byte) 0x0B;
109        CHAR_TO_BYTE['\u000C'] = (byte) 0x0C;
110        CHAR_TO_BYTE[0xD] = (byte) 0x0D;
111        CHAR_TO_BYTE['\u000E'] = (byte) 0x0E;
112        CHAR_TO_BYTE['\u000F'] = (byte) 0x0F;
113        CHAR_TO_BYTE['\u0010'] = (byte) 0x10;
114        CHAR_TO_BYTE['\u0011'] = (byte) 0x11;
115        CHAR_TO_BYTE['\u0012'] = (byte) 0x12;
116        CHAR_TO_BYTE['\u0013'] = (byte) 0x13;
117        CHAR_TO_BYTE['\u009D'] = (byte) 0x14;
118        CHAR_TO_BYTE['\u0085'] = (byte) 0x15;
119        CHAR_TO_BYTE['\u0008'] = (byte) 0x16;
120        CHAR_TO_BYTE['\u0087'] = (byte) 0x17;
121        CHAR_TO_BYTE['\u0018'] = (byte) 0x18;
122        CHAR_TO_BYTE['\u0019'] = (byte) 0x19;
123        CHAR_TO_BYTE['\u0092'] = (byte) 0x1A;
124        CHAR_TO_BYTE['\u008F'] = (byte) 0x1B;
125        CHAR_TO_BYTE['\u001C'] = (byte) 0x1C;
126        CHAR_TO_BYTE['\u001D'] = (byte) 0x1D;
127        CHAR_TO_BYTE['\u001E'] = (byte) 0x1E;
128        CHAR_TO_BYTE['\u001F'] = (byte) 0x1F;
129        CHAR_TO_BYTE['\u0080'] = (byte) 0x20;
130        CHAR_TO_BYTE['\u0081'] = (byte) 0x21;
131        CHAR_TO_BYTE['\u0082'] = (byte) 0x22;
132        CHAR_TO_BYTE['\u0083'] = (byte) 0x23;
133        CHAR_TO_BYTE['\u0084'] = (byte) 0x24;
134        CHAR_TO_BYTE[0xA] = (byte) 0x25;
135        CHAR_TO_BYTE['\u0017'] = (byte) 0x26;
136        CHAR_TO_BYTE['\u001B'] = (byte) 0x27;
137        CHAR_TO_BYTE['\u0088'] = (byte) 0x28;
138        CHAR_TO_BYTE['\u0089'] = (byte) 0x29;
139        CHAR_TO_BYTE['\u008A'] = (byte) 0x2A;
140        CHAR_TO_BYTE['\u008B'] = (byte) 0x2B;
141        CHAR_TO_BYTE['\u008C'] = (byte) 0x2C;
142        CHAR_TO_BYTE['\u0005'] = (byte) 0x2D;
143        CHAR_TO_BYTE['\u0006'] = (byte) 0x2E;
144        CHAR_TO_BYTE['\u0007'] = (byte) 0x2F;
145        CHAR_TO_BYTE['\u0090'] = (byte) 0x30;
146        CHAR_TO_BYTE['\u0091'] = (byte) 0x31;
147        CHAR_TO_BYTE['\u0016'] = (byte) 0x32;
148        CHAR_TO_BYTE['\u0093'] = (byte) 0x33;
149        CHAR_TO_BYTE['\u0094'] = (byte) 0x34;
150        CHAR_TO_BYTE['\u0095'] = (byte) 0x35;
151        CHAR_TO_BYTE['\u0096'] = (byte) 0x36;
152        CHAR_TO_BYTE['\u0004'] = (byte) 0x37;
153        CHAR_TO_BYTE['\u0098'] = (byte) 0x38;
154        CHAR_TO_BYTE['\u0099'] = (byte) 0x39;
155        CHAR_TO_BYTE['\u009A'] = (byte) 0x3A;
156        CHAR_TO_BYTE['\u009B'] = (byte) 0x3B;
157        CHAR_TO_BYTE['\u0014'] = (byte) 0x3C;
158        CHAR_TO_BYTE['\u0015'] = (byte) 0x3D;
159        CHAR_TO_BYTE['\u009E'] = (byte) 0x3E;
160        CHAR_TO_BYTE['\u001A'] = (byte) 0x3F;
161        CHAR_TO_BYTE['\u0020'] = (byte) 0x40;
162        CHAR_TO_BYTE['\u00A0'] = (byte) 0x41;
163        CHAR_TO_BYTE['\u00E2'] = (byte) 0x42;
164        CHAR_TO_BYTE['\u007B'] = (byte) 0x43;
165        CHAR_TO_BYTE['\u00E0'] = (byte) 0x44;
166        CHAR_TO_BYTE['\u00E1'] = (byte) 0x45;
167        CHAR_TO_BYTE['\u00E3'] = (byte) 0x46;
168        CHAR_TO_BYTE['\u00E5'] = (byte) 0x47;
169        CHAR_TO_BYTE['\u00E7'] = (byte) 0x48;
170        CHAR_TO_BYTE['\u00F1'] = (byte) 0x49;
171        CHAR_TO_BYTE['\u00C4'] = (byte) 0x4A;
172        CHAR_TO_BYTE['\u002E'] = (byte) 0x4B;
173        CHAR_TO_BYTE['\u003C'] = (byte) 0x4C;
174        CHAR_TO_BYTE['\u0028'] = (byte) 0x4D;
175        CHAR_TO_BYTE['\u002B'] = (byte) 0x4E;
176        CHAR_TO_BYTE['\u0021'] = (byte) 0x4F;
177        CHAR_TO_BYTE['\u0026'] = (byte) 0x50;
178        CHAR_TO_BYTE['\u00E9'] = (byte) 0x51;
179        CHAR_TO_BYTE['\u00EA'] = (byte) 0x52;
180        CHAR_TO_BYTE['\u00EB'] = (byte) 0x53;
181        CHAR_TO_BYTE['\u00E8'] = (byte) 0x54;
182        CHAR_TO_BYTE['\u00ED'] = (byte) 0x55;
183        CHAR_TO_BYTE['\u00EE'] = (byte) 0x56;
184        CHAR_TO_BYTE['\u00EF'] = (byte) 0x57;
185        CHAR_TO_BYTE['\u00EC'] = (byte) 0x58;
186        CHAR_TO_BYTE['\u007E'] = (byte) 0x59;
187        CHAR_TO_BYTE['\u00DC'] = (byte) 0x5A;
188        CHAR_TO_BYTE['\u0024'] = (byte) 0x5B;
189        CHAR_TO_BYTE['\u002A'] = (byte) 0x5C;
190        CHAR_TO_BYTE['\u0029'] = (byte) 0x5D;
191        CHAR_TO_BYTE['\u003B'] = (byte) 0x5E;
192        CHAR_TO_BYTE['\u005E'] = (byte) 0x5F;
193        CHAR_TO_BYTE['\u002D'] = (byte) 0x60;
194        CHAR_TO_BYTE['\u002F'] = (byte) 0x61;
195        CHAR_TO_BYTE['\u00C2'] = (byte) 0x62;
196        CHAR_TO_BYTE['\u005B'] = (byte) 0x63;
197        CHAR_TO_BYTE['\u00C0'] = (byte) 0x64;
198        CHAR_TO_BYTE['\u00C1'] = (byte) 0x65;
199        CHAR_TO_BYTE['\u00C3'] = (byte) 0x66;
200        CHAR_TO_BYTE['\u00C5'] = (byte) 0x67;
201        CHAR_TO_BYTE['\u00C7'] = (byte) 0x68;
202        CHAR_TO_BYTE['\u00D1'] = (byte) 0x69;
203        CHAR_TO_BYTE['\u00F6'] = (byte) 0x6A;
204        CHAR_TO_BYTE['\u002C'] = (byte) 0x6B;
205        CHAR_TO_BYTE['\u0025'] = (byte) 0x6C;
206        CHAR_TO_BYTE['\u005F'] = (byte) 0x6D;
207        CHAR_TO_BYTE['\u003E'] = (byte) 0x6E;
208        CHAR_TO_BYTE['\u003F'] = (byte) 0x6F;
209        CHAR_TO_BYTE['\u00F8'] = (byte) 0x70;
210        CHAR_TO_BYTE['\u00C9'] = (byte) 0x71;
211        CHAR_TO_BYTE['\u00CA'] = (byte) 0x72;
212        CHAR_TO_BYTE['\u00CB'] = (byte) 0x73;
213        CHAR_TO_BYTE['\u00C8'] = (byte) 0x74;
214        CHAR_TO_BYTE['\u00CD'] = (byte) 0x75;
215        CHAR_TO_BYTE['\u00CE'] = (byte) 0x76;
216        CHAR_TO_BYTE['\u00CF'] = (byte) 0x77;
217        CHAR_TO_BYTE['\u00CC'] = (byte) 0x78;
218        CHAR_TO_BYTE['\u0060'] = (byte) 0x79;
219        CHAR_TO_BYTE['\u003A'] = (byte) 0x7A;
220        CHAR_TO_BYTE['\u0023'] = (byte) 0x7B;
221        CHAR_TO_BYTE['\u00A7'] = (byte) 0x7C;
222        CHAR_TO_BYTE[0x27] = (byte) 0x7D;
223        CHAR_TO_BYTE['\u003D'] = (byte) 0x7E;
224        CHAR_TO_BYTE['\u0022'] = (byte) 0x7F;
225        CHAR_TO_BYTE['\u00D8'] = (byte) 0x80;
226        CHAR_TO_BYTE['\u0061'] = (byte) 0x81;
227        CHAR_TO_BYTE['\u0062'] = (byte) 0x82;
228        CHAR_TO_BYTE['\u0063'] = (byte) 0x83;
229        CHAR_TO_BYTE['\u0064'] = (byte) 0x84;
230        CHAR_TO_BYTE['\u0065'] = (byte) 0x85;
231        CHAR_TO_BYTE['\u0066'] = (byte) 0x86;
232        CHAR_TO_BYTE['\u0067'] = (byte) 0x87;
233        CHAR_TO_BYTE['\u0068'] = (byte) 0x88;
234        CHAR_TO_BYTE['\u0069'] = (byte) 0x89;
235        CHAR_TO_BYTE['\u00AB'] = (byte) 0x8A;
236        CHAR_TO_BYTE['\u00BB'] = (byte) 0x8B;
237        CHAR_TO_BYTE['\u00F0'] = (byte) 0x8C;
238        CHAR_TO_BYTE['\u00FD'] = (byte) 0x8D;
239        CHAR_TO_BYTE['\u00FE'] = (byte) 0x8E;
240        CHAR_TO_BYTE['\u00B1'] = (byte) 0x8F;
241        CHAR_TO_BYTE['\u00B0'] = (byte) 0x90;
242        CHAR_TO_BYTE['\u006A'] = (byte) 0x91;
243        CHAR_TO_BYTE['\u006B'] = (byte) 0x92;
244        CHAR_TO_BYTE['\u006C'] = (byte) 0x93;
245        CHAR_TO_BYTE['\u006D'] = (byte) 0x94;
246        CHAR_TO_BYTE['\u006E'] = (byte) 0x95;
247        CHAR_TO_BYTE['\u006F'] = (byte) 0x96;
248        CHAR_TO_BYTE['\u0070'] = (byte) 0x97;
249        CHAR_TO_BYTE['\u0071'] = (byte) 0x98;
250        CHAR_TO_BYTE['\u0072'] = (byte) 0x99;
251        CHAR_TO_BYTE['\u00AA'] = (byte) 0x9A;
252        CHAR_TO_BYTE['\u00BA'] = (byte) 0x9B;
253        CHAR_TO_BYTE['\u00E6'] = (byte) 0x9C;
254        CHAR_TO_BYTE['\u00B8'] = (byte) 0x9D;
255        CHAR_TO_BYTE['\u00C6'] = (byte) 0x9E;
256        CHAR_TO_BYTE['\u00A4'] = (byte) 0x9F;
257        CHAR_TO_BYTE['\u00B5'] = (byte) 0xA0;
258        CHAR_TO_BYTE['\u00DF'] = (byte) 0xA1;
259        CHAR_TO_BYTE['\u0073'] = (byte) 0xA2;
260        CHAR_TO_BYTE['\u0074'] = (byte) 0xA3;
261        CHAR_TO_BYTE['\u0075'] = (byte) 0xA4;
262        CHAR_TO_BYTE['\u0076'] = (byte) 0xA5;
263        CHAR_TO_BYTE['\u0077'] = (byte) 0xA6;
264        CHAR_TO_BYTE['\u0078'] = (byte) 0xA7;
265        CHAR_TO_BYTE['\u0079'] = (byte) 0xA8;
266        CHAR_TO_BYTE['\u007A'] = (byte) 0xA9;
267        CHAR_TO_BYTE['\u00A1'] = (byte) 0xAA;
268        CHAR_TO_BYTE['\u00BF'] = (byte) 0xAB;
269        CHAR_TO_BYTE['\u00D0'] = (byte) 0xAC;
270        CHAR_TO_BYTE['\u00DD'] = (byte) 0xAD;
271        CHAR_TO_BYTE['\u00DE'] = (byte) 0xAE;
272        CHAR_TO_BYTE['\u00AE'] = (byte) 0xAF;
273        CHAR_TO_BYTE['\u00A2'] = (byte) 0xB0;
274        CHAR_TO_BYTE['\u00A3'] = (byte) 0xB1;
275        CHAR_TO_BYTE['\u00A5'] = (byte) 0xB2;
276        CHAR_TO_BYTE['\u00B7'] = (byte) 0xB3;
277        CHAR_TO_BYTE['\u00A9'] = (byte) 0xB4;
278        CHAR_TO_BYTE['\u0040'] = (byte) 0xB5;
279        CHAR_TO_BYTE['\u00B6'] = (byte) 0xB6;
280        CHAR_TO_BYTE['\u00BC'] = (byte) 0xB7;
281        CHAR_TO_BYTE['\u00BD'] = (byte) 0xB8;
282        CHAR_TO_BYTE['\u00BE'] = (byte) 0xB9;
283        CHAR_TO_BYTE['\u00AC'] = (byte) 0xBA;
284        CHAR_TO_BYTE['\u007C'] = (byte) 0xBB;
285        CHAR_TO_BYTE['\u203E'] = (byte) 0xBC;
286        CHAR_TO_BYTE['\u00A8'] = (byte) 0xBD;
287        CHAR_TO_BYTE['\u00B4'] = (byte) 0xBE;
288        CHAR_TO_BYTE['\u00D7'] = (byte) 0xBF;
289        CHAR_TO_BYTE['\u00E4'] = (byte) 0xC0;
290        CHAR_TO_BYTE['\u0041'] = (byte) 0xC1;
291        CHAR_TO_BYTE['\u0042'] = (byte) 0xC2;
292        CHAR_TO_BYTE['\u0043'] = (byte) 0xC3;
293        CHAR_TO_BYTE['\u0044'] = (byte) 0xC4;
294        CHAR_TO_BYTE['\u0045'] = (byte) 0xC5;
295        CHAR_TO_BYTE['\u0046'] = (byte) 0xC6;
296        CHAR_TO_BYTE['\u0047'] = (byte) 0xC7;
297        CHAR_TO_BYTE['\u0048'] = (byte) 0xC8;
298        CHAR_TO_BYTE['\u0049'] = (byte) 0xC9;
299        CHAR_TO_BYTE['\u00AD'] = (byte) 0xCA;
300        CHAR_TO_BYTE['\u00F4'] = (byte) 0xCB;
301        CHAR_TO_BYTE['\u00A6'] = (byte) 0xCC;
302        CHAR_TO_BYTE['\u00F2'] = (byte) 0xCD;
303        CHAR_TO_BYTE['\u00F3'] = (byte) 0xCE;
304        CHAR_TO_BYTE['\u00F5'] = (byte) 0xCF;
305        CHAR_TO_BYTE['\u00FC'] = (byte) 0xD0;
306        CHAR_TO_BYTE['\u004A'] = (byte) 0xD1;
307        CHAR_TO_BYTE['\u004B'] = (byte) 0xD2;
308        CHAR_TO_BYTE['\u004C'] = (byte) 0xD3;
309        CHAR_TO_BYTE['\u004D'] = (byte) 0xD4;
310        CHAR_TO_BYTE['\u004E'] = (byte) 0xD5;
311        CHAR_TO_BYTE['\u004F'] = (byte) 0xD6;
312        CHAR_TO_BYTE['\u0050'] = (byte) 0xD7;
313        CHAR_TO_BYTE['\u0051'] = (byte) 0xD8;
314        CHAR_TO_BYTE['\u0052'] = (byte) 0xD9;
315        CHAR_TO_BYTE['\u00B9'] = (byte) 0xDA;
316        CHAR_TO_BYTE['\u00FB'] = (byte) 0xDB;
317        CHAR_TO_BYTE['\u007D'] = (byte) 0xDC;
318        CHAR_TO_BYTE['\u00F9'] = (byte) 0xDD;
319        CHAR_TO_BYTE['\u00FA'] = (byte) 0xDE;
320        CHAR_TO_BYTE['\u00FF'] = (byte) 0xDF;
321        CHAR_TO_BYTE['\u00D6'] = (byte) 0xE0;
322        CHAR_TO_BYTE['\u00F7'] = (byte) 0xE1;
323        CHAR_TO_BYTE['\u0053'] = (byte) 0xE2;
324        CHAR_TO_BYTE['\u0054'] = (byte) 0xE3;
325        CHAR_TO_BYTE['\u0055'] = (byte) 0xE4;
326        CHAR_TO_BYTE['\u0056'] = (byte) 0xE5;
327        CHAR_TO_BYTE['\u0057'] = (byte) 0xE6;
328        CHAR_TO_BYTE['\u0058'] = (byte) 0xE7;
329        CHAR_TO_BYTE['\u0059'] = (byte) 0xE8;
330        CHAR_TO_BYTE['\u005A'] = (byte) 0xE9;
331        CHAR_TO_BYTE['\u00B2'] = (byte) 0xEA;
332        CHAR_TO_BYTE['\u00D4'] = (byte) 0xEB;
333        CHAR_TO_BYTE[0x5C] = (byte) 0xEC;
334        CHAR_TO_BYTE['\u00D2'] = (byte) 0xED;
335        CHAR_TO_BYTE['\u00D3'] = (byte) 0xEE;
336        CHAR_TO_BYTE['\u00D5'] = (byte) 0xEF;
337        CHAR_TO_BYTE['\u0030'] = (byte) 0xF0;
338        CHAR_TO_BYTE['\u0031'] = (byte) 0xF1;
339        CHAR_TO_BYTE['\u0032'] = (byte) 0xF2;
340        CHAR_TO_BYTE['\u0033'] = (byte) 0xF3;
341        CHAR_TO_BYTE['\u0034'] = (byte) 0xF4;
342        CHAR_TO_BYTE['\u0035'] = (byte) 0xF5;
343        CHAR_TO_BYTE['\u0036'] = (byte) 0xF6;
344        CHAR_TO_BYTE['\u0037'] = (byte) 0xF7;
345        CHAR_TO_BYTE['\u0038'] = (byte) 0xF8;
346        CHAR_TO_BYTE['\u0039'] = (byte) 0xF9;
347        CHAR_TO_BYTE['\u00B3'] = (byte) 0xFA;
348        CHAR_TO_BYTE['\u00DB'] = (byte) 0xFB;
349        CHAR_TO_BYTE['\u005D'] = (byte) 0xFC;
350        CHAR_TO_BYTE['\u00D9'] = (byte) 0xFD;
351        CHAR_TO_BYTE['\u00DA'] = (byte) 0xFE;
352        CHAR_TO_BYTE['\u009F'] = (byte) 0xFF;
353    }
354
355    /** Creates a new {@code IBM273CharsetProvider} instance. */
356    public IBM273CharsetProvider()
357    {
358        super();
359    }
360
361    public Charset charsetForName( final String charsetName )
362    {
363        Charset ret = null;
364
365        if ( charsetName != null )
366        {
367            final String lower = charsetName.toLowerCase();
368            for ( int i = 0; i < SUPPORTED_NAMES.length; i++ )
369            {
370                if ( SUPPORTED_NAMES[i].equals( lower ) )
371                {
372                    ret = new IBM273Charset();
373                    break;
374                }
375            }
376        }
377
378        return ret;
379    }
380
381    public Iterator charsets()
382    {
383        return new Iterator()
384        {
385
386            private boolean hasNext = true;
387
388            public boolean hasNext()
389            {
390                return this.hasNext;
391            }
392
393            public Object next()
394            {
395                if ( this.hasNext )
396                {
397                    this.hasNext = false;
398                    return new IBM273Charset();
399                }
400                else
401                {
402                    throw new NoSuchElementException();
403                }
404
405            }
406
407            public void remove()
408            {
409                throw new UnsupportedOperationException();
410            }
411
412        };
413    }
414
415}
416
417/** IBM273 {@code Charset} implementation. */
418class IBM273Charset extends Charset
419{
420
421    public IBM273Charset()
422    {
423        super( IBM273CharsetProvider.COMMON_NAME, IBM273CharsetProvider.ALIAS_NAMES );
424    }
425
426    public CharsetEncoder newEncoder()
427    {
428        return new IBM273CharsetEncoder( this );
429    }
430
431    public CharsetDecoder newDecoder()
432    {
433        return new IBM273CharsetDecoder( this );
434    }
435
436    public boolean contains( final Charset charset )
437    {
438        return false;
439    }
440
441    static boolean isCharacterSupported( final char c )
442    {
443        return ( c >= '\u0000' && c <= '\u00AE' ) || ( c >= '\u00B0' && c <= '\u00FF' ) || c == '\u203E';
444    }
445
446}
447
448class IBM273CharsetEncoder extends CharsetEncoder
449{
450
451    private final char[] charBuf = new char[ 65536 ];
452
453    IBM273CharsetEncoder( final Charset charset )
454    {
455        super( charset, 1f, 1f );
456        this.onUnmappableCharacter( CodingErrorAction.REPLACE );
457    }
458
459    protected CoderResult encodeLoop( final CharBuffer in, final ByteBuffer buf )
460    {
461        if ( in.hasArray() && buf.hasArray() )
462        {
463            return encodeLoopArray( in, buf );
464        }
465
466        while ( in.hasRemaining() )
467        {
468            in.mark();
469
470            final int len;
471            if ( in.remaining() < this.charBuf.length )
472            {
473                len = in.remaining();
474                in.get( this.charBuf, 0, in.remaining() );
475            }
476            else
477            {
478                in.get( this.charBuf, 0, this.charBuf.length );
479                len = this.charBuf.length;
480            }
481
482            for ( int i = 0; i < len; i++ )
483            {
484                if ( !buf.hasRemaining() )
485                {
486                    in.reset();
487                    in.position( in.position() + i );
488                    return CoderResult.OVERFLOW;
489                }
490
491                if ( !IBM273Charset.isCharacterSupported( this.charBuf[i] ) )
492                {
493                    in.reset();
494                    in.position( in.position() + i );
495                    return CoderResult.unmappableForLength( 1 );
496                }
497
498                buf.put( IBM273CharsetProvider.CHAR_TO_BYTE[this.charBuf[i]] );
499            }
500        }
501
502        return CoderResult.UNDERFLOW;
503    }
504
505    private static CoderResult encodeLoopArray( final CharBuffer in, final ByteBuffer buf )
506    {
507        final int len = in.remaining();
508        for ( int i = 0; i < len; i++, in.position( in.position() + 1 ), buf.position( buf.position() + 1 ) )
509        {
510            if ( !buf.hasRemaining() )
511            {
512                return CoderResult.OVERFLOW;
513            }
514
515            if ( !IBM273Charset.isCharacterSupported( in.array()[in.position() + in.arrayOffset()] ) )
516            {
517                return CoderResult.unmappableForLength( 1 );
518            }
519
520            buf.array()[buf.position() + buf.arrayOffset()] =
521                IBM273CharsetProvider.CHAR_TO_BYTE[in.array()[in.position() + in.arrayOffset()]];
522
523        }
524
525        return CoderResult.UNDERFLOW;
526    }
527
528}
529
530class IBM273CharsetDecoder extends CharsetDecoder
531{
532
533    private final byte[] byteBuf = new byte[ 65536 ];
534
535    IBM273CharsetDecoder( final Charset charset )
536    {
537        super( charset, 1f, 1f );
538        this.onUnmappableCharacter( CodingErrorAction.REPLACE );
539    }
540
541    protected CoderResult decodeLoop( final ByteBuffer in, final CharBuffer buf )
542    {
543        if ( in.hasArray() && buf.hasArray() )
544        {
545            return decodeLoopArray( in, buf );
546        }
547
548        while ( in.hasRemaining() )
549        {
550            in.mark();
551
552            final int len;
553            if ( in.remaining() < this.byteBuf.length )
554            {
555                len = in.remaining();
556                in.get( this.byteBuf, 0, in.remaining() );
557            }
558            else
559            {
560                in.get( this.byteBuf, 0, this.byteBuf.length );
561                len = this.byteBuf.length;
562            }
563
564            for ( int i = 0; i < len; i++ )
565            {
566                if ( !buf.hasRemaining() )
567                {
568                    in.reset();
569                    in.position( in.position() + i );
570                    return CoderResult.OVERFLOW;
571                }
572
573                buf.put( IBM273CharsetProvider.BYTE_TO_CHAR[this.byteBuf[i] & 0xFF] );
574            }
575        }
576
577        return CoderResult.UNDERFLOW;
578    }
579
580    private static CoderResult decodeLoopArray( final ByteBuffer in, final CharBuffer buf )
581    {
582        final int len = in.remaining();
583        for ( int i = 0; i < len; i++, in.position( in.position() + 1 ), buf.position( buf.position() + 1 ) )
584        {
585            if ( !buf.hasRemaining() )
586            {
587                return CoderResult.OVERFLOW;
588            }
589
590            buf.array()[buf.position() + buf.arrayOffset()] =
591                IBM273CharsetProvider.BYTE_TO_CHAR[in.array()[in.position() + in.arrayOffset()] & 0xFF];
592
593        }
594
595        return CoderResult.UNDERFLOW;
596    }
597
598}