public void serveFile(final String contentFile, final String root, final String validSubPaths) {
    if (rootPath == null) {
      final String slash = root.endsWith("/") ? "" : "/";
      rootPath = root + slash;
    }

    final String contentPath = rootPath + context.request.uri;

    try {
      final byte[] fileContent = readFile(contentPath);
      completes().with(Response.of(Ok, Body.from(fileContent, Body.Encoding.UTF8).content));
    } catch (IOException e) {
      completes().with(Response.of(InternalServerError));
    } catch (IllegalArgumentException e) {
      completes().with(Response.of(NotFound));
    }
  }
public void serveFile ( final String contentFile , final String root , final String validSubPaths ) { if ( rootPath == null ) { final String slash = root . endsWith ( "/" ) ? "" : "/" ; rootPath = root + slash ; } final String contentPath = rootPath + context . request . uri ; try { final byte [ ] fileContent = readFile ( contentPath ) ; completes ( ) . with ( Response . of ( Ok , Body . from ( fileContent , Body . Encoding . UTF8 ) . content ) ) ; } catch ( IOException e ) { completes ( ) . with ( Response . of ( InternalServerError ) ) ; } catch ( IllegalArgumentException e ) { completes ( ) . with ( Response . of ( NotFound ) ) ; } }
Completes with {@code Ok} and the file content or {@code NotFound}.
@param contentFile the String name of the content file to be served
@param root the String root path of the static content
@param validSubPaths the String indicating the valid file paths under the root