1:
9:
10: package ;
11:
12: import ;
13:
14: public class BytePtr
15: {
16: ByteBuffer content;
17: int wordSize;
18:
19: BytePtr(ByteBuffer b, int ws)
20: {
21: content = b;
22: wordSize = ws;
23: }
24:
25: public int getsize()
26: {
27: return content.limit();
28: }
29:
30: public int getByte(int offset)
31: {
32: return content.get(offset);
33: }
34:
35: public int getInt(int n)
36: {
37: return content.getInt(n * 4);
38: }
39:
40: public int getShort(int n)
41: {
42: return content.getShort(n * 2);
43: }
44:
45: public long getWord(int n)
46: {
47: if (4 == wordSize)
48: return 0xffffffffL & content.getInt(n * 4);
49: else
50: return content.getLong(n * 8);
51: }
52:
53: public int intsPerWord()
54: {
55: return (4 == wordSize) ? 1 : 2;
56: }
57:
58: public BytePtr getRegion(int offset, int size)
59: {
60: int oldLimit = content.limit();
61: content.position(offset);
62: content.limit(offset + size);
63: ByteBuffer n = content.slice();
64: content.position(0);
65: content.limit(oldLimit);
66:
67: return new BytePtr(n, wordSize);
68: }
69:
70: public void setInt(int a, int n)
71: {
72: content.putInt(a * 4, n);
73: }
74:
75: public void dump()
76: {
77:
78: int i;
79: StringBuilder b = new StringBuilder(67);
80: for (i = 0; i < 66; i++)
81: b.append(' ');
82: b.append('\n');
83:
84: i = 0;
85: do
86: {
87: for (int j = 0; j < 16; j++)
88: {
89: int k = i + j;
90:
91: if (k < content.limit())
92: {
93: int v = 0xff & getByte(k);
94:
95: int v1 = v/16;
96: b.setCharAt(j * 3 + 0,
97: (char)(v1 >= 10 ? 'a' - 10 + v1 : v1 + '0'));
98: v1 = v % 16;
99: b.setCharAt(j * 3 + 1,
100: (char)(v1 >= 10 ? 'a' - 10 + v1 : v1 + '0'));
101:
102: b.setCharAt(j + 50, (char)((v >= 32 && v <= 127) ? v: '.'));
103: }
104: else
105: {
106: b.setCharAt(j * 3 + 0, ' ');
107: b.setCharAt(j * 3 + 1, ' ');
108: b.setCharAt(j + 50, ' ');
109: }
110: }
111: i += 16;
112: System.out.print(b);
113: } while (i < content.limit());
114: }
115: }