use of org.jooq.exception.DataTypeException in project jOOQ by jOOQ.
the class DefaultBinding method pgNewArray.
/**
* Create an array from a String
* <p>
* Unfortunately, this feature is very poorly documented and true UDT
* support by the PostGreSQL JDBC driver has been postponed for a long time.
*
* @param string A String representation of an array
* @return The converted array
*/
private static final Object[] pgNewArray(Class<?> type, String string) {
if (string == null) {
return null;
}
try {
Class<?> component = type.getComponentType();
List<String> values = PostgresUtils.toPGArray(string);
if (values.isEmpty()) {
return (Object[]) java.lang.reflect.Array.newInstance(component, 0);
} else {
Object[] result = (Object[]) java.lang.reflect.Array.newInstance(component, values.size());
for (int i = 0; i < values.size(); i++) result[i] = pgFromString(type.getComponentType(), values.get(i));
return result;
}
} catch (Exception e) {
throw new DataTypeException("Error while creating array", e);
}
}
use of org.jooq.exception.DataTypeException in project jOOQ by jOOQ.
the class PostgresUtils method toBytesFromHexEncoding.
private static byte[] toBytesFromHexEncoding(String string) {
String hex = string.substring(POSTGRESQL_HEX_STRING_PREFIX.length());
final StringReader input = new StringReader(hex);
final ByteArrayOutputStream bytes = new ByteArrayOutputStream(hex.length() / 2);
int hexDigit;
int byteValue;
try {
while ((hexDigit = input.read()) != -1) {
byteValue = (hexValue(hexDigit) << 4);
if ((hexDigit = input.read()) == -1) {
break;
}
byteValue += hexValue(hexDigit);
bytes.write(byteValue);
}
}// should never happen for a string reader
catch (IOException e) {
throw new DataTypeException("Error while decoding hex string", e);
}
input.close();
return bytes.toByteArray();
}
use of org.jooq.exception.DataTypeException in project jOOQ by jOOQ.
the class PostgresUtils method toBytesFromOctalEncoding.
private static byte[] toBytesFromOctalEncoding(final String string) {
final Reader reader = new StringReader(string);
final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
try {
convertOctalToBytes(reader, bytes);
return bytes.toByteArray();
} catch (IOException x) {
throw new DataTypeException("failed to parse octal hex string: " + x.getMessage(), x);
}
}
Aggregations