@@ -161,27 +161,31 @@ public boolean readBoolean () {
161
161
/// (short)((read() << 8)|(read() & 0xFF))
162
162
@ Override
163
163
public short readShort () {
164
+ if (count < pos + 2 ) throw new ArrayIndexOutOfBoundsException ("readShort, but " +available ());// EOF
164
165
short v = JBytes .DirectByteArrayAccess .getShort (buf , pos );
165
166
pos += 2 ;
166
167
return v ;
167
168
}
168
169
169
170
@ Override
170
- public int readUnsignedShort () {
171
+ public int readUnsignedShort () {
172
+ if (count < pos + 2 ) throw new ArrayIndexOutOfBoundsException ("readUnsignedShort, but " +available ());// EOF
171
173
int v = JBytes .DirectByteArrayAccess .getUnsignedShort (buf , pos );
172
174
pos += 2 ;
173
175
return v ;
174
176
}
175
177
176
178
@ Override
177
- public char readChar () {
179
+ public char readChar () {
180
+ if (count < pos + 2 ) throw new ArrayIndexOutOfBoundsException ("readChar, but " +available ());// EOF
178
181
char v = JBytes .DirectByteArrayAccess .getChar (buf , pos );
179
182
pos += 2 ;
180
183
return v ;
181
184
}
182
185
183
186
@ Override
184
- public int readInt () {
187
+ public int readInt () {
188
+ if (count < pos + 4 ) throw new ArrayIndexOutOfBoundsException ("readInt, but " +available ());// EOF
185
189
//return read() << 24 | ((read() & 0xFF) << 16) | ((read() & 0xFF) << 8) | (read() & 0xFF);
186
190
int v = JBytes .DirectByteArrayAccess .getInt (buf , pos );
187
191
pos += 4 ;
@@ -195,6 +199,7 @@ public int readMedium () {
195
199
/// @see UUID#UUID(long, long)
196
200
/// @see UUID#fromString(String)
197
201
public UUID readUUID () {
202
+ if (count < pos + 16 ) throw new ArrayIndexOutOfBoundsException ("readUUID, but " +available ());// EOF
198
203
//val bb = ByteBuffer.wrap(bytes); long mostSigBits = bb.getLong(); long leastSigBits = bb.getLong(); быстрее за счёт VarHandle
199
204
long mostSigBits = readLong ();// 0..7
200
205
long leastSigBits = readLong ();// 8..15
@@ -203,6 +208,7 @@ public UUID readUUID () {
203
208
204
209
@ Override
205
210
public long readLong () {
211
+ if (count < pos + 8 ) throw new ArrayIndexOutOfBoundsException ("readLong, but " +available ());// EOF
206
212
//return (long) readInt() << 32 | (readInt() & 0xFFFF_FFFFL);
207
213
long v = JBytes .DirectByteArrayAccess .getLong (buf , pos );
208
214
pos += 8 ;
@@ -211,13 +217,15 @@ public long readLong () {
211
217
212
218
@ Override
213
219
public float readFloat () {
220
+ if (count < pos + 4 ) throw new ArrayIndexOutOfBoundsException ("readFloat, but " +available ());// EOF
214
221
float v = JBytes .DirectByteArrayAccess .getFloat (buf , pos );
215
222
pos += 4 ;
216
223
return v ;
217
224
}
218
225
219
226
@ Override
220
227
public double readDouble () {
228
+ if (count < pos + 8 ) throw new ArrayIndexOutOfBoundsException ("readDouble, but " +available ());// EOF
221
229
double v = JBytes .DirectByteArrayAccess .getDouble (buf , pos );
222
230
pos += 8 ;
223
231
return v ;
0 commit comments