111 int n = b.capacity();
112 b.clear();
113 char[] a = new char[n + 7];
114 for (int i = 0; i < n; i++)
115 a[i + 7] = (char)ic(i);
116 b.put(a, 7, n);
117 b.flip();
118 }
119
120 private static void bulkPutBuffer(CharBuffer b) {
121 int n = b.capacity();
122 b.clear();
123 CharBuffer c = CharBuffer.allocate(n + 7);
124 c.position(7);
125 for (int i = 0; i < n; i++)
126 c.put((char)ic(i));
127 c.flip();
128 c.position(7);
129 b.put(c);
130 b.flip();
131 }
132
133 //6231529
134 private static void callReset(CharBuffer b) {
135 b.position(0);
136 b.mark();
137
138 b.duplicate().reset();
139 b.asReadOnlyBuffer().reset();
140 }
141
142
143
144 // 6221101-6234263
145
146 private static void putBuffer() {
147 final int cap = 10;
148
149 CharBuffer direct1 = ByteBuffer.allocateDirect(cap).asCharBuffer();
150 CharBuffer nondirect1 = ByteBuffer.allocate(cap).asCharBuffer();
447 b.get(b.limit());
448 }});
449 tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
450 public void run() {
451 b.get(-1);
452 }});
453
454 tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
455 public void run() {
456 b.put(b.limit(), (char)42);
457 }});
458
459 tryCatch(b, InvalidMarkException.class, new Runnable() {
460 public void run() {
461 b.position(0);
462 b.mark();
463 b.compact();
464 b.reset();
465 }});
466
467 // Values
468
469 b.clear();
470 b.put((char)0);
471 b.put((char)-1);
472 b.put((char)1);
473 b.put(Character.MAX_VALUE);
474 b.put(Character.MIN_VALUE);
475
476
477
478
479
480
481
482
483
484
485
486
917 CharBuffer.wrap(ba, 0, ba.length + 1);
918 }});
919
920 // A NullPointerException will be thrown if the array is null.
921 tryCatch(ba, NullPointerException.class, new Runnable() {
922 public void run() {
923 CharBuffer.wrap((char []) null, 0, 5);
924 }});
925 tryCatch(ba, NullPointerException.class, new Runnable() {
926 public void run() {
927 CharBuffer.wrap((char []) null);
928 }});
929 }
930
931 private static void testAllocate() {
932 // An IllegalArgumentException will be thrown for negative capacities.
933 tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
934 public void run() {
935 CharBuffer.allocate(-1);
936 }});
937
938
939
940
941
942
943 }
944
945 public static void test() {
946 testAllocate();
947 test(0, CharBuffer.allocate(7 * 1024), false);
948 test(0, CharBuffer.wrap(new char[7 * 1024], 0, 7 * 1024), false);
949 test(new char[1024]);
950
951
952
953
954
955
956
|
111 int n = b.capacity();
112 b.clear();
113 char[] a = new char[n + 7];
114 for (int i = 0; i < n; i++)
115 a[i + 7] = (char)ic(i);
116 b.put(a, 7, n);
117 b.flip();
118 }
119
120 private static void bulkPutBuffer(CharBuffer b) {
121 int n = b.capacity();
122 b.clear();
123 CharBuffer c = CharBuffer.allocate(n + 7);
124 c.position(7);
125 for (int i = 0; i < n; i++)
126 c.put((char)ic(i));
127 c.flip();
128 c.position(7);
129 b.put(c);
130 b.flip();
131 try {
132 b.put(b);
133 fail("IllegalArgumentException expected for putting into same buffer");
134 } catch (IllegalArgumentException e) {
135 if (e.getMessage() == null) {
136 fail("Non-null IllegalArgumentException message expected from putting into same buffer");
137 }
138 }
139 }
140
141 //6231529
142 private static void callReset(CharBuffer b) {
143 b.position(0);
144 b.mark();
145
146 b.duplicate().reset();
147 b.asReadOnlyBuffer().reset();
148 }
149
150
151
152 // 6221101-6234263
153
154 private static void putBuffer() {
155 final int cap = 10;
156
157 CharBuffer direct1 = ByteBuffer.allocateDirect(cap).asCharBuffer();
158 CharBuffer nondirect1 = ByteBuffer.allocate(cap).asCharBuffer();
455 b.get(b.limit());
456 }});
457 tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
458 public void run() {
459 b.get(-1);
460 }});
461
462 tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
463 public void run() {
464 b.put(b.limit(), (char)42);
465 }});
466
467 tryCatch(b, InvalidMarkException.class, new Runnable() {
468 public void run() {
469 b.position(0);
470 b.mark();
471 b.compact();
472 b.reset();
473 }});
474
475 try {
476 b.position(b.limit() + 1);
477 fail("IllegalArgumentException expected for setting position beyond limit");
478 } catch (IllegalArgumentException e) {
479 if (e.getMessage() == null) {
480 fail("Non-null IllegalArgumentException message expected for setting position beyond limit");
481 }
482 }
483
484 try {
485 b.position(-1);
486 fail("IllegalArgumentException expected for setting negative position");
487 } catch (IllegalArgumentException e) {
488 if (e.getMessage() == null) {
489 fail("Non-null IllegalArgumentException message expected for setting negative position");
490 }
491 }
492
493 try {
494 b.limit(b.capacity() + 1);
495 fail("IllegalArgumentException expected for setting limit beyond capacity");
496 } catch (IllegalArgumentException e) {
497 if (e.getMessage() == null) {
498 fail("Non-null IllegalArgumentException message expected for setting limit beyond capacity");
499 }
500 }
501
502 try {
503 b.limit(-1);
504 fail("IllegalArgumentException expected for setting negative limit");
505 } catch (IllegalArgumentException e) {
506 if (e.getMessage() == null) {
507 fail("Non-null IllegalArgumentException message expected for setting negative limit");
508 }
509 }
510
511 // Values
512
513 b.clear();
514 b.put((char)0);
515 b.put((char)-1);
516 b.put((char)1);
517 b.put(Character.MAX_VALUE);
518 b.put(Character.MIN_VALUE);
519
520
521
522
523
524
525
526
527
528
529
530
961 CharBuffer.wrap(ba, 0, ba.length + 1);
962 }});
963
964 // A NullPointerException will be thrown if the array is null.
965 tryCatch(ba, NullPointerException.class, new Runnable() {
966 public void run() {
967 CharBuffer.wrap((char []) null, 0, 5);
968 }});
969 tryCatch(ba, NullPointerException.class, new Runnable() {
970 public void run() {
971 CharBuffer.wrap((char []) null);
972 }});
973 }
974
975 private static void testAllocate() {
976 // An IllegalArgumentException will be thrown for negative capacities.
977 tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
978 public void run() {
979 CharBuffer.allocate(-1);
980 }});
981 try {
982 CharBuffer.allocate(-1);
983 } catch (IllegalArgumentException e) {
984 if (e.getMessage() == null) {
985 fail("Non-null IllegalArgumentException message expected attempt to allocate negative capacity buffer");
986 }
987 }
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001 }
1002
1003 public static void test() {
1004 testAllocate();
1005 test(0, CharBuffer.allocate(7 * 1024), false);
1006 test(0, CharBuffer.wrap(new char[7 * 1024], 0, 7 * 1024), false);
1007 test(new char[1024]);
1008
1009
1010
1011
1012
1013
1014
|