11/*
2- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3333 * @library /test/lib
3434 * @build jdk.test.lib.RandomFactory
3535 * @run main ReadAllReadNTransferTo
36- * @bug 8180451
36+ * @bug 6766844 8180451
3737 * @summary Verify ByteArrayInputStream readAllBytes, readNBytes, and transferTo
3838 * @key randomness
3939 */
@@ -48,8 +48,16 @@ public static void main(String... args) throws IOException {
4848 int position = random .nextInt (SIZE /2 );
4949 int size = random .nextInt (SIZE - position );
5050
51- ByteArrayInputStream bais =
52- new ByteArrayInputStream (buf , position , size );
51+ ByteArrayInputStream bais = new ByteArrayInputStream (buf );
52+ bais .readAllBytes ();
53+ if (bais .read (new byte [0 ]) != -1 ) {
54+ throw new RuntimeException ("read(byte[]) did not return -1" );
55+ }
56+ if (bais .read (new byte [1 ], 0 , 0 ) != -1 ) {
57+ throw new RuntimeException ("read(byte[],int,int) did not return -1" );
58+ }
59+
60+ bais = new ByteArrayInputStream (buf , position , size );
5361 int off = size < 2 ? 0 : random .nextInt (size / 2 );
5462 int len = size - off < 1 ? 0 : random .nextInt (size - off );
5563
@@ -72,7 +80,6 @@ public static void main(String... args) throws IOException {
7280 throw new RuntimeException ("readAllBytes content" );
7381 }
7482
75- // XXX transferTo()
7683 bais = new ByteArrayInputStream (buf );
7784 ByteArrayOutputStream baos = new ByteArrayOutputStream (buf .length );
7885 if (bais .transferTo (baos ) != buf .length ) {
0 commit comments