Binary Values Processing
1 Configuration
Binary large object (BLOB) properties can be stored in two ways in the eXo JCR: in the database with items information or in an external storage on host file system. These options can be configured per workspace in the repository configuration file (repository-configuration.xml in portal and exo-jcr-config.xml in standalone mode). The database storage can't be completely disabled. The first case is optimal for most cases where you do not use very large values or/and do not have too many BLOBs. The configuration of the BLOBs size and BLOBs quantity in a repository depend on your database features and hardware. The second case is to use an external values storage. The storage can be located on a built-in hard disk or on an attached storage. But in any case you should have access to the storage as if it was a regular file(s). The external value storage is optional and can be enabled in addition to a database configuration.2 Usage
In both cases a developer can set/update the binary Property via Node.setProperty(String, InputStream), Property.setValue(InputStream) as described in the spec JSR-170. Also there is the setter with a ready Value object (obtainer from ValueFactory.createValue(InputStream)). An example of a specification usage.// Set the property value with given stream content. Property binProp = node.setProperty("BinData", myDataStream); // Get the property value stream. InputStream binStream = binProp.getStream(); // You may change the binary property value with a new Stream, all data will be replaced // with the content from the new stream. Property updatedBinProp = node.setProperty("BinData", newDataStream); // Or update an obtained property updatedBinProp.setValue(newDataStream); // Or update using a Value object updatedBinProp.setValue(ValueFactory.createValue(newDataStream)); // Get the updated property value stream. InputStream newStream = updatedBinProp.getStream();
// get the property value of type PropertyType.STRING ReadableBinaryValue extValue = (ReadableBinaryValue) node.getProperty("LargeText").getValue(); // read 200 bytes to a destStream from the position 1024 in the value content OutputStream destStream = new FileOutputStream("MyTextFile.txt"); extValue.read(destStream, 200, 1024);
// get the property value for PropertyType.BINARY Property EditableBinaryValue extValue = (EditableBinaryValue) node.getProperty("BinData").getValue(); // update length bytes from the stream starting from the position 1024 in existing Value data extValue.update(dataInputStream, dataLength, 1024); // apply the edited EditableBinaryValue to the Property node.setProperty("BinData", extValue); // save the Property to persistence node.save();
// update length bytes from the stream starting from the particular // position in the existing Value data int dpos = 1024; while (source.dataAvailable()) { extValue.update(source.getInputStream(), source.getLength(), dpos); dpos = dpos + source.getLength(); } // apply the edited EditableBinaryValue to the Property node.setProperty("BinData", extValue);
3 Value implementations
ReadableBinaryValue has one method for Value reading.
Read length bytes from the binary value from the given position into the stream.
long read(OutputStream stream, long length, long position) throws IOException, RepositoryException ;
void update(InputStream stream, long length, long position) throws IOException;
void setLength(long size) throws IOException;
on 07/08/2009 at 06:38