use of io.vertx.core.file.OpenOptions in project vert.x by eclipse.
the class HttpServerFileUploadImpl method streamToFileSystem.
@Override
public HttpServerFileUpload streamToFileSystem(String filename) {
pause();
vertx.fileSystem().open(filename, new OpenOptions(), ar -> {
if (ar.succeeded()) {
file = ar.result();
Pump p = Pump.pump(HttpServerFileUploadImpl.this, ar.result());
p.start();
resume();
} else {
notifyExceptionHandler(ar.cause());
}
});
return this;
}
use of io.vertx.core.file.OpenOptions in project vert.x by eclipse.
the class FileSystemExamples method asyncFileWrite.
public void asyncFileWrite() {
Vertx vertx = Vertx.vertx();
vertx.fileSystem().open("target/classes/hello.txt", new OpenOptions(), result -> {
if (result.succeeded()) {
AsyncFile file = result.result();
Buffer buff = Buffer.buffer("foo");
for (int i = 0; i < 5; i++) {
file.write(buff, buff.length() * i, ar -> {
if (ar.succeeded()) {
System.out.println("Written ok!");
} else {
System.err.println("Failed to write: " + ar.cause());
}
});
}
} else {
System.err.println("Cannot open file " + result.cause());
}
});
}
use of io.vertx.core.file.OpenOptions in project vert.x by eclipse.
the class FileSystemTest method testIllegalArguments.
@Test
public void testIllegalArguments() throws Exception {
assertNullPointerException(() -> vertx.fileSystem().copy(null, "ignored", h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().copy("ignored", null, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().copyBlocking(null, "ignored"));
assertNullPointerException(() -> vertx.fileSystem().copyBlocking("ignored", null));
assertNullPointerException(() -> vertx.fileSystem().copyRecursive(null, "ignored", true, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().copyRecursive("ignored", null, true, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().copyRecursiveBlocking(null, "ignored", true));
assertNullPointerException(() -> vertx.fileSystem().copyRecursiveBlocking("ignored", null, true));
assertNullPointerException(() -> vertx.fileSystem().move(null, "ignored", h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().move("ignored", null, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().moveBlocking(null, "ignored"));
assertNullPointerException(() -> vertx.fileSystem().moveBlocking("ignored", null));
assertNullPointerException(() -> vertx.fileSystem().truncate(null, 0, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().truncateBlocking(null, 0));
assertNullPointerException(() -> vertx.fileSystem().chmod(null, "ignored", h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().chmod("ignored", null, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().chmodBlocking(null, "ignored"));
assertNullPointerException(() -> vertx.fileSystem().chmodBlocking("ignored", null));
assertNullPointerException(() -> vertx.fileSystem().chmodRecursive(null, "ignored", "ignored", h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().chmodRecursive("ignored", null, "ignored", h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().chmodRecursiveBlocking(null, "ignored", "ignored"));
assertNullPointerException(() -> vertx.fileSystem().chmodRecursiveBlocking("ignored", null, "ignored"));
assertNullPointerException(() -> vertx.fileSystem().chown(null, "ignored", "ignored", h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().chownBlocking(null, "ignored", "ignored"));
assertNullPointerException(() -> vertx.fileSystem().props(null, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().propsBlocking(null));
assertNullPointerException(() -> vertx.fileSystem().lprops(null, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().lpropsBlocking(null));
assertNullPointerException(() -> vertx.fileSystem().link(null, "ignored", h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().link("ignored", null, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().linkBlocking(null, "ignored"));
assertNullPointerException(() -> vertx.fileSystem().linkBlocking("ignored", null));
assertNullPointerException(() -> vertx.fileSystem().symlink(null, "ignored", h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().symlink("ignored", null, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().symlinkBlocking(null, "ignored"));
assertNullPointerException(() -> vertx.fileSystem().symlinkBlocking("ignored", null));
assertNullPointerException(() -> vertx.fileSystem().unlink(null, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().unlinkBlocking(null));
assertNullPointerException(() -> vertx.fileSystem().readSymlink(null, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().readSymlinkBlocking(null));
assertNullPointerException(() -> vertx.fileSystem().delete(null, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().deleteBlocking(null));
assertNullPointerException(() -> vertx.fileSystem().deleteRecursive(null, true, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().deleteRecursiveBlocking(null, true));
assertNullPointerException(() -> vertx.fileSystem().mkdir(null, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().mkdirBlocking(null));
assertNullPointerException(() -> vertx.fileSystem().mkdir(null, "ignored", h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().mkdirBlocking(null, "ignored"));
assertNullPointerException(() -> vertx.fileSystem().mkdirs(null, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().mkdirsBlocking(null));
assertNullPointerException(() -> vertx.fileSystem().mkdirs(null, "ignored", h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().mkdirsBlocking(null, "ignored"));
assertNullPointerException(() -> vertx.fileSystem().readDir(null, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().readDirBlocking(null));
assertNullPointerException(() -> vertx.fileSystem().readDir(null, "ignored", h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().readDirBlocking(null, "ignored"));
assertNullPointerException(() -> vertx.fileSystem().readFile(null, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().readFileBlocking(null));
assertNullPointerException(() -> vertx.fileSystem().writeFile(null, Buffer.buffer(), h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().writeFile("ignored", null, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().writeFileBlocking(null, Buffer.buffer()));
assertNullPointerException(() -> vertx.fileSystem().writeFileBlocking("ignored", null));
assertNullPointerException(() -> vertx.fileSystem().open(null, new OpenOptions(), h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().open("ignored", null, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().openBlocking(null, new OpenOptions()));
assertNullPointerException(() -> vertx.fileSystem().openBlocking("ignored", null));
assertNullPointerException(() -> vertx.fileSystem().createFile(null, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().createFileBlocking(null));
assertNullPointerException(() -> vertx.fileSystem().createFile(null, "ignored", h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().createFileBlocking(null, "ignored"));
assertNullPointerException(() -> vertx.fileSystem().exists(null, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().existsBlocking(null));
assertNullPointerException(() -> vertx.fileSystem().fsProps(null, h -> {
}));
assertNullPointerException(() -> vertx.fileSystem().fsPropsBlocking(null));
String fileName = "some-file.dat";
AsyncFile asyncFile = vertx.fileSystem().openBlocking(testDir + pathSep + fileName, new OpenOptions());
assertNullPointerException(() -> asyncFile.write(null));
assertIllegalArgumentException(() -> asyncFile.setWriteQueueMaxSize(1));
assertIllegalArgumentException(() -> asyncFile.setWriteQueueMaxSize(0));
assertIllegalArgumentException(() -> asyncFile.setWriteQueueMaxSize(-1));
assertNullPointerException(() -> asyncFile.write(null, 0, h -> {
}));
assertNullPointerException(() -> asyncFile.write(Buffer.buffer(), 0, null));
assertIllegalArgumentException(() -> asyncFile.write(Buffer.buffer(), -1, h -> {
}));
assertNullPointerException(() -> asyncFile.read(null, 0, 0, 0, h -> {
}));
assertNullPointerException(() -> asyncFile.read(Buffer.buffer(), 0, 0, 0, null));
assertIllegalArgumentException(() -> asyncFile.read(Buffer.buffer(), -1, 0, 0, h -> {
}));
assertIllegalArgumentException(() -> asyncFile.read(Buffer.buffer(), 0, -1, 0, h -> {
}));
assertIllegalArgumentException(() -> asyncFile.read(Buffer.buffer(), 0, 0, -1, h -> {
}));
}
use of io.vertx.core.file.OpenOptions in project vert.x by eclipse.
the class FileSystemTest method testDefaultOptionOptions.
@Test
public void testDefaultOptionOptions() {
OpenOptions def = new OpenOptions();
OpenOptions json = new OpenOptions(new JsonObject());
assertEquals(def.getPerms(), json.getPerms());
assertEquals(def.isRead(), json.isRead());
assertEquals(def.isWrite(), json.isWrite());
assertEquals(def.isCreate(), json.isCreate());
assertEquals(def.isCreateNew(), json.isCreateNew());
assertEquals(def.isDeleteOnClose(), json.isDeleteOnClose());
assertEquals(def.isTruncateExisting(), json.isTruncateExisting());
assertEquals(def.isSparse(), json.isSparse());
assertEquals(def.isSync(), json.isSync());
assertEquals(def.isDsync(), json.isDsync());
}
use of io.vertx.core.file.OpenOptions in project vert.x by eclipse.
the class FileSystemTest method testReadStreamWithBufferSize.
@Test
public void testReadStreamWithBufferSize() throws Exception {
String fileName = "some-file.dat";
int chunkSize = 16384;
int chunks = 1;
byte[] content = TestUtils.randomByteArray(chunkSize * chunks);
createFile(fileName, content);
vertx.fileSystem().open(testDir + pathSep + fileName, new OpenOptions(), ar -> {
if (ar.succeeded()) {
AsyncFile rs = ar.result();
rs.setReadBufferSize(chunkSize);
Buffer buff = Buffer.buffer();
int[] callCount = { 0 };
rs.handler((buff1) -> {
buff.appendBuffer(buff1);
callCount[0]++;
});
rs.exceptionHandler(t -> fail(t.getMessage()));
rs.endHandler(v -> {
ar.result().close(ar2 -> {
if (ar2.failed()) {
fail(ar2.cause().getMessage());
} else {
assertEquals(1, callCount[0]);
assertEquals(Buffer.buffer(content), buff);
testComplete();
}
});
});
} else {
fail(ar.cause().getMessage());
}
});
await();
}
Aggregations