1 //$Id: CharConverter.java,v 1.3 2008/10/17 06:47:06 haschart Exp $
\r
3 * Copyright (C) 2005 Bas Peters
\r
5 * This file is part of MARC4J
\r
7 * MARC4J is free software; you can redistribute it and/or
\r
8 * modify it under the terms of the GNU Lesser General Public
\r
9 * License as published by the Free Software Foundation; either
\r
10 * version 2.1 of the License, or (at your option) any later version.
\r
12 * MARC4J is distributed in the hope that it will be useful,
\r
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
15 * Lesser General Public License for more details.
\r
17 * You should have received a copy of the GNU Lesser General Public
\r
18 * License along with MARC4J; if not, write to the Free Software
\r
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
22 package org.marc4j.converter;
\r
25 * Extend this class to create a character converter.
\r
27 * @author Bas Peters
\r
28 * @version $Revision: 1.3 $
\r
30 public abstract class CharConverter {
\r
33 * The method that needs to be implemented in a subclass to create a CharConverter.
\r
34 * Receives a data element extracted from a record as a array of characters, and
\r
35 * converts that data and returns the result as a <code>String</code> object.
\r
37 * @param dataElement the data to convert
\r
38 * @return String the conversion result
\r
40 public abstract String convert(char[] dataElement);
\r
43 * Alternate method for performing a character conversion. Receives the incoming
\r
44 * as a byte array, converts the bytes to characters, and calls the above convert method
\r
45 * which must be implemented in the subclass.
\r
47 * @param dataElement the data to convert
\r
48 * @return String the conversion result
\r
50 final public String convert(byte[] dataElement)
\r
52 char cData[] = new char[dataElement.length];
\r
53 for (int i = 0; i < dataElement.length; i++)
\r
55 byte b = dataElement[i];
\r
56 cData[i] = (char)(b >= 0 ? b : 256 + b);
\r
58 return convert(cData);
\r
62 * Alternate method for performing a character conversion. Receives the incoming
\r
63 * as a String, converts the String to a character array, and calls the above convert
\r
64 * method which must be implemented in the subclass.
\r
66 * @param dataElement the data to convert
\r
67 * @return String the conversion result
\r
69 final public String convert(String dataElement)
\r
72 data = dataElement.toCharArray();
\r
73 return (convert(data));
\r