001/**
002 * Copyright 2015 DuraSpace, Inc.
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 */
016package org.fcrepo.kernel.impl.utils;
017
018import java.io.InputStream;
019
020import javax.jcr.Property;
021import javax.jcr.RepositoryException;
022
023/**
024 * A {@link org.fcrepo.kernel.utils.CacheEntry} for simple Binary objects
025 * @author frank asseg
026 *
027 */
028public class BinaryCacheEntry extends BasicCacheEntry {
029
030    private final Property property;
031
032    /**
033     * Create a new BinaryCacheEntry
034     * @param property the property
035     */
036    public BinaryCacheEntry(final Property property) {
037        super();
038        this.property = property;
039    }
040
041    /*
042     * (non-Javadoc)
043     * @see org.fcrepo.kernel.utils.CacheEntry#getInputStream()
044     */
045    @Override
046    public InputStream getInputStream() throws RepositoryException {
047        return property.getBinary().getStream();
048    }
049
050    /*
051     * (non-Javadoc)
052     * @see org.fcrepo.kernel.utils.CacheEntry#getExternalIdentifier()
053     */
054    @Override
055    public String getExternalIdentifier() throws RepositoryException {
056        return property.getPath();
057    }
058
059    protected Property property() {
060        return property;
061    }
062
063}