private static byte[] toBytesHexEscaped(byte[] s) { byte[] output = new byte[(s.length - 2) / 2]; for (int i = 0; i < output.length; i++) { byte b1 = gethex(s[2 + i * 2]); byte b2 = gethex(s[2 + i * 2 + 1]); // squid:S3034 // Raw byte values should not be used in bitwise operations in combination with shifts output[i] = (byte) ((b1 << 4) | (b2 & 0xff)); } return output; }
public static byte[] toBytes(byte[] s) throws SQLException { if (s == null) { return null; } // Starting with PG 9.0, a new hex format is supported // that starts with "\x". Figure out which format we're // dealing with here. // if (s.length < 2 || s[0] != '\\' || s[1] != 'x') { return toBytesOctalEscaped(s); } return toBytesHexEscaped(s); }
/** * {@inheritDoc} * * <p>In normal use, the bytes represent the raw values returned by the backend. However, if the * column is an OID, then it is assumed to refer to a Large Object, and that object is returned as * a byte array.</p> * * <p><b>Be warned</b> If the large object is huge, then you may run out of memory.</p> */ public byte[] getBytes(int columnIndex) throws SQLException { connection.getLogger().log(Level.FINEST, " getBytes columnIndex: {0}", columnIndex); checkResultSet(columnIndex); if (wasNullFlag) { return null; } if (isBinary(columnIndex)) { // If the data is already binary then just return it return this_row[columnIndex - 1]; } if (fields[columnIndex - 1].getOID() == Oid.BYTEA) { return trimBytes(columnIndex, PGbytea.toBytes(this_row[columnIndex - 1])); } else { return trimBytes(columnIndex, this_row[columnIndex - 1]); } }
} else { try { rowBuffer[columnIndex] = PGbytea.toPGString((byte[]) valueObject).getBytes("ISO-8859-1"); } catch (UnsupportedEncodingException e) { throw new PSQLException(GT.tr("The JVM claims not to support the encoding: {0}", "ISO-8859-1"), PSQLState.UNEXPECTED_ERROR, e);
return trimBytes(columnIndex, PGbytea.toBytes(this_row[columnIndex - 1]));
try { rowBuffer[columnIndex] = PGbytea.toPGString((byte[]) valueObject).getBytes("ISO-8859-1"); } catch (UnsupportedEncodingException e) { throw new PSQLException(
public static byte[] toBytes(byte[] s) throws SQLException { if (s == null) return null; // Starting with PG 9.0, a new hex format is supported // that starts with "\x". Figure out which format we're // dealing with here. // if (s.length < 2 || s[0] != '\\' || s[1] != 'x') { return toBytesOctalEscaped(s); } return toBytesHexEscaped(s); }
return trimBytes(columnIndex, PGbytea.toBytes(this_row[columnIndex - 1]));
} else { try { rowBuffer[columnIndex] = PGbytea.toPGString((byte[]) valueObject).getBytes("ISO-8859-1"); } catch (UnsupportedEncodingException e) { throw new PSQLException(GT.tr("The JVM claims not to support the encoding: {0}", "ISO-8859-1"), PSQLState.UNEXPECTED_ERROR, e);
public static byte[] toBytes(byte[] s) throws SQLException { if (s == null) return null; // Starting with PG 9.0, a new hex format is supported // that starts with "\x". Figure out which format we're // dealing with here. // if (s.length < 2 || s[0] != '\\' || s[1] != 'x') { return toBytesOctalEscaped(s); } return toBytesHexEscaped(s); }
return trimBytes(columnIndex, PGbytea.toBytes(this_row[columnIndex - 1]));
} else { try { rowBuffer[columnIndex] = PGbytea.toPGString((byte[]) valueObject).getBytes("ISO-8859-1"); } catch (UnsupportedEncodingException e) { throw new PSQLException(GT.tr("The JVM claims not to support the encoding: {0}", "ISO-8859-1"), PSQLState.UNEXPECTED_ERROR, e);