001/*
002 * (C) Copyright 2015-2017 Nuxeo (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Florent Guillaume
018 */
019package org.nuxeo.ecm.core.blob;
020
021import java.io.IOException;
022import java.io.InputStream;
023
024import org.nuxeo.ecm.core.api.Blob;
025import org.nuxeo.ecm.core.api.DocumentModel;
026import org.nuxeo.ecm.core.model.Document;
027
028/**
029 * Interface for a provider of {@link Blob}s interacting with {@link Document}s.
030 *
031 * @since 9.2
032 */
033public interface DocumentBlobProvider {
034
035    /**
036     * Returns a new managed blob pointing to a fixed version of the original blob.
037     * <p>
038     *
039     * @param blob the original managed blob
040     * @param doc the document that holds the blob
041     * @return a managed blob with fixed version, or {@code null} if no change is needed
042     * @since 7.3
043     */
044    default ManagedBlob freezeVersion(ManagedBlob blob, Document doc) throws IOException {
045        return null;
046    }
047
048    /**
049     * Gets an {@link InputStream} for a conversion to the given MIME type.
050     * <p>
051     * Like all {@link InputStream}, the result must be closed when done with it to avoid resource leaks.
052     *
053     * @param blob the managed blob
054     * @param mimeType the MIME type to convert to
055     * @param doc the document that holds the blob
056     * @return the stream, or {@code null} if no conversion is available for the given MIME type
057     * @since 7.3
058     */
059    default InputStream getConvertedStream(ManagedBlob blob, String mimeType, DocumentModel doc) throws IOException {
060        return null;
061    }
062
063}