writer.write("\t<" + VALUES_ELEMENT + ">\n");
InternalValue[] values = state.getValues();
if (values != null) {
for (int i = 0; i < values.length; i++) {
writer.write("\t\t<" + VALUE_ELEMENT + ">");
InternalValue val = values[i];
if (val != null) {
if (type == 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
writer.write(blobId);
// 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 {
writer.write(Text.encodeIllegalXMLCharacters(val.toString()));
}
}
writer.write("</" + VALUE_ELEMENT + ">\n");
}
}