]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.jcr/src/org/argeo/jcr/Bin.java
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
6 import javax
.jcr
.Binary
;
7 import javax
.jcr
.Property
;
8 import javax
.jcr
.RepositoryException
;
11 * A {@link Binary} wrapper implementing {@link AutoCloseable} for ease of use
12 * in try/catch blocks.
14 public class Bin
implements Binary
, AutoCloseable
{
15 private final Binary wrappedBinary
;
17 public Bin(Property property
) throws RepositoryException
{
18 this(property
.getBinary());
21 public Bin(Binary wrappedBinary
) {
22 if (wrappedBinary
== null)
23 throw new IllegalArgumentException("Wrapped binary cannot be null");
24 this.wrappedBinary
= wrappedBinary
;
27 // private static Binary getBinary(Property property) throws IOException {
29 // return property.getBinary();
30 // } catch (RepositoryException e) {
31 // throw new IOException("Cannot get binary from property " + property, e);
41 public InputStream
getStream() throws RepositoryException
{
42 return wrappedBinary
.getStream();
46 public int read(byte[] b
, long position
) throws IOException
, RepositoryException
{
47 return wrappedBinary
.read(b
, position
);
51 public long getSize() throws RepositoryException
{
52 return wrappedBinary
.getSize();
56 public void dispose() {
57 wrappedBinary
.dispose();