Example usage for org.springframework.util Base64Utils decode

List of usage examples for org.springframework.util Base64Utils decode

Introduction

In this page you can find the example usage for org.springframework.util Base64Utils decode.

Prototype

public static byte[] decode(byte[] src) 

Source Link

Document

Base64-decode the given byte array.

Usage

From source file:org.cloudfoundry.identity.uaa.client.JdbcClientMetadataProvisioning.java

@Override
public ClientMetadata update(ClientMetadata resource) {
    logger.debug("Updating metadata for client: " + resource.getClientId());

    updateClientNameIfNotEmpty(resource);
    int updated = template.update(CLIENT_METADATA_UPDATE, ps -> {
        int pos = 1;
        ps.setBoolean(pos++, resource.isShowOnHomePage());
        URL appLaunchUrl = resource.getAppLaunchUrl();
        ps.setString(pos++, appLaunchUrl == null ? null : appLaunchUrl.toString());
        String appIcon = resource.getAppIcon();
        if (appIcon != null) {
            byte[] decodedAppIcon = Base64Utils.decode(appIcon.getBytes());
            ps.setBinaryStream(pos++, new ByteArrayInputStream(decodedAppIcon), decodedAppIcon.length);
        } else {/*from w  w w . ja  v  a  2s  . c  o  m*/
            ps.setBinaryStream(pos++, new ByteArrayInputStream(new byte[] {}), 0);
        }
        ps.setString(pos++, resource.getClientId());
        String zone = IdentityZoneHolder.get().getId();
        ps.setString(pos++, zone);
    });

    ClientMetadata resultingClientMetadata = retrieve(resource.getClientId());

    if (updated > 1) {
        throw new IncorrectResultSizeDataAccessException(1);
    }

    return resultingClientMetadata;
}