1 7 8 10 package java.nio; 11 12 13 23 24 class HeapByteBufferR 25 extends HeapByteBuffer 26 { 27 28 36 37 HeapByteBufferR(int cap, int lim) { 39 40 41 42 43 44 45 super(cap, lim); 46 this.isReadOnly = true; 47 48 } 49 50 HeapByteBufferR(byte[] buf, int off, int len) { 52 53 54 55 56 57 58 super(buf, off, len); 59 this.isReadOnly = true; 60 61 } 62 63 protected HeapByteBufferR(byte[] buf, 64 int mark, int pos, int lim, int cap, 65 int off) 66 { 67 68 69 70 71 72 73 74 super(buf, mark, pos, lim, cap, off); 75 this.isReadOnly = true; 76 77 } 78 79 public ByteBuffer slice() { 80 return new HeapByteBufferR (hb, 81 -1, 82 0, 83 this.remaining(), 84 this.remaining(), 85 this.position() + offset); 86 } 87 88 public ByteBuffer duplicate() { 89 return new HeapByteBufferR (hb, 90 this.markValue(), 91 this.position(), 92 this.limit(), 93 this.capacity(), 94 offset); 95 } 96 97 public ByteBuffer asReadOnlyBuffer() { 98 99 100 101 102 103 104 105 106 return duplicate(); 107 108 } 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 public boolean isReadOnly() { 140 return true; 141 } 142 143 public ByteBuffer put(byte x) { 144 145 146 147 148 throw new ReadOnlyBufferException (); 149 150 } 151 152 public ByteBuffer put(int i, byte x) { 153 154 155 156 157 throw new ReadOnlyBufferException (); 158 159 } 160 161 public ByteBuffer put(byte[] src, int offset, int length) { 162 163 164 165 166 167 168 169 170 throw new ReadOnlyBufferException (); 171 172 } 173 174 public ByteBuffer put(ByteBuffer src) { 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 throw new ReadOnlyBufferException (); 199 200 } 201 202 public ByteBuffer compact() { 203 204 205 206 207 208 209 throw new ReadOnlyBufferException (); 210 211 } 212 213 214 215 216 217 byte _get(int i) { return hb[i]; 219 } 220 221 void _put(int i, byte b) { 223 224 225 throw new ReadOnlyBufferException (); 226 227 } 228 229 231 232 233 234 235 236 237 238 239 240 241 242 243 public ByteBuffer putChar(char x) { 244 245 246 247 248 throw new ReadOnlyBufferException (); 249 250 } 251 252 public ByteBuffer putChar(int i, char x) { 253 254 255 256 257 throw new ReadOnlyBufferException (); 258 259 } 260 261 public CharBuffer asCharBuffer() { 262 int size = this.remaining() >> 1; 263 int off = offset + position(); 264 return (bigEndian 265 ? (CharBuffer )(new ByteBufferAsCharBufferRB (this, 266 -1, 267 0, 268 size, 269 size, 270 off)) 271 : (CharBuffer )(new ByteBufferAsCharBufferRL (this, 272 -1, 273 0, 274 size, 275 size, 276 off))); 277 } 278 279 280 282 283 284 285 286 287 288 289 290 291 292 293 294 public ByteBuffer putShort(short x) { 295 296 297 298 299 throw new ReadOnlyBufferException (); 300 301 } 302 303 public ByteBuffer putShort(int i, short x) { 304 305 306 307 308 throw new ReadOnlyBufferException (); 309 310 } 311 312 public ShortBuffer asShortBuffer() { 313 int size = this.remaining() >> 1; 314 int off = offset + position(); 315 return (bigEndian 316 ? (ShortBuffer )(new ByteBufferAsShortBufferRB (this, 317 -1, 318 0, 319 size, 320 size, 321 off)) 322 : (ShortBuffer )(new ByteBufferAsShortBufferRL (this, 323 -1, 324 0, 325 size, 326 size, 327 off))); 328 } 329 330 331 333 334 335 336 337 338 339 340 341 342 343 344 345 public ByteBuffer putInt(int x) { 346 347 348 349 350 throw new ReadOnlyBufferException (); 351 352 } 353 354 public ByteBuffer putInt(int i, int x) { 355 356 357 358 359 throw new ReadOnlyBufferException (); 360 361 } 362 363 public IntBuffer asIntBuffer() { 364 int size = this.remaining() >> 2; 365 int off = offset + position(); 366 return (bigEndian 367 ? (IntBuffer )(new ByteBufferAsIntBufferRB (this, 368 -1, 369 0, 370 size, 371 size, 372 off)) 373 : (IntBuffer )(new ByteBufferAsIntBufferRL (this, 374 -1, 375 0, 376 size, 377 size, 378 off))); 379 } 380 381 382 384 385 386 387 388 389 390 391 392 393 394 395 396 public ByteBuffer putLong(long x) { 397 398 399 400 401 throw new ReadOnlyBufferException (); 402 403 } 404 405 public ByteBuffer putLong(int i, long x) { 406 407 408 409 410 throw new ReadOnlyBufferException (); 411 412 } 413 414 public LongBuffer asLongBuffer() { 415 int size = this.remaining() >> 3; 416 int off = offset + position(); 417 return (bigEndian 418 ? (LongBuffer )(new ByteBufferAsLongBufferRB (this, 419 -1, 420 0, 421 size, 422 size, 423 off)) 424 : (LongBuffer )(new ByteBufferAsLongBufferRL (this, 425 -1, 426 0, 427 size, 428 size, 429 off))); 430 } 431 432 433 435 436 437 438 439 440 441 442 443 444 445 446 447 public ByteBuffer putFloat(float x) { 448 449 450 451 452 throw new ReadOnlyBufferException (); 453 454 } 455 456 public ByteBuffer putFloat(int i, float x) { 457 458 459 460 461 throw new ReadOnlyBufferException (); 462 463 } 464 465 public FloatBuffer asFloatBuffer() { 466 int size = this.remaining() >> 2; 467 int off = offset + position(); 468 return (bigEndian 469 ? (FloatBuffer )(new ByteBufferAsFloatBufferRB (this, 470 -1, 471 0, 472 size, 473 size, 474 off)) 475 : (FloatBuffer )(new ByteBufferAsFloatBufferRL (this, 476 -1, 477 0, 478 size, 479 size, 480 off))); 481 } 482 483 484 486 487 488 489 490 491 492 493 494 495 496 497 498 public ByteBuffer putDouble(double x) { 499 500 501 502 503 throw new ReadOnlyBufferException (); 504 505 } 506 507 public ByteBuffer putDouble(int i, double x) { 508 509 510 511 512 throw new ReadOnlyBufferException (); 513 514 } 515 516 public DoubleBuffer asDoubleBuffer() { 517 int size = this.remaining() >> 3; 518 int off = offset + position(); 519 return (bigEndian 520 ? (DoubleBuffer )(new ByteBufferAsDoubleBufferRB (this, 521 -1, 522 0, 523 size, 524 size, 525 off)) 526 : (DoubleBuffer )(new ByteBufferAsDoubleBufferRL (this, 527 -1, 528 0, 529 size, 530 size, 531 off))); 532 } 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 } 574 | Popular Tags |