Path: blob/master/test/jdk/javax/imageio/stream/DeleteOnExitTest.java
41149 views
/*1* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.ByteArrayInputStream;24import java.io.ByteArrayOutputStream;25import java.io.File;26import java.io.IOException;2728import javax.imageio.ImageIO;29import javax.imageio.stream.ImageInputStream;30import javax.imageio.stream.ImageOutputStream;3132public class DeleteOnExitTest {33public static void main(String[] args) throws IOException {34ByteArrayInputStream is =35new ByteArrayInputStream(new byte[100]);36ByteArrayOutputStream os =37new ByteArrayOutputStream();3839String tmp = System.getProperty("java.io.tmpdir", ".");40System.out.println("tmp: " + tmp);4142// count number of files before test43ImageIO.setUseCache(true);44ImageIO.setCacheDirectory(new File(tmp));4546File tmpDir = ImageIO.getCacheDirectory();47System.out.println("tmpDir is " + tmpDir);48int fnum_before = tmpDir.list().length;49System.out.println("Files before test: " + fnum_before);5051ImageInputStream iis =52ImageIO.createImageInputStream(is);53System.out.println("iis = " + iis);5455ImageInputStream iis2 =56ImageIO.createImageInputStream(is);5758ImageOutputStream ios =59ImageIO.createImageOutputStream(os);60System.out.println("ios = " + ios);6162ImageOutputStream ios2 =63ImageIO.createImageOutputStream(os);6465iis2.close();66ios2.close();67int fnum_after = tmpDir.list().length;68System.out.println("Files after test: " + fnum_after);6970if (fnum_before == fnum_after) {71throw new RuntimeException("Test failed: cache was not used.");72}73}74}757677