List of usage examples for java.nio.file StandardOpenOption CREATE
StandardOpenOption CREATE
To view the source code for java.nio.file StandardOpenOption CREATE.
Click Source Link
From source file:it.greenvulcano.configuration.BaseConfigurationManager.java
@Override public void install(String name, byte[] archive) throws IOException { Path configurationPath = getConfigurationPath(name); try (ZipInputStream zipArchive = new ZipInputStream(new ByteArrayInputStream(archive))) { if (zipArchive.getNextEntry() != null) { Files.write(configurationPath, archive, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); } else {// w w w.j a v a 2s .c om throw new IOException("Empty or invalid zip archive"); } } }
From source file:org.cryptomator.webdav.jackrabbit.DavLocatorFactoryImpl.java
@Override public void writePathSpecificMetadata(String encryptedPath, byte[] encryptedMetadata) throws IOException { final Path metaDataFile = fsRoot.resolve(encryptedPath); Files.write(metaDataFile, encryptedMetadata, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.DSYNC); }
From source file:com.surevine.gateway.scm.git.jgit.TestUtility.java
public static LocalRepoBean createTestRepo() 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();// w w w .jav a2 s.com 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); repoBean.setSourcePartner("partner"); final Git git = new Git(repo); 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("master").call(); repo.close(); return repoBean; }
From source file:edu.cmu.tetrad.cli.AbstractAlgorithmCli.java
@Override public void run() { AlgorithmType algorithmType = getAlgorithmType(); if (needsToShowHelp()) { showHelp(algorithmType.getCmd()); return;//from www . j av a2 s .c o m } parseOptions(); String heading = creteHeading(algorithmType); String argInfo = createArgsInfo(); System.out.printf(heading); System.out.println(argInfo); LOGGER.info(String.format("=== Starting %s: %s", algorithmType.getTitle(), Args.toString(args, ' '))); LOGGER.info(argInfo.trim().replaceAll("\n", ",").replaceAll(" = ", "=")); if (!skipLatest) { LatestClient latestClient = LatestClient.getInstance(); String version = AppTool.jarVersion(); if (version == null) version = "DEVELOPMENT"; latestClient.checkLatest("causal-cmd", version); System.out.println(latestClient.getLatestResult()); } Set<String> excludedVariables = getExcludedVariables(); runPreDataValidations(excludedVariables); DataSet dataSet = AlgorithmCommonTask.readInDataSet(excludedVariables, dataFile, getDataReader(dataFile, delimiter)); runDataValidations(dataSet); IKnowledge knowledge = AlgorithmCommonTask.readInPriorKnowledge(knowledgeFile); Path outputFile = Paths.get(dirOut.toString(), outputPrefix + ".txt"); try (PrintStream writer = new PrintStream( new BufferedOutputStream(Files.newOutputStream(outputFile, StandardOpenOption.CREATE)))) { writer.println(heading); writer.println(createRunInfo(excludedVariables, dataSet)); Algorithm algorithm = getAlgorithm(knowledge); Parameters parameters = getParameters(); if (verbose) { parameters.set(ParamAttrs.PRINT_STREAM, writer); } Graph graph = search(dataSet, algorithm, parameters); writer.println(); writer.println(graph.toString()); if (isSerializeJson) { writeOutJson(outputPrefix, graph, Paths.get(dirOut.toString(), outputPrefix + "_graph.json")); } if (tetradGraphJson) { writeOutTetradGraphJson(graph, Paths.get(dirOut.toString(), outputPrefix + ".json")); } } catch (Exception exception) { LOGGER.error("Run algorithm failed.", exception); System.exit(-128); } }
From source file:com.ontotext.s4.service.S4ServiceClientIntegrationTest.java
@Test public void testClassifyFileContentsDescClient() throws Exception { ServiceDescriptor temp = ServicesCatalog.getItem("news-classifier"); S4ServiceClient client = new S4ServiceClient(temp, testApiKeyId, testApiKeyPass); File f = new File("test-file"); try {// w w w . j av a 2 s. co m Path p = f.toPath(); ArrayList<String> lines = new ArrayList<>(1); lines.add(documentText); Files.write(p, lines, Charset.forName("UTF-8"), StandardOpenOption.CREATE); ClassifiedDocument result = client.classifyFileContents(f, Charset.forName("UTF-8"), documentMimeType); assertNotNull(result.getCategory()); assertEquals(3, result.getAllScores().size()); } finally { f.delete(); } }
From source file:io.apiman.common.es.util.ApimanEmbeddedElastic.java
private void writeProcessId() throws IOException { try {/*from w w w .j a va2 s . co m*/ // Create parent directory (i.e. ~/.cache/apiman/es-pid-{identifier}) Files.createDirectories(pidPath.getParent()); // Get the elasticServer instance variable Field elasticServerField = elastic.getClass().getDeclaredField("elasticServer"); elasticServerField.setAccessible(true); Object elasticServerInstance = elasticServerField.get(elastic); // ElasticServer package-scoped so we can't get the real type. // Get the process ID (pid) long field from ElasticServer Field pidField = elasticServerInstance.getClass().getDeclaredField("pid"); pidField.setAccessible(true); pid = (int) pidField.get(elasticServerInstance); // Get the pid // Write to the PID file Files.write(pidPath, String.valueOf(pid).getBytes(), StandardOpenOption.CREATE, StandardOpenOption.APPEND); } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { throw new RuntimeException(e); } }
From source file:neembuu.uploader.v2tov3conversion.ConvertUploaderClass.java
public void writeTo(Path out) throws IOException { Files.write(out, out_lines, Charset.defaultCharset(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE); }
From source file:de.tuberlin.uebb.jbop.access.ClassAccessor.java
/** * Stores a classfile for the given Classdescriptor. * /* w w w .j a va 2 s. co m*/ * The Class for the File could be loaded with the ClassLoader proposed by this * Class ({@link #getClassloader()}) or any suitable ClassLoader using the returned * Path of the Classfile. * * @param classDescriptor * the class descriptor * @return the path of the written File * @throws JBOPClassException * the jBOP class exception */ public static Path store(final ClassDescriptor classDescriptor) throws JBOPClassException { final Path packageDir = Paths.get(TMP_DIR.toString(), classDescriptor.getPackageDir()); final Path classFile = Paths.get(packageDir.toString(), classDescriptor.getSimpleName() + ".class"); try { Files.createDirectories(packageDir); Files.write(classFile, classDescriptor.getClassData(), StandardOpenOption.CREATE, StandardOpenOption.WRITE); classDescriptor.setFile(classFile.toString()); return classFile; } catch (final IOException e) { throw new JBOPClassException( "Data of Class " + classDescriptor.getName() + " could not be written to file.", e); } }
From source file:org.ulyssis.ipp.reader.Reader.java
/** * Create a new reader and connect to Redis. * //from www . j av a 2s . c o m * options are passed in, rather than * accessed through a singleton or such, to improve testability * and modularity, and to prevent hidden dependencies and * eventual threading issues. * * @param options * The command line options to use for this reader. */ public Reader(ReaderOptions options) { this.options = options; this.readerConfig = Config.getCurrentConfig().getReader(options.getId()); this.llrpReader = new LLRPReader(this::messageReceived, this::errorOccurred); if (readerConfig.getType() == ReaderConfig.Type.SIMULATOR) { executorService = Executors.newSingleThreadScheduledExecutor(); } else { executorService = null; } if (options.getNoRedis()) { LOG.info("Not using Redis, setting initial update count to 0."); this.updateCount = 0L; this.jedis = null; } else { this.jedis = JedisHelper.get(readerConfig.getURI()); try { this.updateCount = jedis.llen("updates"); } catch (JedisConnectionException e) { LOG.error("Couldn't connect to Jedis when getting update count. Setting 0 instead.", e); this.updateCount = 0L; // TODO: Is 0 appropriate? } } String statusChannel = Config.getCurrentConfig().getStatusChannel(); this.statusReporter = new StatusReporter(readerConfig.getURI(), statusChannel); String controlChannel = Config.getCurrentConfig().getControlChannel(); this.commandProcessor = new CommandProcessor(readerConfig.getURI(), controlChannel, statusReporter); commandProcessor.addHandler(new PingHandler()); this.updateChannel = JedisHelper.dbLocalChannel(Config.getCurrentConfig().getUpdateChannel(), readerConfig.getURI()); options.getReplayFile().ifPresent(replayFile -> { try { LOG.info("Opening replay file: {}", replayFile); ByteChannel channel = Files.newByteChannel(replayFile, StandardOpenOption.APPEND, StandardOpenOption.CREATE); this.replayChannel = Optional.of(channel); } catch (IOException e) { LOG.error("Couldn't open channel for logging to replay file: {}", replayFile, e); } }); this.lastUpdateForTag = new HashMap<>(); }
From source file:net.di2e.ecdr.describe.commands.GenerateDescribeCommand.java
protected void writeToFile(String sourceId, String xml) { try {/*from ww w . j av a 2 s. c o m*/ String filename = sourceId + "-describe-" + (System.currentTimeMillis() / 1000) + ".xml"; Files.write(Paths.get(DESCRIBE_DIR, filename), xml.getBytes(), StandardOpenOption.CREATE); console.println("New describe file written to DDF_HOME/" + DESCRIBE_DIR + ": " + filename); } catch (IOException e) { LOGGER.error("Could not write describe file for source {}", sourceId, e); } }