/** * 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.lealone.util.StringUtils.convertHexToBytes(\"" + StringUtils.convertBytesToHex(x) + "\")"; }
@Override public String getString() { return StringUtils.convertBytesToHex(value); }
/** * 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); }
@Override public String getSQL() { return "X'" + StringUtils.convertBytesToHex(getBytesNoCopy()) + "'"; }
/** * 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 + "'"; }
break; buff.append(StringUtils.convertBytesToHex(bytes, len)).append("')"); String sql = buff.toString(); add(sql, true);
/** * 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 = Utils.readLong(binary, 0); long low = Utils.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, Constants.UTF8); } 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()); } }