for (int i = 0; i < values.length; i++) {
InternalValue val = values[i];
if (state.getType() == PropertyType.BINARY) {
// special handling required for binary value:
// put binary value in BLOB store
BLOBFileValue blobVal = (BLOBFileValue) val.internalValue();
InputStream in = blobVal.getStream();
String blobId = blobStore.createId(state.getPropertyId(), i);
try {
blobStore.put(blobId, in, blobVal.getLength());
} finally {
try {
in.close();
} catch (IOException e) {
// ignore
}
}
// store id of BLOB as property value
out.writeUTF(blobId); // value
// replace value instance with value backed by resource
// in BLOB store and discard old value instance (e.g. temp file)
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(blobId);
values[i] = InternalValue.create(fsRes);
} else {
in = blobStore.get(blobId);
try {
values[i] = InternalValue.create(in, false);
} finally {
try {
in.close();
} catch (IOException e) {
// ignore
}
}
}
blobVal.discard();
} else {
/**
* because writeUTF(String) has a size limit of 65k,
* Strings are serialized as <length><byte[]>
*/