? .settings ? bin Index: org/postgresql/util/PGbytea.java =================================================================== RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/util/PGbytea.java,v retrieving revision 1.17 diff -u -w -r1.17 PGbytea.java --- org/postgresql/util/PGbytea.java 6 Apr 2010 23:45:09 -0000 1.17 +++ org/postgresql/util/PGbytea.java 21 Jun 2011 12:25:14 -0000 @@ -9,7 +9,8 @@ */ package org.postgresql.util; -import java.sql.*; +import java.sql.SQLException; +import java.util.Arrays; /** * Converts to and from the postgresql bytea datatype used by the backend. @@ -18,6 +19,36 @@ { private static final int MAX_3_BUFF_SIZE = 2 * 1024 * 1024; + private static final byte[][] HEX_LOOKUP = new byte[103][103]; + + static { + // build the hex lookup table + for (int i = 0; i < 256; ++i) { + int lo = i & 0x0f; + int lo2 = lo; + int hi = (i & 0xf0) >> 4; + int hi2 = hi; + // 0-9 == 48-57 + // a-f == 97-102 + // A-F == 65-70 + if (lo < 10) { + lo += 48; + lo2 = lo; + } else { + lo += 87; + lo2 += 55; + } + if (hi < 10) { + hi += 48; + hi2 = hi; + } else { + hi += 87; + hi2 += 55; + } + HEX_LOOKUP[lo][hi] = (byte)i; + } + } + /* * Converts a PG bytea raw value (i.e. the raw binary representation * of the bytea data type) into a java byte[] @@ -37,30 +68,14 @@ return toBytesHexEscaped(s); } - private static byte[] toBytesHexEscaped(byte[] s) + private static byte[] toBytesHexEscaped(final byte[] s) { - byte[] output = new byte[(s.length - 2) / 2]; - for (int i=0; i= 97) - return (byte)(b - 97 + 10); - - // A-F == 65-70 - return (byte)(b - 65 + 10); - } - private static byte[] toBytesOctalEscaped(byte[] s) { final int slength = s.length;