Source:
private void doSendFile(String filename, long offset, long length, Handler<AsyncResult<Void>> resultHandler) { synchronized (conn) { if (headWritten) { throw new IllegalStateException("Head already written"); } checkWritten(); File file = vertx.resolveFile(filename); long fileLength = file.length(); if (!contentLengthSet()) { putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(Math.min(length, fileLength - offset))); } if (!contentTypeSet()) { int li = filename.lastIndexOf('.'); if (li != -1 && li != filename.length() - 1) { String ext = filename.substring(li + 1, filename.length()); String contentType = MimeMapping.getMimeTypeForExtension(ext); if (contentType != null) { putHeader(HttpHeaders.CONTENT_TYPE, contentType); } } } prepareHeaders(() -> { RandomAccessFile raf; try { raf = new RandomAccessFile(file, "r"); conn.queueForWrite(response); conn.sendFile(raf, Math.min(offset, fileLength), Math.min(length, fileLength - offset)); } catch (IOException e) { if (resultHandler != null) { ContextImpl ctx = vertx.getOrCreateContext(); ctx.runOnContext((v) -> resultHandler.handle(Future.failedFuture(e))); } else { log.error("Failed to send file", e); } return; } channelFuture = conn.writeToChannel(LastHttpContent.EMPTY_LAST_CONTENT); headWritten = written = true; if (resultHandler != null) { ContextImpl ctx = vertx.getOrCreateContext(); channelFuture.addListener(future -> { AsyncResult<Void> res; if (future.isSuccess()) { res = Future.succeededFuture(); } else { res = Future.failedFuture(future.cause()); } ctx.runOnContext((v) -> resultHandler.handle(res)); }); } if (!keepAlive) { closeConnAfterWrite(); } conn.responseComplete(); if (bodyEndHandler != null) { bodyEndHandler.handle(null); } }); } }

Target:
private void doSendFile(String filename, long offset, long length, Handler<AsyncResult<Void>> resultHandler) { synchronized (conn) { if (headWritten) { throw new IllegalStateException("Head already written"); } checkWritten(); File file = vertx.resolveFile(filename); long contentLength = Math.min(length, file.length() - offset); if (!contentLengthSet()) { putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(contentLength)); } if (!contentTypeSet()) { int li = filename.lastIndexOf('.'); if (li != -1 && li != filename.length() - 1) { String ext = filename.substring(li + 1, filename.length()); String contentType = MimeMapping.getMimeTypeForExtension(ext); if (contentType != null) { putHeader(HttpHeaders.CONTENT_TYPE, contentType); } } } prepareHeaders(() -> { RandomAccessFile raf = null; try { raf = new RandomAccessFile(file, "r"); conn.queueForWrite(response); conn.sendFile(raf, Math.min(offset, file.length()), contentLength); } catch (IOException e) { try { if (raf != null) { raf.close(); } } catch (IOException ignore) { } if (resultHandler != null) { ContextImpl ctx = vertx.getOrCreateContext(); ctx.runOnContext((v) -> resultHandler.handle(Future.failedFuture(e))); } else { log.error("Failed to send file", e); } return; } channelFuture = conn.writeToChannel(LastHttpContent.EMPTY_LAST_CONTENT); headWritten = written = true; if (resultHandler != null) { ContextImpl ctx = vertx.getOrCreateContext(); channelFuture.addListener(future -> { AsyncResult<Void> res; if (future.isSuccess()) { res = Future.succeededFuture(); } else { res = Future.failedFuture(future.cause()); } ctx.runOnContext((v) -> resultHandler.handle(res)); }); } if (!keepAlive) { closeConnAfterWrite(); } conn.responseComplete(); if (bodyEndHandler != null) { bodyEndHandler.handle(null); } }); } }