/** * Write the last processed commit githash to the checkpoint file * @param gitHash * @throws IOException */ private void writeCheckpoint(String gitHash) throws IOException { // write to a temporary name then rename to make the operation atomic when the file system allows a file to be // replaced File tmpCheckpointFile = new File(this.repoDir, CHECKPOINT_FILE_TMP); File checkpointFile = new File(this.repoDir, CHECKPOINT_FILE); Files.write(gitHash, tmpCheckpointFile, Charsets.UTF_8); Files.move(tmpCheckpointFile, checkpointFile); }
private void persistEventTypeIdMap() { //noinspection ResultOfMethodCallIgnored new File(filename).getParentFile().mkdirs(); String newFilename = filename + ".new"; try { try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(newFilename))) { oos.writeObject(eventTypeIdMap); } Files.move(new File(newFilename), new File(filename)); } catch (IOException e) { throw new RuntimeException(e); } } }
/** * {@inheritDoc} */ @Override public synchronized void writeCheckpoint(Dag<JobExecutionPlan> dag) throws IOException { // write to a temporary name then rename to make the operation atomic when the file system allows a file to be // replaced String fileName = DagManagerUtils.generateDagId(dag) + DAG_FILE_EXTENSION; String serializedDag = serializeDag(dag); File tmpCheckpointFile = new File(this.dagCheckpointDir, fileName + ".tmp"); File checkpointFile = new File(this.dagCheckpointDir, fileName); Files.write(serializedDag, tmpCheckpointFile, Charsets.UTF_8); Files.move(tmpCheckpointFile, checkpointFile); }
@Override public void onJobCompletion(JobContext jobContext) { JobState jobState = jobContext.getJobState(); if (!jobState.contains(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY)) { LOG.error("Job configuration file path not found in job state of job " + jobState.getJobId()); return; } String jobConfigFile = jobState.getProp(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY); // Rename the config file so we won't run this job when the worker is bounced try { Files.move(new File(jobConfigFile), new File(jobConfigFile + ".done")); } catch (IOException ioe) { LOG.error("Failed to rename job configuration file for job " + jobState.getJobName(), ioe); } } }
private void moveHelper(boolean success, File from, File to) throws IOException { try { Files.move(from, to); if (success) { assertFalse(from.exists()); assertTrue(to.exists()); } else { fail("expected exception"); } } catch (IOException possiblyExpected) { if (success) { throw possiblyExpected; } } }
+ "." + System.currentTimeMillis()); Files.move(srcFile, backupFile); writer = Files.newWriter(srcFile, Charset.defaultCharset());
private void generateRefreshJarFiles(String version) throws IOException, InterruptedException { String u = HiveTestUtils .getFileFromClasspath(RELOADED_CLAZZ_PREFIX_NAME + version + HiveTestUtils.TXT_FILE_EXT); File jarFile = HiveTestUtils.genLocalJarForTest(u, RELOADED_CLAZZ_PREFIX_NAME); Files.move(jarFile, new File(jarFile.getAbsolutePath() + "." + version)); }
) { FileCopyUtils.copy(in, out); Files.move(cachedResourceVersionDownloadFile, cachedResourceVersionDataFile);
Files.move(nodeConf2, nodeConf); n++;
private void replace(final FileInfo input) throws DITAOTException { final File inputFile = new File(job.tempDir, input.file.getPath() + FILE_EXTENSION_TEMP); final File outputFile = new File(job.tempDir, input.file.getPath()); try { Files.move(inputFile, outputFile); } catch (final IOException e) { throw new DITAOTException("Failed to replace temporary file " + inputFile + ": " + e.getMessage(), e); } }
private void writeNow() throws IOException { T val = requireWrite.getAndSet(null); Stopwatch stopwatch = new Stopwatch(); // Write to the temp file, then atomically move it to the permanent file location Files.write(serializer.toString(val)+"\n", tmpFile, Charsets.UTF_8); Files.move(tmpFile, file); modCount.incrementAndGet(); if (LOG.isTraceEnabled()) LOG.trace("Wrote {}, took {}ms; modified file {} times", new Object[] {file, stopwatch.elapsed(TimeUnit.MILLISECONDS), modCount}); }
@Override public void close() throws IOException { if (writer.isPresent()) { writer.get().endArray().close(); } if (workFile.exists()) { Files.move(workFile, resultFile); } } }
/** * Sorts the given file externally using the {@link #lexComparator} and removes duplicates. * * @param file file whose contents needs to be sorted */ public static void sort(File file) throws IOException { File sorted = createTempFile("fleioutilssort", null); merge(sortInBatch(file, lexComparator, true), sorted); move(sorted, file); }
/** * Sorts the given file externally using the {@link #lexComparator} and removes duplicates. * * @param file file whose contents needs to be sorted */ public static void sort(File file) throws IOException { File sorted = createTempFile("fleioutilssort", null); merge(sortInBatch(file, lexComparator, true), sorted); move(sorted, file); }
/** * Sorts the given file externally with the given comparator and removes duplicates. * * @param file file whose contents needs to be sorted * @param comparator to compare * @throws IOException */ public static void sort(File file, Comparator<String> comparator) throws IOException { File sorted = createTempFile("fleioutilssort", null); merge(sortInBatch(file, comparator, true), sorted, comparator); move(sorted, file); }
/** * Sorts the given file externally with the given comparator and removes duplicates. * * @param file file whose contents needs to be sorted * @param comparator to compare * @throws IOException */ public static void sort(File file, Comparator<String> comparator) throws IOException { File sorted = createTempFile("fleioutilssort", null); merge(sortInBatch(file, comparator, true), sorted, comparator); move(sorted, file); }
/** * Sorts the given file externally using the {@link #lexComparator} and removes duplicates. * * @param file file whose contents needs to be sorted */ public static void sort(File file) throws IOException { File sorted = createTempFile("fleioutilssort", null); merge(sortInBatch(file, lexComparator, true), sorted); move(sorted, file); }
/** * 文件移动/重命名. */ public static void moveFile(@NotNull File from, @NotNull File to) throws IOException { Validate.isTrue(isFileExists(from), from + " is not exist or not a file"); Validate.notNull(to); Validate.isTrue(!isDirExists(to), to + " is exist but it is a dir"); Files.move(from, to); }
@Override public void run() { File newFile = new File(parentDir, "fileRename-"+i.incrementAndGet()+".txt"); try { Files.move(file, newFile); } catch (IOException e) { throw Exceptions.propagate(e); } file = newFile; }})); }
private ArtifactFilesystem renameFileToSHA1Naming(final String tenant, final File file, final AbstractDbArtifact artifact) throws IOException { final File fileSHA1Naming = getFile(tenant, artifact.getHashes().getSha1()); if (fileSHA1Naming.exists()) { FileUtils.deleteQuietly(file); } else { Files.move(file, fileSHA1Naming); } return new ArtifactFilesystem(fileSHA1Naming, artifact.getArtifactId(), artifact.getHashes(), artifact.getSize(), artifact.getContentType()); }