/** * The BinaryWrapper contains both the Binary metadata and raw byte array content, but in encoded format. * The Binary meta will be Base64 decoded, then GZip decompressed, then JSON deserialized. Then the binary * byte array in the wrapper will be assigned into the decoded Binary. * The end result Binary contains both binary meta and the raw content byte array. * * @param wrapper BinaryWrapper to decode, decompress and convert to Binary * @return Binary a full Binary object containing metadata and raw content byte [] * @throws SerializationException if anything goes wrong during decompressing, deserialization */ public Binary build(BinaryWrapper wrapper) throws SerializationException { byte[] binaryBytes = CompressionUtils.decodeBase64(wrapper.getBinary()); String binaryJSON = CompressionUtils.decompressGZip(binaryBytes); Binary result = serializer.deserialize(binaryJSON, BinaryImpl.class); BinaryDataImpl binaryData = new BinaryDataImpl(); binaryData.setBytes(wrapper.getContent()); result.setBinaryData(binaryData); return result; }
private Binary getBinary(final TCMURI binaryUri, final BinaryMeta binaryMeta) throws ItemNotFoundException { final BinaryImpl binary = new BinaryImpl(); binary.setId(binaryUri.toString()); binary.setUrlPath(binaryMeta.getURLPath()); binary.setMimeType(binaryMeta.getType()); binary.setLastPublishedDate(getLastPublishDate(binaryUri.toString())); // TODO: binary.setMetadata(binaryMeta.getCustomMeta().getChildren()); String variantId = binaryMeta.getVariantId(); final BinaryDataImpl binaryDataBytes = new BinaryDataImpl(); if (isEmpty(variantId)) { binaryDataBytes.setBytes(getBinaryContentById(binaryUri.getItemId(), binaryUri.getPublicationId())); } else { binaryDataBytes.setBytes(getBinaryContentByIdAndVariantId( binaryUri.getItemId(), binaryUri.getPublicationId(), variantId)); } binary.setBinaryData(binaryDataBytes); return binary; }
final BinaryDataImpl binaryData = new BinaryDataImpl(); binaryData.setBytes(content.getContent().clone()); binary.setBinaryData(binaryData);