3235N/A/*
3235N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3235N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3235N/A *
3235N/A * This code is free software; you can redistribute it and/or modify it
3235N/A * under the terms of the GNU General Public License version 2 only, as
3235N/A * published by the Free Software Foundation.
3235N/A *
3235N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3235N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3235N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3235N/A * version 2 for more details (a copy is included in the LICENSE file that
3235N/A * accompanied this code).
3235N/A *
3235N/A * You should have received a copy of the GNU General Public License version
3235N/A * 2 along with this work; if not, write to the Free Software Foundation,
3235N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3235N/A *
3235N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3235N/A * or visit www.oracle.com if you need additional information or have any
3235N/A * questions.
3235N/A */
3235N/A
3235N/A/* @test
3235N/A @bug 7003462
3235N/A @summary Make sure cached Inflater does not get finalized.
3235N/A */
3235N/A
3235N/Aimport java.io.File;
3235N/Aimport java.io.InputStream;
3235N/Aimport java.io.IOException;
3235N/Aimport java.util.zip.ZipEntry;
3235N/Aimport java.util.zip.ZipFile;
3235N/A
3235N/Apublic class FinalizeInflater {
3235N/A
3235N/A public static void main(String[] args) throws Throwable {
3235N/A try (ZipFile zf = new ZipFile(new File(System.getProperty("test.src", "."), "input.zip")))
3235N/A {
3235N/A ZipEntry ze = zf.getEntry("ReadZip.java");
3235N/A read(zf.getInputStream(ze));
3235N/A System.gc();
3235N/A System.runFinalization();
3235N/A System.gc();
3235N/A // read again
3235N/A read(zf.getInputStream(ze));
3235N/A }
3235N/A }
3235N/A
3235N/A private static void read(InputStream is)
3235N/A throws IOException
3235N/A {
3235N/A Wrapper wrapper = new Wrapper(is);
3235N/A byte[] buffer = new byte[32];
3235N/A try {
3235N/A while(is.read(buffer)>0){}
3235N/A } catch (IOException ioe) {
3235N/A ioe.printStackTrace();
3235N/A }
3235N/A }
3235N/A
3235N/A static class Wrapper{
3235N/A InputStream is;
3235N/A public Wrapper(InputStream is) {
3235N/A this.is = is;
3235N/A }
3235N/A
3235N/A @Override
3235N/A protected void finalize() throws Throwable {
3235N/A super.finalize();
3235N/A is.close();
3235N/A }
3235N/A }
3235N/A}