Example usage for org.springframework.security.crypto.codec Hex encode

List of usage examples for org.springframework.security.crypto.codec Hex encode

Introduction

In this page you can find the example usage for org.springframework.security.crypto.codec Hex encode.

Prototype

public static char[] encode(byte[] bytes) 

Source Link

Usage

From source file:de.thm.arsnova.service.UserServiceImpl.java

private String generateGuestId() {
    if (null == keygen) {
        keygen = KeyGenerators.secureRandom(16);
    }//from  ww  w  .java2s.  c  o m

    return new String(Hex.encode(keygen.generateKey()));
}

From source file:org.apache.syncope.core.util.ContentExporter.java

private String getValues(final ResultSet rs, final String columnName, final Integer columnType)
        throws SQLException {

    String res = null;/* ww w  . ja  v  a 2s  . c  o m*/

    try {
        switch (columnType) {
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            final InputStream is = rs.getBinaryStream(columnName);
            if (is != null) {
                res = new String(Hex.encode(IOUtils.toByteArray(is)));
            }
            break;

        case Types.BLOB:
            final Blob blob = rs.getBlob(columnName);
            if (blob != null) {
                res = new String(Hex.encode(IOUtils.toByteArray(blob.getBinaryStream())));
            }
            break;

        case Types.BIT:
        case Types.BOOLEAN:
            if (rs.getBoolean(columnName)) {
                res = "1";
            } else {
                res = "0";
            }
            break;

        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            final Timestamp timestamp = rs.getTimestamp(columnName);
            if (timestamp != null) {
                res = DataFormat.format(new Date(timestamp.getTime()));
            }
            break;

        default:
            res = rs.getString(columnName);
        }
    } catch (IOException e) {
        LOG.error("Error retrieving hexadecimal string", e);
    }

    return res;
}