com.memority.citadel.shared.api.im.DataValue Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of citadel-api Show documentation
Show all versions of citadel-api Show documentation
This artifact provides the API classes that are necessary to implement general configuration Rules on the Memority IM platform.
/*
* Copyright (c) 2016-2023 Memority. All Rights Reserved.
*
* This file is part of Memority Citadel API , a Memority project.
*
* This file is released under the Memority Public Artifacts End-User License Agreement,
* see
* Unauthorized copying of this file, via any medium is strictly prohibited.
*/
package com.memority.citadel.shared.api.im;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.memority.toolkit.core.api.misc.DataUrl;
import lombok.EqualsAndHashCode;
import java.util.Base64;
/**
* An attribute value instance representing a binary type, as an object.
*/
@EqualsAndHashCode
public class DataValue {
private final String base64Data;
private final String mediaType;
@JsonCreator
public DataValue(@JsonProperty("data") String base64Data, @JsonProperty("mediaType") String mediaType) {
this.base64Data = base64Data;
this.mediaType = mediaType;
}
@JsonProperty("data")
public String getBase64Data() {
return this.base64Data;
}
@JsonIgnore
public byte[] getData() {
Base64.Decoder base64Decoder = Base64.getDecoder();
return base64Decoder.decode(this.base64Data);
}
@JsonProperty("mediaType")
public String getMediaType() {
return this.mediaType;
}
public DataUrl toDataUrl() {
return new DataUrl(getData(), getMediaType());
}
public static DataValue from(DataUrl dataUrl) {
return new DataValue(dataUrl.getBase64Data(), dataUrl.getMediaType());
}
}