2058N/A/*
2058N/A * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
2058N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2058N/A *
2058N/A * This code is free software; you can redistribute it and/or modify it
2058N/A * under the terms of the GNU General Public License version 2 only, as
2058N/A * published by the Free Software Foundation.
2058N/A *
2058N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2058N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2058N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2058N/A * version 2 for more details (a copy is included in the LICENSE file that
2058N/A * accompanied this code).
2058N/A *
2058N/A * You should have received a copy of the GNU General Public License version
2058N/A * 2 along with this work; if not, write to the Free Software Foundation,
2058N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2058N/A *
2058N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2058N/A * or visit www.oracle.com if you need additional information or have any
2320N/A * questions.
2058N/A */
2058N/A
2058N/A/* @test
2058N/A @bug 4110528 4112112 4112103
2320N/A @summary Test if zip related in/output streams will
2058N/A prevent i/o after stream has been closed.
2058N/A */
2058N/Aimport java.util.zip.*;
2320N/Aimport java.util.jar.*;
2058N/Aimport java.io.*;
2058N/A
2058N/Apublic class StreamIOAfterClose {
2058N/A // compressed stub data
2058N/A private static byte[] compressed = {
2058N/A 31,-117,8,0,0,0,0,0,0,0,-85,-107,-79,74,85,97,117,48,
2058N/A -9,117,-47,114,15,-87,-27,-9,-54,-48,49,-108,17,19,20,
2058N/A 118,-87,-84,78,-15,-10,-87,-112,51,115,16,85,81,54,11,
2058N/A 114,44,11,98,116,17,102,-10,72,-10,80,-79,101,14,47,-50,
2058N/A 16,117,-9,-83,16,13,-55,83,83,103,-30,-117,-42,-82,-105,
2058N/A -119,46,-16,20,-111,-85,-16,-48,54,79,-53,-76,116,
2058N/A -80,-78,77,-88,-85,50,113,-54,15,-74,-28,-44,101,-43,47,
2058N/A 85,54,-74,1,0,85,69,28,117,100,0,0,0
2058N/A };
2058N/A
2058N/A private static void testRead(InputStream in) throws Exception {
2058N/A in.close();
2058N/A try {
2058N/A in.read();
2058N/A throw new Exception("read allowed after stream is closed");
2058N/A } catch (IOException e) {
2058N/A }
2058N/A }
private static void testWrite(ZipOutputStream out) throws Exception {
out.close();
try {
out.putNextEntry(new ZipEntry(""));
throw new Exception("write allowed after stream is closed");
} catch (IOException e) {
}
}
public static void main(String argv[]) throws Exception {
ZipOutputStream zos = new ZipOutputStream(new ByteArrayOutputStream());
zos.putNextEntry(new ZipEntry("1"));
testWrite(zos);
JarOutputStream jos = new JarOutputStream(new ByteArrayOutputStream());
jos.putNextEntry(new ZipEntry("1"));
testWrite(jos);
InputStream bis = new ByteArrayInputStream(new byte[10]);
InputStream bis1 = new ByteArrayInputStream(compressed);
testRead(new ZipInputStream(bis));
testRead(new GZIPInputStream(bis1));
}
}