List of usage examples for java.nio.file StandardOpenOption WRITE
StandardOpenOption WRITE
To view the source code for java.nio.file StandardOpenOption WRITE.
Click Source Link
From source file:org.jboss.jbossset.JiraReporterTest.java
@BeforeClass public static void init() throws Exception { List<String> users = new ArrayList<>(); for (int i = 0; i < NUMBER_OF_USERS; i++) users.add("user" + i); Files.write(Paths.get("", USERS_FILE_URL), users, StandardOpenOption.CREATE, StandardOpenOption.WRITE); Properties p = new Properties(); p.put("JIRA", "https://issues.jboss.org"); p.store(new PrintWriter(new File(DOMAIN_FILE_URL)), null); }
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); }/* w w w . j a va 2 s .c o m*/ } } catch (IOException e) { throw e; } }
From source file:net.radai.confusion.spring.SpringAnnotationConfigTest.java
@Test public void testSpringAnnotationIntegration() throws Exception { Path dir = Files.createTempDirectory("test"); Path targetFile = dir.resolve("confFile"); try (InputStream is = getClass().getClassLoader().getResourceAsStream("cats.ini"); OutputStream os = Files.newOutputStream(targetFile, StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW)) { ByteStreams.copy(is, os);/* w ww . j av a 2 s. com*/ } String absolutePath = targetFile.toFile().getCanonicalPath(); System.setProperty("confFile", absolutePath); ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("annotationSpringContext.xml"); //noinspection unchecked SpringAwareConfigurationService<Cats> confService = (SpringAwareConfigurationService<Cats>) context .getBean(ConfigurationService.class); Jsr330AnnotatedConfigurationConsumerBean consumer = context .getBean(Jsr330AnnotatedConfigurationConsumerBean.class); //noinspection unchecked Assert.assertNotNull(consumer.getConfService()); Assert.assertNotNull(consumer.getInitialConf()); Assert.assertTrue(consumer.getCats().isEmpty()); try (InputStream is = getClass().getClassLoader().getResourceAsStream("cat.ini"); OutputStream os = Files.newOutputStream(targetFile, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)) { ByteStreams.copy(is, os); } Thread.sleep(100); //verify event was received Assert.assertEquals(1, consumer.getCats().size()); Assert.assertTrue(consumer.getInitialConf() != consumer.getCats().get(0)); Assert.assertTrue(confService.getConfiguration() == consumer.getCats().get(0)); context.close(); }
From source file:io.druid.segment.writeout.TmpFileSegmentWriteOutMedium.java
@Override public WriteOutBytes makeWriteOutBytes() throws IOException { File file = File.createTempFile("filePeon", null, dir); FileChannel ch = FileChannel.open(file.toPath(), StandardOpenOption.READ, StandardOpenOption.WRITE); closer.register(file::delete);//from www . j ava 2 s. c o m closer.register(ch); return new FileWriteOutBytes(file, ch); }
From source file:net.radai.confusion.spring.SpringXmlConfTest.java
@Test public void testSpringXmlIntegration() throws Exception { Path dir = Files.createTempDirectory("test"); Path targetFile = dir.resolve("confFile"); try (InputStream is = getClass().getClassLoader().getResourceAsStream("cats.ini"); OutputStream os = Files.newOutputStream(targetFile, StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW)) { ByteStreams.copy(is, os);// w w w. ja v a2s .c om } String absolutePath = targetFile.toFile().getCanonicalPath(); System.setProperty("confFile", absolutePath); ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("xmlSpringContext.xml"); //noinspection unchecked SpringAwareConfigurationService<Cats> confService = (SpringAwareConfigurationService<Cats>) context .getBean(ConfigurationService.class); TraditionalConfigurationConsumerBean consumer = context.getBean(TraditionalConfigurationConsumerBean.class); //noinspection unchecked SimpleConfigurationService<Cats> delegate = (SimpleConfigurationService<Cats>) ReflectionTestUtils .getField(confService, "delegate"); Assert.assertNotNull(confService.getConfiguration()); Assert.assertTrue(delegate.isStarted()); Assert.assertTrue(consumer.getConf() == confService.getConfiguration()); Assert.assertTrue(consumer.getConfService() == confService); Assert.assertTrue(consumer.getCats().isEmpty()); try (InputStream is = getClass().getClassLoader().getResourceAsStream("cat.ini"); OutputStream os = Files.newOutputStream(targetFile, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)) { ByteStreams.copy(is, os); } Thread.sleep(100); //verify event was received Assert.assertEquals(1, consumer.getCats().size()); Assert.assertTrue(consumer.getConf() != consumer.getCats().get(0)); Assert.assertTrue(confService.getConfiguration() == consumer.getCats().get(0)); context.close(); Assert.assertFalse(delegate.isStarted()); }
From source file:net.minecrell.serverlistplus.canary.SnakeYAML.java
@SneakyThrows public static void load(Plugin plugin) { try { // Check if it is already loaded Class.forName("org.yaml.snakeyaml.Yaml"); return;/*from w w w .j a v a2 s . co m*/ } catch (ClassNotFoundException ignored) { } Path path = Paths.get("lib", SNAKE_YAML_JAR); if (Files.notExists(path)) { Files.createDirectories(path.getParent()); plugin.getLogman().info("Downloading SnakeYAML..."); URL url = new URL(SNAKE_YAML); MessageDigest sha1 = MessageDigest.getInstance("SHA-1"); try (ReadableByteChannel source = Channels.newChannel(new DigestInputStream(url.openStream(), sha1)); FileChannel out = FileChannel.open(path, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)) { out.transferFrom(source, 0, Long.MAX_VALUE); } if (!new String(Hex.encodeHex(sha1.digest())).equals(EXPECTED_HASH)) { Files.delete(path); throw new IllegalStateException( "Downloaded SnakeYAML, but checksum check failed. Please try again later."); } plugin.getLogman().info("Successfully downloaded!"); } loadJAR(path); }
From source file:org.schedulesdirect.grabber.ScheduleTask.java
static void commit(FileSystem vfs) throws IOException { Iterator<String> itr = FULL_SCHEDS.keySet().iterator(); while (itr.hasNext()) { String id = itr.next();//from w ww.j a v a 2 s . c om JSONObject sched = new JSONObject(); List<JSONObject> airs = FULL_SCHEDS.get(id); Collections.sort(airs, new Comparator<JSONObject>() { @Override public int compare(JSONObject arg0, JSONObject arg1) { return arg0.getString("airDateTime").compareTo(arg1.getString("airDateTime")); } }); sched.put("programs", airs); Path p = vfs.getPath("schedules", String.format("%s.txt", id)); Files.write(p, sched.toString(3).getBytes(ZipEpgClient.ZIP_CHARSET), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE); } FULL_SCHEDS.clear(); }
From source file:org.apache.storm.metric.FileBasedEventLogger.java
private void initLogWriter(Path logFilePath) { try {//w w w. java 2 s.c o m 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:org.cryptomator.ui.settings.Settings.java
public static synchronized void save() { if (INSTANCE != null) { try {/*from ww w . j av a 2 s .co m*/ Files.createDirectories(SETTINGS_DIR); final Path settingsFile = SETTINGS_DIR.resolve(SETTINGS_FILE); final OutputStream out = Files.newOutputStream(settingsFile, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE); JSON_OM.writeValue(out, INSTANCE); } catch (IOException e) { LOG.error("Failed to save settings.", e); } } }
From source file:com.spectralogic.ds3client.helpers.FileObjectPutter_Test.java
/** * This test cannot run on Windows without extra privileges *///from w w w . j av a 2s . c o m @Test public void testSymlink() throws IOException { assumeFalse(Platform.isWindows()); final Path tempDir = Files.createTempDirectory("ds3_file_object_putter_"); final Path tempPath = Files.createTempFile(tempDir, "temp_", ".txt"); try { try (final SeekableByteChannel channel = Files.newByteChannel(tempPath, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) { channel.write(ByteBuffer.wrap(testData)); } final Path symLinkPath = tempDir.resolve("sym_" + tempPath.getFileName().toString()); Files.createSymbolicLink(symLinkPath, tempPath); getFileWithPutter(tempDir, symLinkPath); } finally { Files.deleteIfExists(tempPath); Files.deleteIfExists(tempDir); } }