Nuxeo ECM Projects 5.4.3-SNAPSHOT

org.nuxeo.ecm.core.api
Interface Blob

All Known Implementing Classes:
AbstractBlob, ByteArrayBlob, DefaultBlob, DefaultStreamBlob, FileBlob, InputStreamBlob, LazyBlob, SQLBlob, StreamBlob, StreamingBlob, StringBlob, URLBlob

public interface Blob

A blob contains usually large data.

Document fields holding Blob data are by default fetched in a lazy manner.

A Blob object hides the data source and it also describes data properties like the encoding or mime-type.

The encoding is used to decode Unicode text content that was stored in an encoded form. If not encoding is specified, the default java encoding is used. The encoding is ignored for binary content.

When retrieving the content from a document, it will be returned as source content instead of returning the content bytes.

The same is true when setting the content for a document: you set a content source and not directly the content bytes. Ex:

 File file = new File("/tmp/index.html");
 FileBlob fb = new FileBlob(file);
 fb.setMimeType("text/html");
 fb.setEncoding("UTF-8"); // this specifies that content bytes will be stored as UTF-8
 document.setProperty("file", "content", fb);
 
Then you may want to retrieve the content as follow:
 Blob blob = document.getProperty("file:content");
 htmlDoc = blob.getString(); // the content is decoded from UTF-8 into a java string
 

Author:
Bogdan Stefanescu

Method Summary
 byte[] getByteArray()
           
 String getDigest()
           
 String getEncoding()
           
 String getFilename()
           
 long getLength()
          Gets the data length in bytes if known.
 String getMimeType()
           
 Reader getReader()
           
 InputStream getStream()
           
 String getString()
           
 boolean isPersistent()
          Checks whether this blob is persistent.
 Blob persist()
          Persist this stream so that getStream() method can be called successfully several times.
 void setDigest(String digest)
           
 void setEncoding(String encoding)
           
 void setFilename(String filename)
           
 void setMimeType(String mimeType)
           
 void transferTo(File file)
           
 void transferTo(OutputStream out)
           
 void transferTo(Writer out)
           
 

Method Detail

getLength

long getLength()
Gets the data length in bytes if known.

Returns:
the data length or -1 if not known

getEncoding

String getEncoding()

getMimeType

String getMimeType()

getFilename

String getFilename()

getDigest

String getDigest()

setDigest

void setDigest(String digest)

setFilename

void setFilename(String filename)

setMimeType

void setMimeType(String mimeType)

setEncoding

void setEncoding(String encoding)

getStream

InputStream getStream()
                      throws IOException
Throws:
IOException

getReader

Reader getReader()
                 throws IOException
Throws:
IOException

getByteArray

byte[] getByteArray()
                    throws IOException
Throws:
IOException

getString

String getString()
                 throws IOException
Throws:
IOException

transferTo

void transferTo(OutputStream out)
                throws IOException
Throws:
IOException

transferTo

void transferTo(Writer out)
                throws IOException
Throws:
IOException

transferTo

void transferTo(File file)
                throws IOException
Throws:
IOException

persist

Blob persist()
             throws IOException
Persist this stream so that getStream() method can be called successfully several times. The persistence is done in a temporary file or in memory - this is up to the implementation.

Blobs that are already persistent return themselves.

Persistence should update the internal structure of the Blob to make it persistent whenever possible and hence return itself whenever possible. This behavior cannot be guaranteed by every implementation however.

Returns:
a persistent version of the blob
Throws:
IOException

isPersistent

boolean isPersistent()
Checks whether this blob is persistent. (i.e. if getStream() can be successfully called several times).

Returns:
true if persistent, false otherwise

Nuxeo ECM Projects 5.4.3-SNAPSHOT

Copyright © 2011 Nuxeo SAS. All Rights Reserved.