public static ScalableStatistics fromBytes ( byte [ ] bytes ) { Preconditions . checkArgument ( bytes . length > 0 ) ; ByteBuffer buf = ByteBuffer . wrap ( bytes ) ; ScalableStatistics stats = new ScalableStatistics ( ) ; Preconditions . checkArgument ( buf . getInt ( ) == MAGIC_CODE ) ; // read basic descriptive stats stats . count = buf . getLong ( ) ; stats . min = buf . getDouble ( ) ; stats . max = buf . getDouble ( ) ; stats . sum = buf . getDouble ( ) ; stats . sumOfSquares = buf . getDouble ( ) ; // read exact values, if any stats . exactQuantilesThreshold = buf . getInt ( ) ; int vlen = buf . getInt ( ) ; if ( vlen >= 0 ) { stats . numExactValues = vlen ; stats . exactValues = new double [ vlen ] ; for ( int i = 0 ; i < vlen ; i ++ ) { stats . exactValues [ i ] = buf . getDouble ( ) ; } } else { stats . exactValues = null ; } // read tdigest byte [ ] classNameBytes = new byte [ buf . getInt ( ) ] ; buf . get ( classNameBytes ) ; String className = new String ( classNameBytes , Charsets . UTF_8 ) ; try { Method method = Class . forName ( className ) . getMethod ( "fromBytes" , ByteBuffer . class ) ; Preconditions . checkArgument ( Modifier . isStatic ( method . getModifiers ( ) ) ) ; stats . tdigest = ( TDigest ) method . invoke ( null , buf ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } Preconditions . checkArgument ( buf . getInt ( ) == MAGIC_CODE ) ; Preconditions . checkArgument ( buf . position ( ) == buf . capacity ( ) ) ; return stats ; }
Derializes the data structure from a byte array