List of usage examples for java.nio.file StandardOpenOption APPEND
StandardOpenOption APPEND
To view the source code for java.nio.file StandardOpenOption APPEND.
Click Source Link
From source file:org.bonitasoft.web.designer.livebuild.WatcherTest.java
@Test public void should_trigger_a_modified_event_when_a_file_is_modified() throws Exception { Path existingFile = Files.createFile(subDirectory.resolve("file")); PathListenerStub listener = new PathListenerStub(); watcher.watch(folder.toPath(), listener); Files.write(existingFile, "hello".getBytes(), StandardOpenOption.APPEND); Thread.sleep(SLEEP_DELAY);// ww w . j a v a2 s. c om assertThat(listener.getChanged()).containsExactly(existingFile); }
From source file:org.jsontocsv.writer.CSVWriter.java
/** * Write the given CSV from a flat json to the given file. * //from w ww . j a v a 2s . c om * @param flatJson * @param separator * @param fileName * @param headers */ public static void writeLargeFile(List<Map<String, String>> flatJson, String separator, String fileName, Set<String> headers) { String csvString; csvString = StringUtils.join(headers.toArray(), separator) + "\n"; File file = new File(fileName); try { // ISO8859_1 char code to Latin alphabet FileUtils.write(file, csvString, "ISO8859_1"); for (Map<String, String> map : flatJson) { csvString = ""; csvString = getSeperatedColumns(headers, map, separator) + "\n"; Files.write(Paths.get(fileName), csvString.getBytes("ISO8859_1"), StandardOpenOption.APPEND); } } catch (IOException e) { LOGGER.error("CSVWriter#writeLargeFile(flatJson, separator, fileName, headers) IOException: ", e); } }
From source file:org.apache.pulsar.io.file.TestFileGenerator.java
private final void createFile() { try {/* w w w . j av a 2 s.c o m*/ Path path = Files.createTempFile(tempDir, prefix, suffix, attrs); try (OutputStream out = Files.newOutputStream(path, StandardOpenOption.APPEND)) { for (int idx = 0; idx < numLines; idx++) { IOUtils.write(RandomStringUtils.random(50, true, false) + "\n", out, "UTF-8"); } } producedFiles.put(path.toFile()); } catch (IOException | InterruptedException e) { e.printStackTrace(); } }
From source file:net.sf.jclal.listener.RealScenarioListener.java
/** * {@inheritDoc}/* w w w.ja v a 2s . co m*/ */ @Override public void algorithmStarted(AlgorithmEvent event) { super.algorithmStarted(event); in = new BufferedReader(new InputStreamReader(System.in)); if (getInformativeInstances() == null || getInformativeInstances().isEmpty()) { setInformativeInstances(newInformativeInstances()); } File keep = new File(getInformativeInstances()); keep.getParentFile().mkdirs(); try { writer = Files.newBufferedWriter(new File(getInformativeInstances()).toPath(), Charset.defaultCharset(), StandardOpenOption.CREATE, StandardOpenOption.APPEND); } catch (IOException ex) { Logger.getLogger(RealScenarioListener.class.getName()).log(Level.SEVERE, null, ex); } /////////////////////////////////// System.out.println( "\nWelcome to the real scenario listener. You can use it to obtain the most informative unlabeled data." + "\nAt the end of this session you can save the labeled data for further analysis." + "\nYou must specify in the configuration file the parameter <informative-instances> for setting the path where the " + "instances that were labeled will be saved." + "\nThis example of real-world use can be combined with a simulated or a human oracle." + "\nThe labeled instances will be stored sequentially in: " + getInformativeInstances() + "." + "\nIf you are ready to begin please press <enter>."); readLine(); System.out.println("Active Learning begins..."); }
From source file:com.liferay.ide.gradle.core.GradleProjectBuilder.java
public IStatus initBundle(IProject project, String bundleUrl, IProgressMonitor monitor) throws CoreException { String bundleUrlProperty = "\n\n" + LiferayWorkspaceUtil.LIFERAY_WORKSPACE_BUNDLE_URL + "=" + bundleUrl; IPath gradlePropertiesLocation = project.getFile("gradle.properties").getLocation(); File gradlePropertiesFile = gradlePropertiesLocation.toFile(); try {//from w ww.j av a 2s .c o m Files.write(gradlePropertiesFile.toPath(), bundleUrlProperty.getBytes(), StandardOpenOption.APPEND); } catch (IOException ioe) { GradleCore.logError("Error append bundle url property", ioe); } _runGradleTask("initBundle", monitor); project.refreshLocal(IResource.DEPTH_INFINITE, monitor); return Status.OK_STATUS; }
From source file:wso2.sample.SampleScheduledTask.java
public void execute() { try {/*from w w w .j av a 2 s . c om*/ Files.write(Paths.get("/Users/sewmini/Desktop/INABOXGROUPDEV-36/text.log"), ("param1: " + param1 + "," + " param2: " + param2 + "\n").getBytes(), StandardOpenOption.APPEND); } catch (IOException e) { log.error(e); } }
From source file:org.reactor.monitoring.util.FileHandler.java
public static void createAndUpdateFile(final boolean replaceFile, final String fileLocation, final String output) { try {/* w w w . j a va2s .c o m*/ Path path = Paths.get(fileLocation); Path parentDir = path.getParent(); if (!Files.exists(parentDir)) { Files.createDirectories(parentDir); } if (!Files.exists(path, LinkOption.NOFOLLOW_LINKS)) { Files.createFile(path); } else if (replaceFile) { Files.delete(path); Files.createFile(path); } Files.write(path, output.getBytes(), StandardOpenOption.APPEND); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:ru.xxlabaza.csv.merger.Main.java
@SneakyThrows private static void writeIntersections(Path resultFile, Map<String, List<String>> first, Map<String, List<String>> second) { val toWrite = first.entrySet().stream().filter(entry -> { return second.containsKey(entry.getKey()); }).flatMap(entry -> {/*w w w . ja v a 2 s . co m*/ return entry.getValue().stream().flatMap(firstValue -> { return second.get(entry.getKey()).stream().map(secondValue -> { return new StringBuilder().append(entry.getKey()).append(',').append(firstValue).append(',') .append(secondValue).toString(); }); }); }).collect(toList()); Files.write(resultFile, toWrite, StandardOpenOption.APPEND); }
From source file:org.geppetto.persistence.s3.S3Manager.java
public void saveTextToS3(String text, String path) throws IOException { File file = File.createTempFile("file", ""); Files.write(file.toPath(), text.getBytes(), StandardOpenOption.APPEND); saveFileToS3(file, path);// w w w . ja v a2 s. com }
From source file:com.vaushell.superpipes.transforms.done.T_Done.java
@Override public Message transform(final Message message) throws Exception { if (LOGGER.isTraceEnabled()) { LOGGER.trace("[" + getNode().getNodeID() + "/" + getClass().getSimpleName() + "] transform message : " + Message.formatSimple(message)); }/*from w w w.j a v a 2s . c o m*/ final String ID = buildID(message, fields); if (ids.contains(ID)) { return null; } // Save message ID. Won't be replay ids.add(ID); try (final BufferedWriter bfw = Files.newBufferedWriter(path, Charset.forName("utf-8"), StandardOpenOption.APPEND, StandardOpenOption.CREATE)) { bfw.write(ID); bfw.write(' '); bfw.write(Message.formatSimple(message)); bfw.newLine(); } return message; }