Refine search
/** * Creates a new temporary file with a generated unique name. * @return the new File * @throws IOException in case of error creating the new file */ public File newFile() throws IOException { return Files.createTempFile(root, "test", "file").toFile(); }
public String perform() { try { Path tmpFile; if (parentDir != null) { Path dir = vertx.resolveFile(parentDir).toPath(); if (attrs != null) { tmpFile = Files.createTempFile(dir, prefix, suffix, attrs); } else { tmpFile = Files.createTempFile(dir, prefix, suffix); } } else { if (attrs != null) { tmpFile = Files.createTempFile(prefix, suffix, attrs); } else { tmpFile = Files.createTempFile(prefix, suffix); } } return tmpFile.toFile().getAbsolutePath(); } catch (IOException e) { throw new FileSystemException(e); } } };
@Override public OutputStreamWrapper outputStream() throws IOException { File file = Files.createTempFile("blade", ".temp").toFile(); OutputStream outputStream = new FileOutputStream(file); return new OutputStreamWrapper(outputStream, file); }
@Override public OutputStreamWrapper outputStream() throws IOException { File file = Files.createTempFile("blade", ".temp").toFile(); OutputStream outputStream = new FileOutputStream(file); return new OutputStreamWrapper(outputStream, file); }
@Override public Path call() throws IOException { Path folder = target.getParent(); String prefix = target.getFileName().toString(); Path tempModuleLocation = Files.createTempFile(folder, prefix + "_", ".tmp"); tempModuleLocation.toFile().deleteOnExit(); logger.debug("Downloading {} from {}", target, url); long length = -1; URLConnection conn = url.openConnection(); if (conn instanceof HttpURLConnection) { length = ((HttpURLConnection) conn).getContentLengthLong(); } try (InputStream is = url.openStream(); OutputStream os = Files.newOutputStream(tempModuleLocation)) { copy(is, os, length, listener); Files.move(tempModuleLocation, target, StandardCopyOption.REPLACE_EXISTING); } return target; }
@Override public void data(final ByteBuffer buffer) throws IOException { this.currentFileSize += buffer.remaining(); if (this.maxIndividualFileSize > 0 && this.currentFileSize > this.maxIndividualFileSize) { throw UndertowMessages.MESSAGES.maxFileSizeExceeded(this.maxIndividualFileSize); } if (file == null && fileName != null && fileSizeThreshold < this.currentFileSize) { try { if (tempFileLocation != null) { file = Files.createTempFile(tempFileLocation, "undertow", "upload"); } else { file = Files.createTempFile("undertow", "upload"); } createdFiles.add(file); FileOutputStream fileOutputStream = new FileOutputStream(file.toFile()); contentBytes.writeTo(fileOutputStream); fileChannel = fileOutputStream.getChannel(); } catch (IOException e) { throw new RuntimeException(e); } } if (file == null) { while (buffer.hasRemaining()) { contentBytes.write(buffer.get()); } } else { fileChannel.write(buffer); } }
private static File copyToLocal(FileSystem fs, Path keyPath) throws IOException { java.nio.file.Path tmpKeyPath = Files.createTempFile(GoogleCommon.class.getSimpleName(), "tmp", PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwx------"))); File copied = tmpKeyPath.toFile(); copied.deleteOnExit(); fs.copyToLocalFile(keyPath, new Path(copied.getAbsolutePath())); return copied; }
@Implementation protected static FileDescriptor nCreate(String name, int size) throws ErrnoException { maybeThrow(fakeCreateException); TempDirectory tempDirectory = RuntimeEnvironment.getTempDirectory(); try { // Give each instance its own private file. File sharedMemoryFile = Files.createTempFile( tempDirectory.createIfNotExists("SharedMemory"), "shmem-" + name, ".tmp") .toFile(); RandomAccessFile randomAccessFile = new RandomAccessFile(sharedMemoryFile, "rw"); randomAccessFile.setLength(0); randomAccessFile.setLength(size); filesByFd.put(randomAccessFile.getFD(), sharedMemoryFile); return randomAccessFile.getFD(); } catch (IOException e) { throw new RuntimeException("Unable to create file descriptior", e); } }
/** * Get a temp file from the classpath, and (optionally) place it in the specified directory<br> * Note that:<br> * - If the directory is not specified, the file is copied to the default temporary directory, using * {@link Files#createTempFile(String, String, FileAttribute[])}. Consequently, the extracted file will have a * different filename to the extracted one.<br> * - If the directory *is* specified, the file is copied directly - and the original filename is maintained * * @param rootDirectory May be null. If non-null, copy to the specified directory * @return the temp file * @throws IOException If an error occurs when files are being copied * @see #getTempFileFromArchive(File) */ public File getTempFileFromArchive(File rootDirectory) throws IOException { InputStream is = getInputStream(); File tmpFile; if(rootDirectory != null){ //Maintain original file names, as it's going in a directory... tmpFile = new File(rootDirectory, FilenameUtils.getName(path)); } else { tmpFile = Files.createTempFile(FilenameUtils.getName(path), "tmp").toFile(); } tmpFile.deleteOnExit(); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tmpFile)); IOUtils.copy(is, bos); bos.flush(); bos.close(); return tmpFile; }
@Override public FSDataOutputStream create(Path path, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { if ((!overwrite) && exists(path)) { throw new IOException("File already exists:" + path); } if (!stagingDirectory.exists()) { createDirectories(stagingDirectory.toPath()); } if (!stagingDirectory.isDirectory()) { throw new IOException("Configured staging path is not a directory: " + stagingDirectory); } File tempFile = createTempFile(stagingDirectory.toPath(), "presto-s3-", ".tmp").toFile(); String key = keyFromPath(qualifiedPath(path)); return new FSDataOutputStream( new PrestoS3OutputStream(s3, getBucketName(uri), key, tempFile, sseEnabled, sseType, sseKmsKeyId, multiPartUploadMinFileSize, multiPartUploadMinPartSize, s3AclType), statistics); }
/** * Create a temp file that does not exists. */ public static File tmpFile(String suffix) throws Exception { File tmp = Files.createTempFile("vertx", suffix).toFile(); assertTrue(tmp.delete()); return tmp; }
private File getTempFile() throws Exception { return java.nio.file.Files.createTempFile("drill-hive-test", ".txt").toFile(); }
tmpFile = Files.createTempFile(metricsDir, "hmsmetrics", "json", FILE_ATTRS); } catch (IOException e) { LOG.error("failed to create temp file for JSON metrics", e); try (BufferedWriter bw = new BufferedWriter(new FileWriter(tmpFile.toFile()))) { bw.write(json); } catch (IOException e) { if (tmpFile.toFile().exists()) {
tmpFile = Files.createTempFile(metricsDir, "hmetrics", "json", FILE_ATTRS); } catch (IOException e) { LOGGER.error("failed to create temp file for JSON metrics", e); try (BufferedWriter bw = new BufferedWriter(new FileWriter(tmpFile.toFile()))) { bw.write(json); } catch (IOException e) { } finally { if (tmpFile != null && tmpFile.toFile().exists()) {
Path temporarySelectorFile = Files.createTempFile(null, null); temporarySelectorFile.toFile().deleteOnExit(); Blobs.writeToFileWithLock(Blobs.from(layerDigest.getHash()), temporarySelectorFile);
/** * * @return Path to the zip file that has all the filtered files, null if no files are selected to * export. */ public Path export() throws IOException { Path tempDirectory = Files.createTempDirectory("exportLogs"); if (baseLogFile != null) { for (Path logFile : findLogFiles(baseLogFile.toPath().getParent())) { Path filteredLogFile = tempDirectory.resolve(logFile.getFileName()); writeFilteredLogFile(logFile, filteredLogFile); } } if (baseStatsFile != null) { for (Path statFile : findStatFiles(baseStatsFile.toPath().getParent())) { Files.copy(statFile, tempDirectory.resolve(statFile.getFileName())); } } Path zipFile = null; if (tempDirectory.toFile().listFiles().length > 0) { zipFile = Files.createTempFile("logExport", ".zip"); ZipUtils.zipDirectory(tempDirectory, zipFile); LOGGER.info("Zipped files to: " + zipFile); } FileUtils.deleteDirectory(tempDirectory.toFile()); return zipFile; }
File tempFile = Files.createTempFile(baseName, "." + ext).toFile();
private static Path copyAndUncompress(Path compressed) throws IOException { Path tempFile = Files.createTempFile("part", ".csv"); tempFile.toFile().deleteOnExit(); try (InputStream in = new GZIPInputStream(Files.newInputStream(compressed))) { Files.copy(in, tempFile, StandardCopyOption.REPLACE_EXISTING); } return tempFile; }
final Path realJar; if (Files.isDirectory(apkIn)) { realJar = Files.createTempFile("d2j", ".jar"); tmp = realJar; System.out.println("zipping " + apkIn + " -> " + realJar); signer.sign(apkIn.toFile(), output.toFile());
@Before public void setUp() throws Exception { File file = Files.createTempFile("test", "json").toFile(); this.resource = new FileSystemResource(file); }