private static File createOutputFile(String fileName) throws IOException { File outputFile = new File(fileName); Files.createParentDirs(outputFile); return outputFile; }
private void createDirectoryStructureIfNotExists(final File dir) throws IOException { if (!dir.exists()) { try { Files.createParentDirs(new File(dir, DUMMY_FILE_NAME)); } catch (final IOException e) { throw new IOException("Failed to create directory: " + dir.getAbsolutePath(), e); } } else if (!dir.isDirectory()) { throw new IOException("This location is not a directory: " + dir.getAbsolutePath()); } }
@GuardedBy("tasks") private void saveRunningTasks() { final File restoreFile = getRestoreFile(); final List<String> theTasks = new ArrayList<>(); for (ForkingTaskRunnerWorkItem forkingTaskRunnerWorkItem : tasks.values()) { theTasks.add(forkingTaskRunnerWorkItem.getTaskId()); } try { Files.createParentDirs(restoreFile); jsonMapper.writeValue(restoreFile, new TaskRestoreInfo(theTasks)); } catch (Exception e) { log.warn(e, "Failed to save tasks to restore file[%s]. Skipping this save.", restoreFile); } }
/** * Saves this {@link FileConfiguration} to the specified location. * <p> * If the file does not exist, it will be created. If already exists, it * will be overwritten. If it cannot be overwritten or created, an * exception will be thrown. * <p> * This method will save using the system default encoding, or possibly * using UTF8. * * @param file File to save to. * @throws IOException Thrown when the given file cannot be written to for * any reason. * @throws IllegalArgumentException Thrown when file is null. */ public void save(File file) throws IOException { Validate.notNull(file, "File cannot be null"); Files.createParentDirs(file); String data = saveToString(); Writer writer = new OutputStreamWriter(new FileOutputStream(file), UTF8_OVERRIDE && !UTF_BIG ? Charsets.UTF_8 : Charset.defaultCharset()); try { writer.write(data); } finally { writer.close(); } }
@VisibleForTesting static MemoryHistory getHistory(File historyFile) { MemoryHistory history; try { // try creating the history file and its parents to check // whether the directory tree is readable/writeable createParentDirs(historyFile.getParentFile()); historyFile.createNewFile(); history = new FileHistory(historyFile); history.setMaxSize(10000); } catch (IOException e) { System.err.printf("WARNING: Failed to load history file (%s): %s. " + "History will not be available during this session.%n", historyFile, e.getMessage()); history = new MemoryHistory(); } history.setAutoTrim(true); return history; }
public static void createSourceJsonFile(File sourceJsonFile) throws IOException { Files.createParentDirs(sourceJsonFile); Files.write(SOURCE_JSON_DOCS, sourceJsonFile, ConfigurationKeys.DEFAULT_CHARSET_ENCODING); }
public void testCreateParentDirs_relativePath() throws IOException { File file = file("nonexistent.file"); assertNull(file.getParentFile()); assertNotNull(file.getCanonicalFile().getParentFile()); Files.createParentDirs(file); }
public void testCreateParentDirs_root() throws IOException { File file = root(); assertNull(file.getParentFile()); assertNull(file.getCanonicalFile().getParentFile()); Files.createParentDirs(file); }
public void testCreateParentDirs_noParentsNeeded() throws IOException { File file = file(getTempDir(), "nonexistent.file"); assertTrue(file.getParentFile().exists()); Files.createParentDirs(file); }
public void testCreateParentDirs_multipleParentsNeeded() throws IOException { File file = file(getTempDir(), "grandparent", "parent", "nonexistent.file"); File parent = file.getParentFile(); File grandparent = parent.getParentFile(); assertFalse(grandparent.exists()); Files.createParentDirs(file); assertTrue(parent.exists()); }
public void testCreateParentDirs_oneParentNeeded() throws IOException { File file = file(getTempDir(), "parent", "nonexistent.file"); File parent = file.getParentFile(); assertFalse(parent.exists()); try { Files.createParentDirs(file); assertTrue(parent.exists()); } finally { assertTrue(parent.delete()); } }
@Override public synchronized void open() throws IOException { if (this.sps == null) { String file = outputSpec.getFile(); if (outputSpec.isLogStdout() || file == null) { this.sps = new SharedPrintStream(System.out); } else { SharedPrintStream cachedPs = printStreamMap.get(file); if (cachedPs == null) { Files.createParentDirs(new File(file)); PrintStream ps = new PrintStream(new FileOutputStream(file), true); cachedPs = new SharedPrintStream(ps); printStreamMap.put(file, cachedPs); } else { cachedPs.allocate(); } this.sps = cachedPs; } } }
public void testCreateParentDirs_nonDirectoryParentExists() throws IOException { File parent = getTestFile("ascii.txt"); assertTrue(parent.isFile()); File file = file(parent, "foo"); try { Files.createParentDirs(file); fail(); } catch (IOException expected) { } }
Files.createParentDirs(new File(pathToApplicationConfInSrcDir));
public void generate() throws Exception { initPlanTest(); try { getQueryResourcePaths() .parallel() .forEach(queryResourcePath -> { try { Path queryPlanWritePath = Paths.get( getSourcePath().toString(), "src/test/resources", getQueryPlanResourcePath(queryResourcePath)); createParentDirs(queryPlanWritePath.toFile()); write(generateQueryPlan(read(queryResourcePath)).getBytes(UTF_8), queryPlanWritePath.toFile()); System.out.println("Generated expected plan for query: " + queryResourcePath); } catch (IOException e) { throw new UncheckedIOException(e); } }); } finally { destroyPlanTest(); } }
if ( usState.getUs() != null ) Files.createParentDirs(idFile); String id = String.format("%d\n", usState.getUs().getServerId()); Files.write(id.getBytes(), idFile);
/** * Write contents to a file * * @param file * @param contents * @return file handle * @throws IOException */ public static File write(File file, String contents) throws IOException { com.google.common.io.Files.createParentDirs(file); com.google.common.io.Files.write(contents, file, StandardCharsets.UTF_8); return file; } }
/** * Write contents to a file * * @param file * @param contents * @return file handle * @throws IOException */ public static File write(File file, String contents) throws IOException { com.google.common.io.Files.createParentDirs(file); com.google.common.io.Files.write(contents, file, StandardCharsets.UTF_8); return file; } }
/** * Open a CSV writer to write to a file. * * @param file The file to write to. * @param layout The layout of the table. * @param compression What compression, if any, to use. * @return A CSV writer outputting to {@code file}. * @throws IOException if there is an error opening the file or writing the column header. */ public static CSVWriter open(File file, TableLayout layout, CompressionMode compression) throws IOException { Files.createParentDirs(file); Writer writer = LKFileUtils.openOutput(file, Charset.defaultCharset(), compression); try { return new CSVWriter(writer, layout); } catch (Throwable th) { try { writer.close(); } catch (Throwable th2) { th.addSuppressed(th2); } Throwables.propagateIfInstanceOf(th, IOException.class); throw Throwables.propagate(th); } }
Files.createParentDirs(gitPropsFile); try (OutputStream outputStream = new FileOutputStream(gitPropsFile)) { SortedProperties sortedLocalProperties = new SortedProperties();