/* * Copyright 2009 Sun Microsystems, Inc. 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ /** * @test * @bug 4167874 * @library ../../../../com/sun/net/httpserver * @build FileServerHandler * @run shell build.sh * @run main/othervm CloseTest * @summary URL-downloaded jar files can consume all available file descriptors */ import java.io.*; import java.net.*; import java.lang.reflect.*; import com.sun.net.httpserver.*; public class CloseTest { static void copyFile (String src, String dst) { copyFile (new File(src), new File(dst)); } static void copyDir (String src, String dst) { copyDir (new File(src), new File(dst)); } static void copyFile (File src, File dst) { try { if (!src.isFile()) { throw new RuntimeException ("File not found: " + src.toString()); } dst.delete(); dst.createNewFile(); FileInputStream i = new FileInputStream (src); FileOutputStream o = new FileOutputStream (dst); byte[] buf = new byte [1024]; int count; while ((count=i.read(buf)) >= 0) { o.write (buf, 0, count); } i.close(); o.close(); } catch (IOException e) { throw new RuntimeException (e); } } static void rm_minus_rf (File path) { if (!path.exists()) { return; } if (path.isFile()) { if (!path.delete()) { throw new RuntimeException ("Could not delete " + path); } } else if (path.isDirectory ()) { String[] names = path.list(); File[] files = path.listFiles(); for (int i=0; i