org.apache.jackrabbit.core.value
Class BLOBFileValue

java.lang.Object
  extended by org.apache.jackrabbit.core.value.BLOBFileValue
All Implemented Interfaces:
Value

public class BLOBFileValue
extends Object
implements Value

BLOBFileValue represents a binary Value which is backed by a resource or byte[]. Unlike BinaryValue it has no state, i.e. the getStream() method always returns a fresh InputStream instance.

Important Note:

This is class is for Jackrabbit-internal use only. Applications should use javax.jcr.ValueFactory to create binary values.


Field Summary
protected static String DEFAULT_ENCODING
          the default encoding
static int TYPE
          the property type
 
Constructor Summary
BLOBFileValue(byte[] bytes)
          Creates a new BLOBFileValue instance from a byte[] array.
BLOBFileValue(File file)
          Creates a new BLOBFileValue instance from a File.
BLOBFileValue(FileSystemResource fsResource)
          Creates a new BLOBFileValue instance from a resource in the virtual file system.
BLOBFileValue(InputStream in)
          Creates a new BLOBFileValue instance from an InputStream.
BLOBFileValue(InputStream in, boolean temp)
          Creates a new BLOBFileValue instance from an InputStream.
 
Method Summary
 void delete()
          Deletes the persistent resource backing this BLOBFileValue.
 void delete(boolean pruneEmptyParentDirs)
          Deletes the persistent resource backing this BLOBFileValue.
 void discard()
          Frees temporarily allocated resources such as temporary file, buffer, etc.
 boolean equals(Object obj)
          
 boolean getBoolean()
          
 Calendar getDate()
          
 double getDouble()
          
 long getLength()
          Returns the length of this BLOBFileValue.
 long getLong()
          
 InputStream getStream()
          
 String getString()
          
 int getType()
          
 int hashCode()
          Returns zero to satisfy the Object equals/hashCode contract.
 void spool(OutputStream out)
          Spools the contents of this BLOBFileValue to the given output stream.
 String toString()
          Returns a string representation of this BLOBFileValue instance.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE

public static final int TYPE
the property type

See Also:
Constant Field Values

DEFAULT_ENCODING

protected static final String DEFAULT_ENCODING
the default encoding

See Also:
Constant Field Values
Constructor Detail

BLOBFileValue

public BLOBFileValue(InputStream in)
              throws IOException
Creates a new BLOBFileValue instance from an InputStream. The contents of the stream is spooled to a temporary file or to a byte buffer if its size is smaller than MAX_BUFFER_SIZE.

The new instance represents a temporary value whose dynamically allocated resources will be freed explicitly on discard().

Parameters:
in - stream to be represented as a BLOBFileValue instance
Throws:
IOException - if an error occurs while reading from the stream or writing to the temporary file

BLOBFileValue

public BLOBFileValue(InputStream in,
                     boolean temp)
              throws IOException
Creates a new BLOBFileValue instance from an InputStream. The contents of the stream is spooled to a temporary file or to a byte buffer if its size is smaller than MAX_BUFFER_SIZE.

The temp parameter governs whether dynamically allocated resources will be freed explicitly on discard(). Note that any dynamically allocated resources (temp file/buffer) will be freed implicitly once this instance has been gc'ed.

Parameters:
in - stream to be represented as a BLOBFileValue instance
temp - flag indicating whether this instance represents a temporary value whose resources can be explicitly freed on discard().
Throws:
IOException - if an error occurs while reading from the stream or writing to the temporary file

BLOBFileValue

public BLOBFileValue(byte[] bytes)
Creates a new BLOBFileValue instance from a byte[] array.

Parameters:
bytes - byte array to be represented as a BLOBFileValue instance

BLOBFileValue

public BLOBFileValue(File file)
              throws IOException
Creates a new BLOBFileValue instance from a File.

Parameters:
file - file to be represented as a BLOBFileValue instance
Throws:
IOException - if the file can not be read

BLOBFileValue

public BLOBFileValue(FileSystemResource fsResource)
              throws IOException
Creates a new BLOBFileValue instance from a resource in the virtual file system.

Parameters:
fsResource - resource in virtual file system
Throws:
IOException - if the resource can not be read
Method Detail

getLength

public long getLength()
Returns the length of this BLOBFileValue.

Returns:
The length, in bytes, of this BLOBFileValue, or -1L if the length can't be determined.

discard

public void discard()
Frees temporarily allocated resources such as temporary file, buffer, etc. If this BLOBFileValue is backed by a persistent resource calling this method will have no effect.

See Also:
delete(), delete(boolean)

delete

public void delete()
Deletes the persistent resource backing this BLOBFileValue. Same as #delete(false).

If this BLOBFileValue is not backed by a persistent resource calling this method will have no effect.

See Also:
discard()

delete

public void delete(boolean pruneEmptyParentDirs)
Deletes the persistent resource backing this BLOBFileValue.

Parameters:
pruneEmptyParentDirs - if true, empty parent directories will automatically be deleted

spool

public void spool(OutputStream out)
           throws RepositoryException,
                  IOException
Spools the contents of this BLOBFileValue to the given output stream.

Parameters:
out - output stream
Throws:
RepositoryException - if the input stream for this BLOBFileValue could not be obtained
IOException - if an error occurs while while spooling

toString

public String toString()
Returns a string representation of this BLOBFileValue instance. The string representation of a resource backed value is the path of the underlying resource. If this instance is backed by an in-memory buffer the generic object string representation of the byte array will be used instead.

Overrides:
toString in class Object
Returns:
A string representation of this BLOBFileValue instance.

equals

public boolean equals(Object obj)

Overrides:
equals in class Object

hashCode

public int hashCode()
Returns zero to satisfy the Object equals/hashCode contract. This class is mutable and not meant to be used as a hash key.

Overrides:
hashCode in class Object
Returns:
always zero
See Also:
Object.hashCode()

getType

public int getType()

Specified by:
getType in interface Value

getString

public String getString()
                 throws ValueFormatException,
                        IllegalStateException,
                        RepositoryException

Specified by:
getString in interface Value
Throws:
ValueFormatException
IllegalStateException
RepositoryException

getStream

public InputStream getStream()
                      throws IllegalStateException,
                             RepositoryException

Specified by:
getStream in interface Value
Throws:
IllegalStateException
RepositoryException

getDouble

public double getDouble()
                 throws ValueFormatException,
                        IllegalStateException,
                        RepositoryException

Specified by:
getDouble in interface Value
Throws:
ValueFormatException
IllegalStateException
RepositoryException

getDate

public Calendar getDate()
                 throws ValueFormatException,
                        IllegalStateException,
                        RepositoryException

Specified by:
getDate in interface Value
Throws:
ValueFormatException
IllegalStateException
RepositoryException

getLong

public long getLong()
             throws ValueFormatException,
                    IllegalStateException,
                    RepositoryException

Specified by:
getLong in interface Value
Throws:
ValueFormatException
IllegalStateException
RepositoryException

getBoolean

public boolean getBoolean()
                   throws ValueFormatException,
                          IllegalStateException,
                          RepositoryException

Specified by:
getBoolean in interface Value
Throws:
ValueFormatException
IllegalStateException
RepositoryException


Copyright © 2004-2007 The Apache Software Foundation. All Rights Reserved.