KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > nio > ByteBufferAsIntBufferB


1 /*
2  * @(#)ByteBufferAs-X-Buffer.java 1.17 04/05/03
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 // -- This file was mechanically generated: Do not edit! -- //
9

10 package java.nio;
11
12
13 class ByteBufferAsIntBufferB // package-private
14
extends IntBuffer JavaDoc
15 {
16
17
18
19     protected final ByteBuffer JavaDoc bb;
20     protected final int offset;
21
22
23
24     ByteBufferAsIntBufferB(ByteBuffer JavaDoc bb) { // package-private
25

26     super(-1, 0,
27           bb.remaining() >> 2,
28           bb.remaining() >> 2);
29     this.bb = bb;
30     // enforce limit == capacity
31
int cap = this.capacity();
32     this.limit(cap);
33     int pos = this.position();
34     assert (pos <= cap);
35     offset = pos;
36
37
38
39     }
40
41     ByteBufferAsIntBufferB(ByteBuffer JavaDoc bb,
42                      int mark, int pos, int lim, int cap,
43                      int off)
44     {
45
46     super(mark, pos, lim, cap);
47     this.bb = bb;
48     offset = off;
49
50
51
52     }
53
54     public IntBuffer JavaDoc slice() {
55     int pos = this.position();
56     int lim = this.limit();
57     assert (pos <= lim);
58     int rem = (pos <= lim ? lim - pos : 0);
59     int off = (pos << 2) + offset;
60         assert (off >= 0);
61     return new ByteBufferAsIntBufferB JavaDoc(bb, -1, 0, rem, rem, off);
62     }
63
64     public IntBuffer JavaDoc duplicate() {
65     return new ByteBufferAsIntBufferB JavaDoc(bb,
66                             this.markValue(),
67                             this.position(),
68                             this.limit(),
69                             this.capacity(),
70                             offset);
71     }
72
73     public IntBuffer JavaDoc asReadOnlyBuffer() {
74
75     return new ByteBufferAsIntBufferRB JavaDoc(bb,
76                          this.markValue(),
77                          this.position(),
78                          this.limit(),
79                          this.capacity(),
80                          offset);
81
82
83
84     }
85
86
87
88     protected int ix(int i) {
89     return (i << 2) + offset;
90     }
91
92     public int get() {
93     return Bits.getIntB(bb, ix(nextGetIndex()));
94     }
95
96     public int get(int i) {
97     return Bits.getIntB(bb, ix(checkIndex(i)));
98     }
99
100
101
102     public IntBuffer JavaDoc put(int x) {
103
104     Bits.putIntB(bb, ix(nextPutIndex()), x);
105     return this;
106
107
108
109     }
110
111     public IntBuffer JavaDoc put(int i, int x) {
112
113     Bits.putIntB(bb, ix(checkIndex(i)), x);
114     return this;
115
116
117
118     }
119
120     public IntBuffer JavaDoc compact() {
121
122     int pos = position();
123     int lim = limit();
124     assert (pos <= lim);
125     int rem = (pos <= lim ? lim - pos : 0);
126
127     ByteBuffer JavaDoc db = bb.duplicate();
128     db.limit(ix(lim));
129     db.position(ix(0));
130     ByteBuffer JavaDoc sb = db.slice();
131     sb.position(pos << 2);
132     sb.compact();
133     position(rem);
134     limit(capacity());
135     return this;
136
137
138
139     }
140
141     public boolean isDirect() {
142     return bb.isDirect();
143     }
144
145     public boolean isReadOnly() {
146     return false;
147     }
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189     public ByteOrder JavaDoc order() {
190
191     return ByteOrder.BIG_ENDIAN;
192
193
194
195
196     }
197
198 }
199
Popular Tags