/** * Convert a byte array to a hex encoded string. * * @param value the byte array * @return the hex encoded string */ public static String convertBytesToHex(byte[] value) { return convertBytesToHex(value, value.length); }
/** * Format a byte array to the Java source code that represents this object. * * @param x the byte array to convert * @return the Java source code */ protected static String quoteBytes(byte[] x) { if (x == null) { return "null"; } return "org.h2.util.StringUtils.convertHexToBytes(\"" + StringUtils.convertBytesToHex(x) + "\")"; }
@Override public String getString() { return StringUtils.convertBytesToHex(value); }
/** {@inheritDoc} */ @Override public String toString() { return "g_" + convertBytesToHex(b); } }
/** {@inheritDoc} */ @Override public String toString() { return "j_" + convertBytesToHex(b); } }
/** {@inheritDoc} */ @Override public String toString() { return "b_" + convertBytesToHex(b); } }
/** {@inheritDoc} */ @Override public String toString() { return scale + "_" + convertBytesToHex(b); } }
private void setUniqueId() { byte[] bytes = MathUtils.secureRandomBytes(RANDOM_BYTES); String random = StringUtils.convertBytesToHex(bytes); uniqueId = Long.toHexString(System.currentTimeMillis()) + random; properties.setProperty("id", uniqueId); }
@Override public String getSQL() { // WKT does not hold Z or SRID with JTS 1.13. As getSQL is used to // export database, it should contains all object attributes. Moreover // using bytes is faster than converting WKB to Geometry then to WKT. return "X'" + StringUtils.convertBytesToHex(getBytesNoCopy()) + "'::Geometry"; }
@Override public String getSQL() { return "X'" + StringUtils.convertBytesToHex(getBytesNoCopy()) + "'"; }
private static String generateSessionId() { byte[] buff = MathUtils.secureRandomBytes(16); return StringUtils.convertBytesToHex(buff); }
/** * INTERNAL */ public static String toString(Xid xid) { return PREFIX + '_' + xid.getFormatId() + '_' + StringUtils.convertBytesToHex(xid.getBranchQualifier()) + '_' + StringUtils.convertBytesToHex(xid.getGlobalTransactionId()); }
/** * Get the CREATE SQL statement for this object. * * @param password true if the password (actually the salt and hash) should * be returned * @return the SQL statement */ public String getCreateSQL(boolean password) { StringBuilder buff = new StringBuilder("CREATE USER IF NOT EXISTS "); buff.append(getSQL()); if (comment != null) { buff.append(" COMMENT ").append(StringUtils.quoteStringSQL(comment)); } if (password) { buff.append(" SALT '"). append(StringUtils.convertBytesToHex(salt)). append("' HASH '"). append(StringUtils.convertBytesToHex(passwordHash)). append('\''); } else { buff.append(" PASSWORD ''"); } if (admin) { buff.append(" ADMIN"); } return buff.toString(); }
@Override public String getSQL() { String s; if (type == Value.CLOB) { s = getString(); return StringUtils.quoteStringSQL(s); } byte[] buff = getBytes(); s = StringUtils.convertBytesToHex(buff); return "X'" + s + "'"; }
@Override public String getSQL() { String s; if (type == Value.CLOB) { s = getString(); return StringUtils.quoteStringSQL(s); } byte[] buff = getBytes(); s = StringUtils.convertBytesToHex(buff); return "X'" + s + "'"; }
return "'" + data.toString() + "'"; return "'" + StringUtils.convertBytesToHex((byte[]) data) + "'"; case Types.CLOB: case Types.JAVA_OBJECT:
break; buff.append(StringUtils.convertBytesToHex(bytes, len)).append("')"); String sql = buff.toString(); add(sql, true);
@Override public String getString() { int len = precision > Integer.MAX_VALUE || precision == 0 ? Integer.MAX_VALUE : (int) precision; try { if (type == Value.CLOB) { if (small != null) { return new String(small, StandardCharsets.UTF_8); } return IOUtils.readStringAndClose(getReader(), len); } byte[] buff; if (small != null) { buff = small; } else { buff = IOUtils.readBytesAndClose(getInputStream(), len); } return StringUtils.convertBytesToHex(buff); } catch (IOException e) { throw DbException.convertIOException(e, fileName); } }
/** * Get or create a UUID for the given 16 bytes. * * @param binary the byte array (must be at least 16 bytes long) * @return the UUID */ public static ValueUuid get(byte[] binary) { if (binary.length < 16) { return get(StringUtils.convertBytesToHex(binary)); } long high = Bits.readLong(binary, 0); long low = Bits.readLong(binary, 8); return (ValueUuid) Value.cache(new ValueUuid(high, low)); }
@Override public String getString() { int len = precision > Integer.MAX_VALUE || precision == 0 ? Integer.MAX_VALUE : (int) precision; try { if (type == Value.CLOB) { if (small != null) { return new String(small, StandardCharsets.UTF_8); } return IOUtils.readStringAndClose(getReader(), len); } byte[] buff; if (small != null) { buff = small; } else { buff = IOUtils.readBytesAndClose(getInputStream(), len); } return StringUtils.convertBytesToHex(buff); } catch (IOException e) { throw DbException.convertIOException(e, toString()); } }