{
// do what you want
// 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(), PrivilegedFileHelper.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 (!PrivilegedFileHelper.renameTo(tempFile, 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: "
+ PrivilegedFileHelper.getAbsolutePath(tempFile)
+ ". Destination: "
+ PrivilegedFileHelper.getAbsolutePath(file));
}
copyClose(PrivilegedFileHelper.fileInputStream(tempFile), PrivilegedFileHelper.fileOutputStream(file));
}
}
else
{
// not spooled, use client InputStream
copyClose(streamed.getStream(), PrivilegedFileHelper.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