comparison app/src/main/java/org/tn5250j/encoding/builtin/CodepageConverterAdapter.java @ 438:d29cce60f393

migrate from Eclipse to Android Studio
author Carl Byington <carl@five-ten-sg.com>
date Thu, 03 Dec 2015 11:23:55 -0800
parents src/org/tn5250j/encoding/builtin/CodepageConverterAdapter.java@77ac18bc1b2f
children
comparison
equal deleted inserted replaced
437:208b31032318 438:d29cce60f393
1 /**
2 * $Id$
3 *
4 * Title: tn5250J
5 * Copyright: Copyright (c) 2001,2009
6 * Company:
7 * @author: master_jaf
8 *
9 * Description:
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this software; see the file COPYING. If not, write to
23 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
24 * Boston, MA 02111-1307 USA
25 *
26 */
27 package org.tn5250j.encoding.builtin;
28
29 import java.util.Arrays;
30
31 /**
32 * Adapter class for converters using 8bit codepages.
33 *
34 * @author master_jaf
35 */
36 public abstract class CodepageConverterAdapter implements ICodepageConverter {
37
38 private char[] codepage = null;
39 private int[] reverse_codepage = null;
40
41 /* (non-Javadoc)
42 * @see org.tn5250j.cp.ICodepageConverter#init()
43 */
44 public ICodepageConverter init() {
45 codepage = getCodePage();
46 int size = 0;
47
48 for (int i = 0; i < codepage.length; i++) {
49 size = Math.max(size, codepage[i]);
50 }
51
52 assert(size + 1) < 1024 * 1024; // some kind of maximum size limiter.
53 reverse_codepage = new int[size + 1];
54 Arrays.fill(reverse_codepage, '?');
55
56 for (int i = 0; i < codepage.length; i++) {
57 reverse_codepage[codepage[i]] = i;
58 }
59
60 return this;
61 }
62
63 /* (non-Javadoc)
64 * @see org.tn5250j.cp.ICodepageConverter#uni2ebcdic(char)
65 */
66 public byte uni2ebcdic(char index) {
67 assert index < reverse_codepage.length;
68 return (byte)reverse_codepage[index];
69 }
70
71 /* (non-Javadoc)
72 * @see org.tn5250j.cp.ICodepageConverter#ebcdic2uni(int)
73 */
74 public char ebcdic2uni(int index) {
75 index = index & 0xFF;
76 assert index < 256;
77 return codepage[index];
78 }
79
80 /**
81 * @return The oringal 8bit codepage.
82 */
83 protected abstract char[] getCodePage();
84
85 }