use of java.nio.file.OpenOption in project wildfly-core by wildfly.
the class ServerConfigurator method appendConf.
private static void appendConf(final Path containerHome, final String baseName, final String envName) throws IOException {
// Add the local maven repository to the conf file
final String localRepo = System.getProperty("maven.repo.local");
if (localRepo != null) {
final Path binDir = containerHome.resolve("bin");
if (TestSuiteEnvironment.isWindows()) {
// Batch conf
Path conf = binDir.resolve(baseName + ".conf.bat");
OpenOption[] options;
if (Files.notExists(conf)) {
options = new OpenOption[] { StandardOpenOption.CREATE_NEW };
} else {
options = new OpenOption[] { StandardOpenOption.APPEND };
}
try (BufferedWriter writer = Files.newBufferedWriter(conf, options)) {
writer.newLine();
writer.write("set \"");
writer.write(envName);
writer.write("=-Dmaven.repo.local=");
writer.write(localRepo);
writer.write(" %");
writer.write(envName);
writer.write("%\"");
writer.newLine();
}
// Powershell conf
conf = binDir.resolve(baseName + ".conf.ps1");
if (Files.notExists(conf)) {
options = new OpenOption[] { StandardOpenOption.CREATE_NEW };
} else {
options = new OpenOption[] { StandardOpenOption.APPEND };
}
try (BufferedWriter writer = Files.newBufferedWriter(conf, options)) {
writer.newLine();
writer.write('$');
writer.write(envName);
writer.write(" += '-Dmaven.repo.local=");
writer.write(localRepo);
writer.write("'");
writer.newLine();
}
} else {
final Path conf = binDir.resolve(baseName + ".conf");
try (BufferedWriter writer = Files.newBufferedWriter(conf, StandardOpenOption.APPEND)) {
writer.newLine();
writer.write(envName);
writer.write("=\"-Dmaven.repo.local=");
writer.write(localRepo);
writer.write(" $");
writer.write(envName);
writer.write('"');
writer.newLine();
}
}
}
}
use of java.nio.file.OpenOption in project cyberduck by iterate-ch.
the class LocalWriteFeature method write.
@Override
public StatusOutputStream<Void> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
try {
final java.nio.file.Path p = session.toPath(file);
final Set<OpenOption> options = new HashSet<>();
options.add(StandardOpenOption.WRITE);
if (status.isAppend()) {
if (!status.isExists()) {
options.add(StandardOpenOption.CREATE);
}
} else {
if (status.isExists()) {
if (file.isSymbolicLink()) {
Files.delete(p);
options.add(StandardOpenOption.CREATE);
} else {
options.add(StandardOpenOption.TRUNCATE_EXISTING);
}
} else {
options.add(StandardOpenOption.CREATE_NEW);
}
}
final FileChannel channel = FileChannel.open(session.toPath(file), options.stream().toArray(OpenOption[]::new));
channel.position(status.getOffset());
return new VoidStatusOutputStream(Channels.newOutputStream(channel));
} catch (IOException e) {
throw new LocalExceptionMappingService().map("Upload {0} failed", e, file);
}
}
use of java.nio.file.OpenOption in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.
the class DataBufferUtils method write.
/**
* Write the given stream of {@link DataBuffer DataBuffers} to the given
* file {@link Path}. The optional {@code options} parameter specifies
* how the file is created or opened (defaults to
* {@link StandardOpenOption#CREATE CREATE},
* {@link StandardOpenOption#TRUNCATE_EXISTING TRUNCATE_EXISTING}, and
* {@link StandardOpenOption#WRITE WRITE}).
* @param source the stream of data buffers to be written
* @param destination the path to the file
* @param options the options specifying how the file is opened
* @return a {@link Mono} that indicates completion or error
* @since 5.2
*/
public static Mono<Void> write(Publisher<DataBuffer> source, Path destination, OpenOption... options) {
Assert.notNull(source, "Source must not be null");
Assert.notNull(destination, "Destination must not be null");
Set<OpenOption> optionSet = checkWriteOptions(options);
return Mono.create(sink -> {
try {
AsynchronousFileChannel channel = AsynchronousFileChannel.open(destination, optionSet, null);
sink.onDispose(() -> closeChannel(channel));
write(source, channel).subscribe(DataBufferUtils::release, sink::error, sink::success);
} catch (IOException ex) {
sink.error(ex);
}
});
}
use of java.nio.file.OpenOption in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.
the class DataBufferUtils method checkWriteOptions.
private static Set<OpenOption> checkWriteOptions(OpenOption[] options) {
int length = options.length;
Set<OpenOption> result = new HashSet<>(length + 3);
if (length == 0) {
result.add(StandardOpenOption.CREATE);
result.add(StandardOpenOption.TRUNCATE_EXISTING);
} else {
for (OpenOption opt : options) {
if (opt == StandardOpenOption.READ) {
throw new IllegalArgumentException("READ not allowed");
}
result.add(opt);
}
}
result.add(StandardOpenOption.WRITE);
return result;
}
use of java.nio.file.OpenOption in project spring-framework-debug by Joker-5.
the class DataBufferUtils method checkWriteOptions.
private static Set<OpenOption> checkWriteOptions(OpenOption[] options) {
int length = options.length;
Set<OpenOption> result = new HashSet<>(length + 3);
if (length == 0) {
result.add(StandardOpenOption.CREATE);
result.add(StandardOpenOption.TRUNCATE_EXISTING);
} else {
for (OpenOption opt : options) {
if (opt == StandardOpenOption.READ) {
throw new IllegalArgumentException("READ not allowed");
}
result.add(opt);
}
}
result.add(StandardOpenOption.WRITE);
return result;
}
Aggregations