Os { public static File newTempFile(String prefix, String ext) { String sanitizedPrefix = (Strings.isNonEmpty(prefix) ? Strings.makeValidFilename(prefix) + "-" : ""); if (sanitizedPrefix.length()>101) sanitizedPrefix = sanitizedPrefix.substring(0, 100)+"--"; String extWithPrecedingSeparator = (Strings.isNonEmpty(ext) ? ext.startsWith(".") || ext.length()>4 ? ext : "."+ext : ""); if (extWithPrecedingSeparator.length()>13) sanitizedPrefix = sanitizedPrefix.substring(0, 12)+"--"; try { File tempFile = File.createTempFile(sanitizedPrefix, extWithPrecedingSeparator, new File(tmp())); tempFile.deleteOnExit(); return tempFile; } catch (IOException e) { throw Exceptions.propagate(e); } }  static String tmp(); static String user(); static String home(); static String mergePathsUnix(String ...items); static String mergePaths(String ...items); @Beta static DeletionResult deleteRecursively(File dir); @Beta static DeletionResult deleteRecursively(File dir, boolean skipSafetyChecks); @Beta static DeletionResult deleteRecursively(String dir); static void deleteOnExit(File directoryToDeleteIfEmptyOrFile); static void deleteOnExitRecursively(File directoryToCleanOrFile); static int deleteOnExitEmptyParentsUpTo(File subsubDirOrFile, File dir); static void deleteOnExitRecursivelyAndEmptyParentsUpTo(File directoryToCleanOrFile, File highestAncestorToDelete); static File mkdirs(File dir); static File writeToTempFile(InputStream is, String prefix, String suffix); static File writeToTempFile(InputStream is, File tempDir, String prefix, String suffix); static File writePropertiesToTempFile(Properties props, String prefix, String suffix); static File writePropertiesToTempFile(Properties props, File tempDir, String prefix, String suffix); static String tidyPath(String path); static boolean isAbsolutish(String path); static String fromHome(String path); static String nativePath(String path); static boolean isMicrosoftWindows(); static File newTempFile(String prefix, String ext); static File newTempFile(Class<?> clazz, String ext); static File newTempDir(String prefix); static File newTempDir(Class<?> clazz); static final String LINE_SEPARATOR; }
@Test(groups="Integration") public void testNewTempFile() { int CREATE_CNT = 5000; Collection<File> folders = new ArrayList<File>(CREATE_CNT); try { for (int i = 0; i < CREATE_CNT; i++) { try { folders.add(Os.newTempFile(OsTest.class, "test")); } catch (IllegalStateException e) { log.warn("testNewTempFile failed at " + i + " iteration."); Exceptions.propagate(e); } } } finally { for (File folder : folders) { folder.delete(); } } }