test/lib/jdk/test/lib/Utils.java
changeset 50225 2942ae532175
parent 49255 acdb8531cc8b
child 50367 b73f9723aa54
equal deleted inserted replaced
50224:67066e7971e1 50225:2942ae532175
    33 import java.net.URLClassLoader;
    33 import java.net.URLClassLoader;
    34 import java.net.UnknownHostException;
    34 import java.net.UnknownHostException;
    35 import java.nio.file.Files;
    35 import java.nio.file.Files;
    36 import java.nio.file.Path;
    36 import java.nio.file.Path;
    37 import java.nio.file.Paths;
    37 import java.nio.file.Paths;
       
    38 import java.nio.file.attribute.FileAttribute;
    38 import java.nio.channels.SocketChannel;
    39 import java.nio.channels.SocketChannel;
    39 import java.util.ArrayList;
    40 import java.util.ArrayList;
    40 import java.util.Arrays;
    41 import java.util.Arrays;
    41 import java.util.Collection;
    42 import java.util.Collection;
    42 import java.util.Collections;
    43 import java.util.Collections;
   768         }
   769         }
   769 
   770 
   770         return result;
   771         return result;
   771     }
   772     }
   772 
   773 
       
   774     /**
       
   775      * Creates an empty file in "user.dir" if the property set.
       
   776      * <p>
       
   777      * This method is meant as a replacement for {@code Files#createTempFile(String, String, FileAttribute...)}
       
   778      * that doesn't leave files behind in /tmp directory of the test machine
       
   779      * <p>
       
   780      * If the property "user.dir" is not set, "." will be used.
       
   781      *
       
   782      * @param prefix
       
   783      * @param suffix
       
   784      * @param attrs
       
   785      * @return the path to the newly created file that did not exist before this
       
   786      *         method was invoked
       
   787      * @throws IOException
       
   788      *
       
   789      * @see {@link Files#createTempFile(String, String, FileAttribute...)}
       
   790      */
       
   791     public static Path createTempFile(String prefix, String suffix, FileAttribute<?>... attrs) throws IOException {
       
   792         Path dir = Paths.get(System.getProperty("user.dir", "."));
       
   793         return Files.createTempFile(dir, prefix, suffix);
       
   794     }
   773 }
   795 }
   774 
   796