diff --git a/pgjdbc/src/main/java/org/postgresql/core/Encoding.java b/pgjdbc/src/main/java/org/postgresql/core/Encoding.java index 5e71b224c1..8479577259 100644 --- a/pgjdbc/src/main/java/org/postgresql/core/Encoding.java +++ b/pgjdbc/src/main/java/org/postgresql/core/Encoding.java @@ -87,22 +87,34 @@ private Encoding() { } /** - * Use the charset passed as parameter. + * Subclasses may use this constructor if they know in advance of their ASCII number + * compatibility. * * @param encoding charset name to use + * @param fastASCIINumbers whether this encoding is compatible with ASCII numbers. */ - protected Encoding(String encoding) { + protected Encoding(String encoding, boolean fastASCIINumbers) { if (encoding == null) { throw new NullPointerException("Null encoding charset not supported"); } this.encoding = encoding; - this.fastASCIINumbers = testAsciiNumbers(encoding); + this.fastASCIINumbers = fastASCIINumbers; if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.log(Level.FINEST, "Creating new Encoding {0} with fastASCIINumbers {1}", new Object[]{encoding, fastASCIINumbers}); } } + /** + * Use the charset passed as parameter and tests at creation time whether the specified encoding + * is compatible with ASCII numbers. + * + * @param encoding charset name to use + */ + protected Encoding(String encoding) { + this(encoding, testAsciiNumbers(encoding)); + } + /** * Returns true if this encoding has characters '-' and '0'..'9' in exactly same posision as * ascii. @@ -122,7 +134,7 @@ public boolean hasAsciiNumbers() { */ public static Encoding getJVMEncoding(String jvmEncoding) { if ("UTF-8".equals(jvmEncoding)) { - return new UTF8Encoding(jvmEncoding); + return new UTF8Encoding(); } if (Charset.isSupported(jvmEncoding)) { return new Encoding(jvmEncoding); diff --git a/pgjdbc/src/main/java/org/postgresql/core/UTF8Encoding.java b/pgjdbc/src/main/java/org/postgresql/core/UTF8Encoding.java index 3ae6cb12f7..35a2047f19 100644 --- a/pgjdbc/src/main/java/org/postgresql/core/UTF8Encoding.java +++ b/pgjdbc/src/main/java/org/postgresql/core/UTF8Encoding.java @@ -17,8 +17,8 @@ class UTF8Encoding extends Encoding { private char[] decoderArray = new char[1024]; - UTF8Encoding(String jvmEncoding) { - super(jvmEncoding); + UTF8Encoding() { + super("UTF-8", true); } // helper for decode