private void doClose(Handler<AsyncResult<Void>> handler) { ContextInternal handlerContext = vertx.getOrCreateContext(); handlerContext.executeBlockingInternal(res -> { try { ch.close(); res.complete(null); } catch (IOException e) { res.fail(e); } }, handler); }
/** {@inheritDoc} */ @Override public void close() throws IOException { for (ChannelOpFuture asyncFut : asyncFuts) { try { asyncFut.getUninterruptibly(); // Ignore interrupts while waiting for channel close. } catch (IgniteCheckedException e) { throw new IOException(e); } } ch.close(); }
.verify(); channel.close();
@Test public void writeAsynchronousFileChannelCanceled() throws Exception { DataBuffer foo = stringBuffer("foo"); DataBuffer bar = stringBuffer("bar"); Flux<DataBuffer> flux = Flux.just(foo, bar); AsynchronousFileChannel channel = AsynchronousFileChannel.open(tempFile, StandardOpenOption.WRITE); Flux<DataBuffer> writeResult = DataBufferUtils.write(flux, channel); StepVerifier.create(writeResult, 1) .consumeNextWith(stringConsumer("foo")) .thenCancel() .verify(); String result = String.join("", Files.readAllLines(tempFile)); assertEquals("foo", result); channel.close(); flux.subscribe(DataBufferUtils::release); }
@Test public void writeAsynchronousFileChannelErrorInFlux() throws Exception { DataBuffer foo = stringBuffer("foo"); DataBuffer bar = stringBuffer("bar"); Flux<DataBuffer> flux = Flux.just(foo, bar).concatWith(Mono.error(new RuntimeException())); AsynchronousFileChannel channel = AsynchronousFileChannel.open(tempFile, StandardOpenOption.WRITE); Flux<DataBuffer> writeResult = DataBufferUtils.write(flux, channel); StepVerifier.create(writeResult) .consumeNextWith(stringConsumer("foo")) .consumeNextWith(stringConsumer("bar")) .expectError(RuntimeException.class) .verify(); String result = String.join("", Files.readAllLines(tempFile)); assertEquals("foobar", result); channel.close(); }
@Test public void writeAsynchronousFileChannel() throws Exception { DataBuffer foo = stringBuffer("foo"); DataBuffer bar = stringBuffer("bar"); DataBuffer baz = stringBuffer("baz"); DataBuffer qux = stringBuffer("qux"); Flux<DataBuffer> flux = Flux.just(foo, bar, baz, qux); AsynchronousFileChannel channel = AsynchronousFileChannel.open(tempFile, StandardOpenOption.WRITE); Flux<DataBuffer> writeResult = DataBufferUtils.write(flux, channel); verifyWrittenData(writeResult); channel.close(); }
private void doClose(Handler<AsyncResult<Void>> handler) { ContextInternal handlerContext = vertx.getOrCreateContext(); handlerContext.executeBlockingInternal(res -> { try { ch.close(); res.complete(null); } catch (IOException e) { res.fail(e); } }, handler); }
@Override public Void call() throws IOException { ac.close(); return null; } });
private void close() { if (this.channel != null) { try { this.channel.close(); this.channel = null; } catch (IOException e) { } } }
private void close() { if (this.channel != null) { try { this.channel.close(); this.channel = null; } catch (IOException e) { } } }
private static void closeFileChannelSafe(AsynchronousFileChannel ch) { if (ch != null) { try { ch.close(); } catch (IOException e1) { } } }
private void close(ByteBuffer buffer, AsynchronousFileChannel channel) { try { channel.close(); } catch (Throwable e) { } } });
private void close(AsynchronousFileChannel channel) { try { channel.close(); } catch (Exception e) { Logger.getAnonymousLogger().log(Level.WARNING, String.format("PUT of file failed %s", e.toString())); } } });
private void close(AsynchronousFileChannel channel) { try { channel.close(); } catch (Throwable e) { Logger.getAnonymousLogger().log(Level.WARNING, String.format("PUT of file failed %s", e.toString())); } } });
public void close() { try { fileChannel.close(); fileChannel = null; } catch (IOException e) { FSTUtil.<RuntimeException>rethrow(e); } } }
@Override public void failed(Throwable exe, Void v) { try { channel.close(); } catch (IOException e) { } get.fail(exe); } });
@Override public void failed(Throwable ex, Operation op) { logWarning("Backup Failed %s", Utils.toString(ex)); try { channel.close(); } catch (IOException e) { } // fail the put op, sender can retry sending the same range put.fail(ex); } });
private void done() throws IOException { if (fileChannel != null) { if (!contentStream.isEmpty()) { ByteBuffer bb = ByteBuffer.allocate(contentStream.length()); bb.put(contentStream.toByteArray()); bb.flip(); contentStream.clear(); fileChannel.write(bb, fileChannel.size()); fileChannel.close(); } } }
@Override public void failed(Throwable exc, ByteBuffer dataBuffer) { try { channel.close(); } catch (IOException ignored) { } this.sink.error(exc); } }
private void doClose(AsyncResultHandler<Void> handler) { AsyncResult<Void> res; try { ch.close(); res = new AsyncResult<>((Void)null); } catch (IOException e) { res = new AsyncResult<Void>(e); } if (handler != null) { handler.handle(res); } }