Search in sources :

Example 26 with OpenOption

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();
            }
        }
    }
}
Also used : Path(java.nio.file.Path) OpenOption(java.nio.file.OpenOption) StandardOpenOption(java.nio.file.StandardOpenOption) BufferedWriter(java.io.BufferedWriter)

Example 27 with OpenOption

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);
    }
}
Also used : OpenOption(java.nio.file.OpenOption) StandardOpenOption(java.nio.file.StandardOpenOption) VoidStatusOutputStream(ch.cyberduck.core.io.VoidStatusOutputStream) FileChannel(java.nio.channels.FileChannel) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 28 with OpenOption

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);
        }
    });
}
Also used : AsynchronousFileChannel(java.nio.channels.AsynchronousFileChannel) OpenOption(java.nio.file.OpenOption) StandardOpenOption(java.nio.file.StandardOpenOption) IOException(java.io.IOException)

Example 29 with OpenOption

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;
}
Also used : OpenOption(java.nio.file.OpenOption) StandardOpenOption(java.nio.file.StandardOpenOption) HashSet(java.util.HashSet)

Example 30 with OpenOption

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;
}
Also used : OpenOption(java.nio.file.OpenOption) StandardOpenOption(java.nio.file.StandardOpenOption) HashSet(java.util.HashSet)

Aggregations

OpenOption (java.nio.file.OpenOption)99 StandardOpenOption (java.nio.file.StandardOpenOption)73 IOException (java.io.IOException)40 HashSet (java.util.HashSet)32 Path (java.nio.file.Path)30 File (java.io.File)19 FileChannel (java.nio.channels.FileChannel)18 Test (org.junit.Test)18 NoSuchFileException (java.nio.file.NoSuchFileException)16 OutputStream (java.io.OutputStream)12 ArrayList (java.util.ArrayList)11 InputStream (java.io.InputStream)10 SeekableByteChannel (java.nio.channels.SeekableByteChannel)10 FileIO (org.apache.ignite.internal.processors.cache.persistence.file.FileIO)10 FileIODecorator (org.apache.ignite.internal.processors.cache.persistence.file.FileIODecorator)10 ByteBuffer (java.nio.ByteBuffer)9 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)9 FileIOFactory (org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory)8 RandomAccessFileIOFactory (org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory)8 Set (java.util.Set)7