
com.zandero.rest.writer.FileResponseWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rest.vertx Show documentation
Show all versions of rest.vertx Show documentation
JAX-RS REST annotation processor for vert.x verticals
The newest version!
package com.zandero.rest.writer;
import io.vertx.core.file.FileSystem;
import io.vertx.core.http.*;
import io.vertx.ext.web.RoutingContext;
import javax.ws.rs.core.Context;
import java.io.FileNotFoundException;
/**
* Serves static files / resources
*/
public class FileResponseWriter implements HttpResponseWriter {
@Context
RoutingContext context;
@Override
public void write(String path, HttpServerRequest request, HttpServerResponse response) throws FileNotFoundException {
if (!fileExists(context, path)) {
throw new FileNotFoundException(path);
}
response.sendFile(path);
}
protected boolean fileExists(RoutingContext context, String file) {
FileSystem fs = context.vertx().fileSystem();
return fs.existsBlocking(file);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy