public long commit ( ) throws IOException { final PageFile < N > file = super . getFile ( ) ; if ( ! ( file instanceof PersistentPageFile ) ) { throw new IllegalStateException ( "Trying to commit a non-persistent XTree" ) ; } long npid = file . getNextPageID ( ) ; XTreeHeader ph = ( XTreeHeader ) ( ( PersistentPageFile < ? > ) file ) . getHeader ( ) ; long offset = ( ph . getReservedPages ( ) + npid ) * ph . getPageSize ( ) ; ph . setSupernode_offset ( npid * ph . getPageSize ( ) ) ; ph . setNumberOfElements ( num_elements ) ; RandomAccessFile ra_file = ( ( PersistentPageFile < ? > ) file ) . getFile ( ) ; ph . writeHeader ( ra_file ) ; ra_file . seek ( offset ) ; long nBytes = 0 ; for ( Iterator < N > iterator = supernodes . values ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { N supernode = iterator . next ( ) ; ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; ObjectOutputStream oos = new ObjectOutputStream ( baos ) ; supernode . writeSuperNode ( oos ) ; oos . close ( ) ; baos . close ( ) ; byte [ ] array = baos . toByteArray ( ) ; byte [ ] sn_array = new byte [ getPageSize ( ) * ( int ) Math . ceil ( ( double ) supernode . getCapacity ( ) / dirCapacity ) ] ; if ( array . length > sn_array . length ) { throw new IllegalStateException ( "Supernode is too large for fitting in " + ( ( int ) Math . ceil ( ( double ) supernode . getCapacity ( ) / dirCapacity ) ) + " pages of total size " + sn_array . length ) ; } System . arraycopy ( array , 0 , sn_array , 0 , array . length ) ; // file.countWrite(); ra_file . write ( sn_array ) ; nBytes += sn_array . length ; } return nBytes ; }
Writes all supernodes to the end of the file . This is only supposed to be used for a final saving of an XTree . If another page is added to this tree the supernodes written to file by this operation are over - written .