use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.
the class Serializer method deserialize.
/**
* Deserializes a <code>PropertyState</code> object from the given binary
* <code>stream</code>. Binary values are retrieved from the specified
* <code>BLOBStore</code>.
*
* @param state <code>state</code> to deserialize
* @param stream the stream where the <code>state</code> should be
* deserialized from
* @param blobStore handler for BLOB data
* @throws Exception if an error occurs during the deserialization
* @see #serialize(PropertyState, OutputStream, BLOBStore)
*/
public static void deserialize(PropertyState state, InputStream stream, BLOBStore blobStore) throws Exception {
DataInputStream in = new DataInputStream(stream);
// type
int type = in.readInt();
state.setType(type);
// multiValued
boolean multiValued = in.readBoolean();
state.setMultiValued(multiValued);
// definitionId
in.readUTF();
// modCount
short modCount = in.readShort();
state.setModCount(modCount);
// values
// count
int count = in.readInt();
InternalValue[] values = new InternalValue[count];
for (int i = 0; i < count; i++) {
InternalValue val;
if (type == PropertyType.BINARY) {
// value (i.e. blobId)
String s = in.readUTF();
// in the BLOB store
if (blobStore instanceof ResourceBasedBLOBStore) {
// optimization: if the BLOB store is resource-based
// retrieve the resource directly rather than having
// to read the BLOB from an input stream
FileSystemResource fsRes = ((ResourceBasedBLOBStore) blobStore).getResource(s);
val = InternalValue.create(fsRes);
} else {
InputStream is = blobStore.get(s);
try {
val = InternalValue.create(is);
} finally {
try {
is.close();
} catch (IOException e) {
// ignore
}
}
}
} else {
/**
* because writeUTF(String) has a size limit of 65k,
* Strings are serialized as <length><byte[]>
*/
//s = in.readUTF(); // value
// lenght of byte[]
int len = in.readInt();
byte[] bytes = new byte[len];
// byte[]
in.readFully(bytes);
String s = new String(bytes, ENCODING);
val = InternalValue.valueOf(s, type);
}
values[i] = val;
}
state.setValues(values);
}
use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.
the class XMLPersistenceManager method exists.
/**
* {@inheritDoc}
*/
public synchronized boolean exists(PropertyId id) throws ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
try {
String propFilePath = buildPropFilePath(id);
FileSystemResource propFile = new FileSystemResource(itemStateFS, propFilePath);
return propFile.exists();
} catch (FileSystemException fse) {
String msg = "failed to check existence of item state: " + id;
log.error(msg, fse);
throw new ItemStateException(msg, fse);
}
}
use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.
the class ObjectPersistenceManager method exists.
/**
* {@inheritDoc}
*/
public synchronized boolean exists(NodeId id) throws ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
try {
String nodeFilePath = buildNodeFilePath(id);
FileSystemResource nodeFile = new FileSystemResource(itemStateFS, nodeFilePath);
return nodeFile.exists();
} catch (FileSystemException fse) {
String msg = "failed to check existence of item state: " + id;
log.error(msg, fse);
throw new ItemStateException(msg, fse);
}
}
use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.
the class FileSystemBLOBStore method remove.
/**
* {@inheritDoc}
*/
public boolean remove(String blobId) throws Exception {
// the blobId is an absolute file system path
FileSystemResource res = new FileSystemResource(fs, blobId);
if (!res.exists()) {
return false;
}
// delete resource and prune empty parent folders
res.delete(true);
return true;
}
use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.
the class FileSystemBLOBStore method put.
/**
* {@inheritDoc}
*/
public void put(String blobId, InputStream in, long size) throws Exception {
// the blobId is an absolute file system path
FileSystemResource internalBlobFile = new FileSystemResource(fs, blobId);
internalBlobFile.makeParentDirs();
OutputStream out = internalBlobFile.getOutputStream();
try {
IOUtils.copy(in, out);
} finally {
out.close();
}
}
Aggregations