use of java.nio.file.OpenOption in project fastr by oracle.
the class RCompression method bzipCompressToFile.
public static void bzipCompressToFile(byte[] data, TruffleFile path, boolean append) throws IOException {
String[] command = new String[] { "bzip2", "-zc" };
int rc;
ProcessBuilder pb = new ProcessBuilder(command);
pb.redirectError(Redirect.INHERIT);
Process p = pb.start();
InputStream is = p.getInputStream();
OutputStream os = p.getOutputStream();
ProcessOutputManager.OutputThreadVariable readThread = new ProcessOutputManager.OutputThreadVariable(command[0], is);
readThread.start();
os.write(data);
os.close();
try {
rc = p.waitFor();
if (rc == 0) {
readThread.join();
byte[] cData = Arrays.copyOf(readThread.getData(), readThread.getTotalRead());
OpenOption[] openOptions = append ? new OpenOption[] { StandardOpenOption.APPEND } : new OpenOption[0];
path.newOutputStream(openOptions).write(cData);
return;
} else {
throw new IOException("bzip2 error code: " + rc);
}
} catch (InterruptedException ex) {
// fall through
}
throw new IOException();
}
use of java.nio.file.OpenOption in project SchemaCrawler by schemacrawler.
the class FileOutputResource method openNewOutputWriter.
@Override
public Writer openNewOutputWriter(final Charset charset, final boolean appendOutput) throws IOException {
requireNonNull(charset, "No output charset provided");
final OpenOption[] openOptions;
if (appendOutput) {
openOptions = new OpenOption[] { WRITE, CREATE, APPEND };
} else {
openOptions = new OpenOption[] { WRITE, CREATE, TRUNCATE_EXISTING };
}
final Writer writer = newBufferedWriter(outputFile, charset, openOptions);
LOGGER.log(Level.FINE, new StringFormat("Opened output writer to file <%s>", outputFile));
return wrapWriter(getDescription(), writer, true);
}
use of java.nio.file.OpenOption in project quilt-loader by QuiltMC.
the class QuiltJoinedFileSystemProvider method newByteChannel.
@Override
public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException {
for (OpenOption o : options) {
if (o != StandardOpenOption.READ) {
throw new UnsupportedOperationException("'" + o + "' not allowed");
}
}
if (!(path instanceof QuiltJoinedPath)) {
throw new IllegalArgumentException("The given path is not a QuiltJoinedPath!");
}
QuiltJoinedPath p = (QuiltJoinedPath) path;
int count = p.fs.getBackingPathCount();
for (int i = 0; i < count; i++) {
Path real = p.fs.getBackingPath(i, p);
try {
return Files.newByteChannel(real, options, attrs);
} catch (NoSuchFileException e) {
if (i == count - 1) {
throw e;
}
}
}
throw new NoSuchFileException(path.toString());
}
use of java.nio.file.OpenOption in project quilt-loader by QuiltMC.
the class QuiltMemoryFileSystemProvider method newInputStream.
@Override
public InputStream newInputStream(Path path, OpenOption... options) throws IOException {
for (OpenOption o : options) {
if (o != StandardOpenOption.READ) {
throw new UnsupportedOperationException("'" + o + "' not allowed");
}
}
if (path instanceof QuiltMemoryPath) {
QuiltMemoryPath p = (QuiltMemoryPath) path;
QuiltMemoryEntry entry = p.fs.files.get(p.toAbsolutePath().normalize());
if (entry instanceof QuiltMemoryFile) {
return ((QuiltMemoryFile) entry).createInputStream();
} else if (entry != null) {
throw new FileSystemException("Cannot open an InputStream on a directory!");
} else {
throw new NoSuchFileException(path.toString());
}
} else {
throw new IllegalArgumentException("The given path is not a QuiltMemoryPath!");
}
}
use of java.nio.file.OpenOption in project mina-sshd by apache.
the class ScpHelper method receiveFileStream.
public void receiveFileStream(OutputStream local, int bufferSize) throws IOException {
receive((session, line, isDir, timestamp) -> {
if (isDir) {
throw new StreamCorruptedException("Cannot download a directory into a file stream: " + line);
}
Path path = new MockPath(line);
receiveStream(line, new ScpTargetStreamResolver() {
@Override
// see
@SuppressWarnings("synthetic-access")
public // https://bugs.eclipse.org/bugs/show_bug.cgi?id=537593
OutputStream resolveTargetStream(Session session, String name, long length, Set<PosixFilePermission> perms, OpenOption... options) throws IOException {
if (log.isDebugEnabled()) {
log.debug("resolveTargetStream({}) name={}, perms={}, len={} - started local stream download", ScpHelper.this, name, perms, length);
}
return local;
}
@Override
public Path getEventListenerFilePath() {
return path;
}
@Override
// see
@SuppressWarnings("synthetic-access")
public // https://bugs.eclipse.org/bugs/show_bug.cgi?id=537593
void postProcessReceivedData(String name, boolean preserve, Set<PosixFilePermission> perms, ScpTimestampCommandDetails time) throws IOException {
if (log.isDebugEnabled()) {
log.debug("postProcessReceivedData({}) name={}, perms={}, preserve={} time={}", ScpHelper.this, name, perms, preserve, time);
}
}
@Override
public String toString() {
return line;
}
}, timestamp, false, bufferSize);
});
}
Aggregations