protected long writeStreamedValue ( File file , ValueData value ) throws IOException { long size ; // stream Value if ( value instanceof StreamPersistedValueData ) { StreamPersistedValueData streamed = ( StreamPersistedValueData ) value ; if ( streamed . isPersisted ( ) ) { // already persisted in another Value, copy it to this Value size = 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 ( ) ) ; } size = copyClose ( new FileInputStream ( tempFile ) , new FileOutputStream ( file ) ) ; } else { size = file . length ( ) ; } } else { // not spooled, use client InputStream size = 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 size = copyClose ( value . getAsStream ( ) , new FileOutputStream ( file ) ) ; } return size ; }
Write streamed value to a file .