1 package com.quadcap.sql.file; 2 3 40 41 47 public class ByteUtil { 48 55 public static final short getShort(byte[] buf, int pos) { 56 return (short)(((buf[pos] & 0xff) << 8) + (buf[pos+1] & 0xff)); 57 } 58 59 66 public static final void putShort(byte[] buf, int pos, short val) { 67 buf[pos++] = (byte)((val >>> 8) & 0xff); 68 buf[pos] = (byte)((val ) & 0xff); 69 } 70 71 78 public static final int getInt(byte[] buf, int pos) { 79 return 80 ((buf[pos] & 0xff) << 24) + 81 ((buf[pos+1] & 0xff) << 16) + 82 ((buf[pos+2] & 0xff) << 8) + 83 (buf[pos+3] & 0xff); 84 } 85 86 93 public static final void putInt(byte[] buf, int pos, int val) { 94 buf[pos++] = (byte)((val >>> 24) & 0xff); 95 buf[pos++] = (byte)((val >>> 16) & 0xff); 96 buf[pos++] = (byte)((val >>> 8) & 0xff); 97 buf[pos] = (byte)((val ) & 0xff); 98 } 99 100 107 public static final long getLong(byte[] buf, int pos) { 108 return 109 ((long)(buf[pos] & 0xff) << 56) + 110 ((long)(buf[pos+1] & 0xff) << 48) + 111 ((long)(buf[pos+2] & 0xff) << 40) + 112 ((long)(buf[pos+3] & 0xff) << 32) + 113 ((long)(buf[pos+4] & 0xff) << 24) + 114 ((long)(buf[pos+5] & 0xff) << 16) + 115 ((long)(buf[pos+6] & 0xff) << 8) + 116 ((long)buf[pos+7] & 0xff); 117 } 118 119 126 public static final void putLong(byte[] buf, int pos, long val) { 127 buf[pos++] = (byte)((val >>> 56) & 0xff); 128 buf[pos++] = (byte)((val >>> 48) & 0xff); 129 buf[pos++] = (byte)((val >>> 40) & 0xff); 130 buf[pos++] = (byte)((val >>> 32) & 0xff); 131 buf[pos++] = (byte)((val >>> 24) & 0xff); 132 buf[pos++] = (byte)((val >>> 16) & 0xff); 133 buf[pos++] = (byte)((val >>> 8) & 0xff); 134 buf[pos] = (byte)((val ) & 0xff); 135 } 136 137 138 } 139 | Popular Tags |