// if this is already saved to disk just return
if (lob.getReference() instanceof BaseLob) {
try {
BaseLob baseLob = (BaseLob)lob.getReference();
InputStreamFactory isf = baseLob.getStreamFactory();
if (isf.isPersistent()) {
return lob;
}
} catch (SQLException e) {
// go through regular persistence.
}
}
long offset = store.getLength();
int length = 0;
Streamable<?> persistedLob;
try {
InputStreamFactory isf = new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
if (lob instanceof BlobType) {
return new BlobInputStreamFactory((Blob)lob).getInputStream();
}
else if (lob instanceof ClobType) {
return new ClobInputStreamFactory((Clob)lob).getInputStream();
}
return new SQLXMLInputStreamFactory((SQLXML)lob).getInputStream();
}
};
InputStream is = isf.getInputStream();
OutputStream fsos = store.createOutputStream();
length = ObjectConverterUtil.write(fsos, is, bytes, -1);
} catch (IOException e) {
throw new TeiidComponentException(e);
}
// re-construct the new lobs based on the file store
final long lobOffset = offset;
final int lobLength = length;
InputStreamFactory isf = new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return store.createInputStream(lobOffset, lobLength);
}