Package io.lumify.core.model.properties.types

Source Code of io.lumify.core.model.properties.types.VideoTranscriptProperty

package io.lumify.core.model.properties.types;

import io.lumify.core.exception.LumifyException;
import io.lumify.core.ingest.video.VideoTranscript;
import org.securegraph.property.StreamingPropertyValue;
import org.apache.commons.io.IOUtils;
import org.json.JSONObject;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

public class VideoTranscriptProperty extends LumifyProperty<VideoTranscript, StreamingPropertyValue> {
    public VideoTranscriptProperty(String inKey) {
        super(inKey);
    }

    @Override
    public StreamingPropertyValue wrap(VideoTranscript value) {
        InputStream in = new ByteArrayInputStream(value.toJson().toString().getBytes());
        StreamingPropertyValue result = new StreamingPropertyValue(in, byte[].class);
        result.searchIndex(false);
        return result;
    }

    @Override
    public VideoTranscript unwrap(Object value) {
        String strValue = null;
        if (value instanceof StreamingPropertyValue) {
            try {
                strValue = IOUtils.toString(((StreamingPropertyValue) value).getInputStream());
            } catch (IOException e) {
                throw new LumifyException("Could not read propery value", e);
            }
        } else if (value != null) {
            strValue = value.toString();
        }
        JSONObject json = new JSONObject(strValue);
        return new VideoTranscript(json);
    }
}
TOP

Related Classes of io.lumify.core.model.properties.types.VideoTranscriptProperty

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.