public synchronized void setArrayLength ( int arrayLength , File renameToFile ) throws IOException { if ( arrayLength < 0 ) { throw new IOException ( "Invalid array length: " + arrayLength ) ; } if ( this . _arrayLength == arrayLength ) return ; // Flush all the changes. this . flush ( ) ; // Change the file length. long fileLength = DATA_START_POSITION + ( ( long ) arrayLength * _elementSize ) ; RandomAccessFile raf = new RandomAccessFile ( _file , "rw" ) ; try { raf . setLength ( fileLength ) ; } catch ( IOException e ) { _log . error ( "failed to setArrayLength " + arrayLength ) ; throw e ; } finally { raf . close ( ) ; } // Write the new array length. writeArrayLength ( arrayLength ) ; this . flush ( ) ; if ( renameToFile != null ) { if ( _file . renameTo ( renameToFile ) ) { _writer . close ( ) ; _file = renameToFile ; _writer = IOFactory . createDataWriter ( _file , _type ) ; _writer . open ( ) ; return ; } else { _log . warn ( "Failed to rename " + _file . getAbsolutePath ( ) + " to " + renameToFile . getAbsolutePath ( ) ) ; } } if ( MultiMappedWriter . class . isInstance ( _writer ) ) { ( ( MultiMappedWriter ) _writer ) . remap ( ) ; _log . info ( "remap " + _file . getPath ( ) + " " + _file . length ( ) ) ; } else { _writer . close ( ) ; _writer = IOFactory . createDataWriter ( _file , _type ) ; _writer . open ( ) ; } }
Updates the length of this ArrayFile to the specified value .