diff options
Diffstat (limited to 'test/sun/security/util/DerValue/BadValue.java')
-rw-r--r-- | test/sun/security/util/DerValue/BadValue.java | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/test/sun/security/util/DerValue/BadValue.java b/test/sun/security/util/DerValue/BadValue.java index ef3a9ef381..d02a47896e 100644 --- a/test/sun/security/util/DerValue/BadValue.java +++ b/test/sun/security/util/DerValue/BadValue.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -35,43 +35,48 @@ public class BadValue { public static void main(String[] args) throws Exception { - // Test IOUtils.readFully + // Test IOUtils. // We have 4 bytes InputStream in = new ByteArrayInputStream(new byte[10]); - byte[] bs = IOUtils.readFully(in, 4, true); + byte[] bs = IOUtils.readExactlyNBytes(in, 4); if (bs.length != 4 || in.available() != 6) { throw new Exception("First read error"); } // But only 6 left - bs = IOUtils.readFully(in, 10, false); + bs = IOUtils.readNBytes(in, 10); if (bs.length != 6 || in.available() != 0) { throw new Exception("Second read error"); } - // MAX read as much as it can + // MAX length results in exception in = new ByteArrayInputStream(new byte[10]); - bs = IOUtils.readFully(in, Integer.MAX_VALUE, true); - if (bs.length != 10 || in.available() != 0) { - throw new Exception("Second read error"); + try { + bs = IOUtils.readExactlyNBytes(in, Integer.MAX_VALUE); + throw new Exception("No exception on MAX_VALUE length"); + } catch (EOFException ex) { + // this is expected } - // MAX ignore readAll + // -1 length results in exception in = new ByteArrayInputStream(new byte[10]); - bs = IOUtils.readFully(in, Integer.MAX_VALUE, false); - if (bs.length != 10 || in.available() != 0) { - throw new Exception("Second read error"); + try { + bs = IOUtils.readExactlyNBytes(in, -1); + throw new Exception("No exception on -1 length"); + } catch (IOException ex) { + // this is expected } + // 20>10, readAll means failure in = new ByteArrayInputStream(new byte[10]); try { - bs = IOUtils.readFully(in, 20, true); - throw new Exception("Third read error"); + bs = IOUtils.readExactlyNBytes(in, 20); + throw new Exception("No exception on EOF"); } catch (EOFException e) { // OK } int bignum = 10 * 1024 * 1024; - bs = IOUtils.readFully(new SuperSlowStream(bignum), -1, true); + bs = IOUtils.readExactlyNBytes(new SuperSlowStream(bignum), bignum); if (bs.length != bignum) { - throw new Exception("Fourth read error"); + throw new Exception("Read returned small array"); } // Test DerValue |