void store ( Index . IndexSpace indexSpace ) throws IOException { this . offset = indexSpace . offset ; this . occupiedSpace = indexSpace . length ; ByteBuffer buffer = ByteBuffer . allocate ( length ( ) ) ; buffer . putShort ( ( short ) prefix . length ) ; buffer . put ( prefix ) ; byte flags = 0 ; if ( innerNodes != null && innerNodes . length != 0 ) { flags |= HAS_NODES ; } else if ( leafNodes != null && leafNodes . length != 0 ) { flags |= HAS_LEAVES ; } buffer . put ( flags ) ; buffer . putShort ( ( short ) keyParts . length ) ; for ( byte [ ] keyPart : keyParts ) { buffer . putShort ( ( short ) keyPart . length ) ; buffer . put ( keyPart ) ; } if ( innerNodes != null ) { for ( InnerNode innerNode : innerNodes ) { buffer . putLong ( innerNode . offset ) ; buffer . putShort ( innerNode . length ) ; } } else { for ( LeafNode leafNode : leafNodes ) { buffer . putInt ( leafNode . file ) ; buffer . putInt ( leafNode . offset ) ; buffer . putShort ( leafNode . numRecords ) ; } } buffer . flip ( ) ; segment . getIndexFile ( ) . write ( buffer , offset ) ; if ( trace ) { log . tracef ( "Persisted %08x (length %d, %d %s) to %d:%d" , System . identityHashCode ( this ) , length ( ) , innerNodes != null ? innerNodes . length : leafNodes . length , innerNodes != null ? "children" : "leaves" , offset , occupiedSpace ) ; } }
called only internally or for root