protected void writeStreamedValue(File file, ValueData value) throws IOException
{
// stream Value
if (value instanceof StreamPersistedValueData)
{
StreamPersistedValueData streamed = (StreamPersistedValueData)value;
if (streamed.isPersisted())
{
// already persisted in another Value, copy it to this Value
copyClose(streamed.getAsStream(), new FileOutputStream(file));
}
else
{
// the Value not yet persisted, i.e. or in client stream or spooled to a temp file
File tempFile;
if ((tempFile = streamed.getTempFile()) != null)
{
// it's spooled Value, try move its file to VS
if (!tempFile.renameTo(file))
{
// not succeeded - copy bytes, temp file will be deleted by transient ValueData
if (LOG.isDebugEnabled())
{
LOG
.debug("Value spool file move (rename) to Values Storage is not succeeded. Trying bytes copy. Spool file: "
+ tempFile.getAbsolutePath() + ". Destination: " + file.getAbsolutePath());
}
copyClose(new FileInputStream(tempFile), new FileOutputStream(file));
}
}
else
{
// not spooled, use client InputStream
copyClose(streamed.getStream(), new FileOutputStream(file));
}
// link this Value to file in VS
streamed.setPersistedFile(file);
}
}
else
{
// copy from Value stream to the file, e.g. from FilePersistedValueData to this Value