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:nls.formacao.matriculador.descarregador.DesCarregadorFicheiro.java
@Override public void escrever(String info) { String nome = Utils.obtemNomeFicheiro("txt"); try {//from w ww. j a v a2 s . c om Path p = Paths.get(nome); Files.write(p, info.getBytes(Charset.forName("UTF-8")), StandardOpenOption.CREATE, StandardOpenOption.APPEND); } catch (IOException ex) { LOG.error("Erro a descarregar registos para o ecr.", ex); System.err.println("Erro a descarregar informao para o ecr."); } System.out.println(String.format("Criado o ficheiro %s.", nome)); }
From source file:org.roda.core.plugins.plugins.base.InventoryReportPluginUtils.java
public static void mergeFiles(List<Path> files, Path mergedFile) throws IOException { try (FileChannel out = FileChannel.open(mergedFile, StandardOpenOption.APPEND, StandardOpenOption.WRITE)) { for (Path path : files) { try (FileChannel in = FileChannel.open(path, StandardOpenOption.READ)) { for (long p = 0, l = in.size(); p < l;) p += in.transferTo(p, l - p, out); }//from w ww. j a v a 2s . co m } } catch (IOException e) { throw e; } }
From source file:org.roda.core.data.utils.JsonUtils.java
public static void appendObjectToFile(Object object, Path file) throws GenericException { try {// www . j av a2 s . c om String json = getJsonFromObject(object) + "\n"; Files.write(file, json.getBytes(), StandardOpenOption.APPEND); } catch (IOException e) { throw new GenericException("Error writing object, as json, to file", e); } }
From source file:eu.itesla_project.iidm.datasource.Bzip2FileDataSource.java
@Override public OutputStream newOutputStream(String suffix, String ext, boolean append) throws IOException { Path path = getPath(suffix, ext); OutputStream os = new BZip2CompressorOutputStream(new BufferedOutputStream( Files.newOutputStream(path, append ? StandardOpenOption.APPEND : StandardOpenOption.CREATE))); return observer != null ? new ObservableOutputStream(os, path.toString(), observer) : os; }
From source file:nls.formacao.matriculador.descarregador.DesCarregadorFicheiro.java
@Override public void escrever(Registo[] info) { String nomeFicheiro = Utils.obtemNomeFicheiro("txt"); for (Registo registo : info) { if (registo == null) { continue; }/*from w ww. ja v a 2s. c o m*/ try { Path p = Paths.get(nomeFicheiro); Files.write(p, registo.prettyPrint().getBytes(Charset.forName("UTF-8")), StandardOpenOption.CREATE, StandardOpenOption.APPEND); } catch (IOException ex) { LOG.error("Erro a descarregar registo para o ecr.", ex); System.err.println("Erro a descarregar registo para o ficheiro."); } } LOG.info(String.format("Informao descarregada com sucesso para o ficheiro '%s'", nomeFicheiro)); System.out.println(String.format("Criado o ficheiro %s.", nomeFicheiro)); }
From source file:org.apache.storm.metric.FileBasedEventLogger.java
private void initLogWriter(Path logFilePath) { try {/* w w w . j a v a 2 s . c om*/ LOG.info("Event log path {}", logFilePath); eventLogPath = logFilePath; eventLogWriter = Files.newBufferedWriter(eventLogPath, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.APPEND); } catch (IOException e) { LOG.error("Error setting up FileBasedEventLogger.", e); throw new RuntimeException(e); } }
From source file:fi.johannes.kata.ocr.utils.files.ExistingFileConnection.java
public void appendLines(List<String> lines) throws IOException { Files.write(p, lines, StandardOpenOption.APPEND); }
From source file:org.schedulesdirect.api.utils.HttpUtils.java
static public void captureToDisk(String msg) { Config conf = Config.get();//w ww. j a v a 2 s. co m if (conf.captureHttpComm()) { if (!auditSetup) setupAudit(); try { if (AUDIT_LOG != null) synchronized (HttpUtils.class) { Files.write(AUDIT_LOG, msg.getBytes("UTF-8"), StandardOpenOption.APPEND, StandardOpenOption.WRITE, StandardOpenOption.CREATE); } } catch (IOException e) { LOG.error("Unable to write capture file, logging at trace level instead!", e); LOG.trace(msg); } } }
From source file:fr.treeptik.cloudunit.config.Http401EntryPoint.java
public void generateLogTraceForFail2ban() { log.debug("generateLogTraceForFail2ban"); String filePath = "/var/log/culogin.log"; try {/* w w w .j av a 2s . c o m*/ Files.write(Paths.get(filePath), "Access Denied".getBytes(), StandardOpenOption.APPEND); Files.write(Paths.get(filePath), System.getProperty("line.separator").getBytes(), StandardOpenOption.APPEND); } catch (IOException e) { log.error("Cannot write to " + filePath + "", e.getMessage()); } }
From source file:com.surevine.gateway.scm.git.jgit.TestUtility.java
public static LocalRepoBean createTestRepoMultipleBranches() throws Exception { final String projectKey = "test_" + UUID.randomUUID().toString(); final String repoSlug = "testRepo"; final String remoteURL = "ssh://fake_url"; final Path repoPath = Paths.get(PropertyUtil.getGitDir(), "local_scm", projectKey, repoSlug); Files.createDirectories(repoPath); final Repository repo = new FileRepository(repoPath.resolve(".git").toFile()); repo.create();/*from w ww . j a v a 2s . c om*/ final StoredConfig config = repo.getConfig(); config.setString("remote", "origin", "url", remoteURL); config.save(); final LocalRepoBean repoBean = new LocalRepoBean(); repoBean.setProjectKey(projectKey); repoBean.setSlug(repoSlug); repoBean.setLocalBare(false); final Git git = new Git(repo); // add some files to some branches for (int i = 0; i < 3; i++) { final String filename = "newfile" + i + ".txt"; Files.write(repoPath.resolve(filename), Arrays.asList("Hello World"), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.APPEND); git.add().addFilepattern(filename).call(); git.commit().setMessage("Added " + filename).call(); } git.checkout().setName("branch1").setCreateBranch(true).call(); for (int i = 0; i < 3; i++) { final String filename = "branch1" + i + ".txt"; Files.write(repoPath.resolve(filename), Arrays.asList("Hello World"), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.APPEND); git.add().addFilepattern(filename).call(); git.commit().setMessage("Added " + filename).call(); } git.checkout().setName("master").call(); git.checkout().setName("branch2").setCreateBranch(true).call(); for (int i = 0; i < 3; i++) { final String filename = "branch2" + i + ".txt"; Files.write(repoPath.resolve(filename), Arrays.asList("Hello World"), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.APPEND); git.add().addFilepattern(filename).call(); git.commit().setMessage("Added " + filename).call(); } repo.close(); return repoBean; }