public interface Blob
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:
Then you may want to retrieve the content as follow:
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);
Blob blob = document.getProperty("file:content");
htmlDoc = blob.getString(); // the content is decoded from UTF-8 into a java string
Modifier and Type | Method and Description |
---|---|
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) |
long getLength()
String getEncoding()
String getMimeType()
String getFilename()
String getDigest()
void setDigest(String digest)
void setFilename(String filename)
void setMimeType(String mimeType)
void setEncoding(String encoding)
InputStream getStream() throws IOException
IOException
Reader getReader() throws IOException
IOException
byte[] getByteArray() throws IOException
IOException
String getString() throws IOException
IOException
void transferTo(OutputStream out) throws IOException
IOException
void transferTo(Writer out) throws IOException
IOException
void transferTo(File file) throws IOException
IOException
Blob persist() throws IOException
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.
IOException
boolean isPersistent()
getStream()
can be
successfully called several times).Copyright © 2014 Nuxeo SA. All Rights Reserved.