org.firebirdsql.encodings.CharacterTranslator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jaybird-jdk18 Show documentation
Show all versions of jaybird-jdk18 Show documentation
JDBC Driver for the Firebird RDBMS
/*
* Firebird Open Source JavaEE Connector - JDBC Driver
*
* Distributable under LGPL license.
* You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* LGPL License for more details.
*
* This file was created by members of the firebird development team.
* All individual contributions remain the Copyright (C) of those
* individuals. Contributors to this file are either listed here or
* can be obtained from a source control history command.
*
* All rights reserved.
*/
package org.firebirdsql.encodings;
import java.sql.SQLException;
import java.sql.SQLNonTransientException;
import java.util.*;
/**
* Class responsible for character translation.
*
* @deprecated To be removed in Jaybird 4
*/
@Deprecated
public final class CharacterTranslator {
/**
* Default mapping table, provides an "identity" mapping of characters
*/
private static final char[] DEFAULT_MAPPING;
private static final int FULL_CHAR_RANGE = 256 * 256;
/**
* CharacterTranslator with the identity mapping established by {@link #DEFAULT_MAPPING};
*/
public static final CharacterTranslator IDENTITY_TRANSLATOR;
static {
DEFAULT_MAPPING = new char[FULL_CHAR_RANGE];
for (int i = 0; i < DEFAULT_MAPPING.length; i++) {
DEFAULT_MAPPING[i] = (char) i;
}
IDENTITY_TRANSLATOR = new CharacterTranslator(DEFAULT_MAPPING);
}
private final char[] mapping;
private CharacterTranslator(char[] mapping) {
assert mapping.length == FULL_CHAR_RANGE
: "Invalid length for mapping table"; // need to cover all possible char values
this.mapping = mapping;
}
/**
* Get mapping table.
*
* @return mapping table.
*/
public char[] getMapping() {
return mapping.clone();
}
/**
* Get mapping for the specified character.
*
* @param toMap
* character to map.
* @return mapped character.
*/
public char getMapping(char toMap) {
return mapping[toMap];
}
/**
* Initialize this class with the specified mapping.
*
* @param mappingPath
* path to the .properties file with the corresponding mapping.
* @throws SQLException
* if I/O error occurred or specified mapping is incorrect or cannot be found.
*/
public static CharacterTranslator create(String mappingPath) throws SQLException {
Properties props = new Properties();
try {
ResourceBundle res = ResourceBundle.getBundle(
mappingPath, Locale.getDefault(), CharacterTranslator.class.getClassLoader());
Enumeration en = res.getKeys();
while (en.hasMoreElements()) {
String key = en.nextElement();
String value = res.getString(key);
props.put(key, value);
}
final char[] mapping = DEFAULT_MAPPING.clone();
for (Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy