short hiTime = (short) ( System.currentTimeMillis() >>> 32 ); int loTime = (int) sysTime; System.arraycopy( BytesHelper.fromShort( hiTime ), 0, loBits, 0, 2 ); System.arraycopy( BytesHelper.fromInt( loTime ), 0, loBits, 2, 4 ); System.arraycopy( Helper.getCountBytes(), 0, loBits, 6, 2 ); System.out.println( " loBits[0] : " + BytesHelper.toBinaryString( loBits[0] ) ); System.out.println( " lsb : " + BytesHelper.toBinaryString( BytesHelper.asLong( loBits ) ) ); System.out.println( " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ); System.out.println( " loBits[0] : " + BytesHelper.toBinaryString( loBits[0] ) ); long leastSignificantBits = BytesHelper.asLong( loBits ); System.out.println( " lsb : " + BytesHelper.toBinaryString( leastSignificantBits ) ); System.out.println( " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
/** * Interpret a long as its binary form * * @param longValue The long to interpret to binary * * @return The binary */ public static byte[] fromLong(long longValue) { byte[] bytes = new byte[8]; fromLong(longValue, bytes, 0); return bytes; }
@AllowSysOut public static void main(String[] args) throws UnknownHostException { byte[] addressBytes = InetAddress.getLocalHost().getAddress(); System.out.println( "Raw ip address bytes : " + addressBytes.toString() ); int addressInt = BytesHelper.toInt( addressBytes ); System.out.println( "ip address int : " + addressInt ); String formatted = Integer.toHexString( addressInt ); StringBuilder buf = new StringBuilder( "00000000" ); buf.replace( 8 - formatted.length(), 8, formatted ); String addressHex = buf.toString(); System.out.println( "ip address hex : " + addressHex ); } }
public static long generateLeastSignificantBits(long seed) { byte[] loBits = new byte[8]; short hiTime = (short) ( seed >>> 32 ); int loTime = (int) seed; System.arraycopy( BytesHelper.fromShort( hiTime ), 0, loBits, 0, 2 ); System.arraycopy( BytesHelper.fromInt( loTime ), 0, loBits, 2, 4 ); System.arraycopy( Helper.getCountBytes(), 0, loBits, 6, 2 ); loBits[0] &= 0x3f; loBits[0] |= ((byte)2 << (byte)6 ); return BytesHelper.asLong( loBits ); }
/** * Interpret the binary representation of a long. * * @param bytes The bytes to interpret. * * @return The long */ public static long asLong(byte[] bytes) { return asLong(bytes, 0); }
public static byte[] getCountBytes() { return BytesHelper.fromShort( getCountShort() ); }
public static long generateLeastSignificantBits(long seed) { byte[] loBits = new byte[8]; short hiTime = (short) ( seed >>> 32 ); int loTime = (int) seed; System.arraycopy( BytesHelper.fromShort( hiTime ), 0, loBits, 0, 2 ); System.arraycopy( BytesHelper.fromInt( loTime ), 0, loBits, 2, 4 ); System.arraycopy( Helper.getCountBytes(), 0, loBits, 6, 2 ); loBits[0] &= 0x3f; loBits[0] |= ((byte)2 << (byte)6 ); return BytesHelper.asLong( loBits ); }
public static byte[] getCountBytes() { return BytesHelper.fromShort( getCountShort() ); }
short hiTime = (short) ( System.currentTimeMillis() >>> 32 ); int loTime = (int) sysTime; System.arraycopy( BytesHelper.fromShort( hiTime ), 0, loBits, 0, 2 ); System.arraycopy( BytesHelper.fromInt( loTime ), 0, loBits, 2, 4 ); System.arraycopy( Helper.getCountBytes(), 0, loBits, 6, 2 ); System.out.println( " loBits[0] : " + BytesHelper.toBinaryString( loBits[0] ) ); System.out.println( " lsb : " + BytesHelper.toBinaryString( BytesHelper.asLong( loBits ) ) ); System.out.println( " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ); System.out.println( " loBits[0] : " + BytesHelper.toBinaryString( loBits[0] ) ); long leastSignificantBits = BytesHelper.asLong( loBits ); System.out.println( " lsb : " + BytesHelper.toBinaryString( leastSignificantBits ) ); System.out.println( " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
public static long generateLeastSignificantBits(long seed) { byte[] loBits = new byte[8]; short hiTime = (short) ( seed >>> 32 ); int loTime = (int) seed; System.arraycopy( BytesHelper.fromShort( hiTime ), 0, loBits, 0, 2 ); System.arraycopy( BytesHelper.fromInt( loTime ), 0, loBits, 2, 4 ); System.arraycopy( Helper.getCountBytes(), 0, loBits, 6, 2 ); loBits[0] &= 0x3f; loBits[0] |= ((byte)2 << (byte)6); return BytesHelper.asLong( loBits ); }
public CustomVersionOneStrategy() { // generate the "most significant bits" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ byte[] hiBits = new byte[8]; // use address as first 32 bits (8 * 4 bytes) System.arraycopy( Helper.getAddressBytes(), 0, hiBits, 0, 4 ); // use the "jvm identifier" as the next 32 bits System.arraycopy( Helper.getJvmIdentifierBytes(), 0, hiBits, 4, 4 ); // set the version (rfc term) appropriately hiBits[6] &= 0x0f; hiBits[6] |= 0x10; mostSignificantBits = BytesHelper.asLong( hiBits ); } @Override
public static void main(String[] args) throws UnknownHostException { byte[] addressBytes = InetAddress.getLocalHost().getAddress(); System.out.println( "Raw ip address bytes : " + addressBytes.toString() ); int addressInt = BytesHelper.toInt( addressBytes ); System.out.println( "ip address int : " + addressInt ); String formatted = Integer.toHexString( addressInt ); StringBuffer buf = new StringBuffer( "00000000" ); buf.replace( 8 - formatted.length(), 8, formatted ); String addressHex = buf.toString(); System.out.println( "ip address hex : " + addressHex ); } }
public static byte[] getCountBytes() { return BytesHelper.fromShort( getCountShort() ); }
short hiTime = (short) ( System.currentTimeMillis() >>> 32 ); int loTime = (int) sysTime; System.arraycopy( BytesHelper.fromShort( hiTime ), 0, loBits, 0, 2 ); System.arraycopy( BytesHelper.fromInt( loTime ), 0, loBits, 2, 4 ); System.arraycopy( Helper.getCountBytes(), 0, loBits, 6, 2 ); System.out.println( " loBits[0] : " + BytesHelper.toBinaryString( loBits[0] ) ); System.out.println( " lsb : " + BytesHelper.toBinaryString( BytesHelper.asLong( loBits ) ) ); System.out.println( " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ); System.out.println( " loBits[0] : " + BytesHelper.toBinaryString( loBits[0] ) ); long leastSignificantBits = BytesHelper.asLong( loBits ); System.out.println( " lsb : " + BytesHelper.toBinaryString( leastSignificantBits ) ); System.out.println( " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
public static long generateLeastSignificantBits(long seed) { byte[] loBits = new byte[8]; short hiTime = (short) ( seed >>> 32 ); int loTime = (int) seed; System.arraycopy( BytesHelper.fromShort( hiTime ), 0, loBits, 0, 2 ); System.arraycopy( BytesHelper.fromInt( loTime ), 0, loBits, 2, 4 ); System.arraycopy( Helper.getCountBytes(), 0, loBits, 6, 2 ); loBits[0] &= 0x3f; loBits[0] |= ((byte)2 << (byte)6); return BytesHelper.asLong( loBits ); }
/** * Interpret the binary representation of a long. * * @param bytes The bytes to interpret. * * @return The long */ public static long asLong(byte[] bytes) { return asLong(bytes, 0); }
/** * Interpret a long as its binary form * * @param longValue The long to interpret to binary * * @return The binary */ public static byte[] fromLong(long longValue) { byte[] bytes = new byte[8]; fromLong(longValue, bytes, 0); return bytes; }
public static void main(String[] args) throws UnknownHostException { byte[] addressBytes = InetAddress.getLocalHost().getAddress(); System.out.println( "Raw ip address bytes : " + addressBytes.toString() ); int addressInt = BytesHelper.toInt( addressBytes ); System.out.println( "ip address int : " + addressInt ); String formatted = Integer.toHexString( addressInt ); StringBuffer buf = new StringBuffer( "00000000" ); buf.replace( 8 - formatted.length(), 8, formatted ); String addressHex = buf.toString(); System.out.println( "ip address hex : " + addressHex ); } }