1 29 package net.metanotion.io.data; 30 31 import net.metanotion.io.Serializer; 32 33 public class LongBytes implements Serializer { 34 public byte[] getBytes(Object o) { 35 byte[] b = new byte[8]; 36 long v = ((Long ) o).longValue(); 37 b[0] = (byte)(0xff & (v >> 56)); 38 b[1] = (byte)(0xff & (v >> 48)); 39 b[2] = (byte)(0xff & (v >> 40)); 40 b[3] = (byte)(0xff & (v >> 32)); 41 b[4] = (byte)(0xff & (v >> 24)); 42 b[5] = (byte)(0xff & (v >> 16)); 43 b[6] = (byte)(0xff & (v >> 8)); 44 b[7] = (byte)(0xff & v); 45 return b; 46 } 47 48 public Object construct(byte[] b) { 49 long v =(((long)(b[0] & 0xff) << 56) | 50 ((long)(b[1] & 0xff) << 48) | 51 ((long)(b[2] & 0xff) << 40) | 52 ((long)(b[3] & 0xff) << 32) | 53 ((long)(b[4] & 0xff) << 24) | 54 ((long)(b[5] & 0xff) << 16) | 55 ((long)(b[6] & 0xff) << 8) | 56 ((long)(b[7] & 0xff))); 57 return new Long (v); 58 } 59 } 60 | Popular Tags |