@Override public void run() { deleteTemporaryFiles(); } };
public static File unzip(InputStream resource) throws IOException { File output = TemporaryFilesystem.createTempDir("unzip", "stream"); ZipInputStream zipStream = new ZipInputStream(new BufferedInputStream(resource, BUF_SIZE)); ZipEntry entry = zipStream.getNextEntry(); while (entry != null) { if (entry.isDirectory()) { createDir(new File(output, entry.getName())); } else { unzipFile(output, zipStream, entry.getName()); } entry = zipStream.getNextEntry(); } return output; }
/** * Delete a temporary directory that we were responsible for creating. * * @param file the file to delete * @throws WebDriverException if interrupted */ public static void deleteTempDir(File file) { if (!shouldReap()) { return; } // If the tempfile can be removed, delete it. If not, it wasn't created by us. if (temporaryFiles.remove(file)) { FileHandler.delete(file); } }
File parentDir = TemporaryFilesystem.createTempDir("webdriver", "libs");
/** * Perform the operation that a shutdown hook would have. */ public static void deleteTemporaryFiles() { if (!shouldReap()) { return; } for (File file : temporaryFiles) { try { FileHandler.delete(file); } catch (WebDriverException e) { // ignore; an interrupt will already have been logged. } } }
File profileDir = TemporaryFilesystem.createTempDir("profile", ""); File firstRunFile = new File(profileDir, "First Run Dev"); firstRunFile.createNewFile();