Path: blob/master/test/jdk/java/io/File/createTempFile/Patterns.java
41152 views
/*1* Copyright (c) 1998, 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*/2223/* @test24@bug 4152178 815227225@summary Check various temp-file prefix/suffix cases */2627import java.io.File;28import java.io.IOException;2930public class Patterns {3132static File dir = new File(".");3334static void ckn(String prefix, String suffix) throws Exception {35try {36File f = File.createTempFile(prefix, suffix, dir);37f.deleteOnExit();38} catch (Exception x) {39if ((x instanceof IOException)40|| (x instanceof NullPointerException)41|| (x instanceof IllegalArgumentException)) {42System.err.println("\"" + prefix + "\", \"" + suffix43+ "\" failed as expected: " + x.getMessage());44return;45}46throw x;47}48throw new Exception("\"" + prefix + "\", \"" + suffix49+ "\" should have failed");50}5152static void cky(String prefix, String suffix) throws Exception {53File f = File.createTempFile(prefix, suffix, dir);54f.deleteOnExit();55System.err.println("\"" + prefix + "\", \"" + suffix56+ "\" --> " + f.getPath());57}5859public static void main(String[] args) throws Exception {60ckn(null, null);61ckn("", null);62ckn("x", null);63ckn("xx", null);64cky("xxx", null);65cky("xxx", "");66cky("xxx", "y");67cky("xxx", ".y");68cky("xyz", "Directory" + System.getProperty("file.separator"));69}7071}727374