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