@GET
  @Path("/browse")
  @Produces(MediaType.TEXT_PLAIN)
  public Response browse(@QueryParam("path") String path, @QueryParam("download") boolean download,
                         @QueryParam("checkperm") boolean checkperm,
                         @Context HttpHeaders headers, @Context UriInfo ui) {
    LOG.debug("browsing path : {} with download : {}", path, download);
    try {
      HdfsApi api = getApi();
      FileStatus status = api.getFileStatus(path);
      FSDataInputStream fs = api.open(path);
      if(checkperm) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("allowed", true);
        return Response.ok(jsonObject)
          .header("Content-Type", MediaType.APPLICATION_JSON)
          .build();
      }
      ResponseBuilder result = Response.ok(fs);
      if (download) {
        result.header("Content-Disposition",
          "attachment; filename=\"" + URLEncoder.encode(status.getPath().getName(), "UTF-8") + "\"").type(MediaType.APPLICATION_OCTET_STREAM);
      } else {
        FileNameMap fileNameMap = URLConnection.getFileNameMap();
        String mimeType = fileNameMap.getContentTypeFor(status.getPath().getName());
        result.header("Content-Disposition",
          "filename=\"" + URLEncoder.encode(status.getPath().getName(), "UTF-8") + "\"").type(mimeType);
      }
      return result.build();
    } catch (WebApplicationException ex) {
      LOG.error("Exception while browsing : {}", path ,ex);
      throw ex;
    } catch (FileNotFoundException ex) {
      LOG.error("File not found while browsing : {}", path ,ex);
      throw new NotFoundFormattedException(ex.getMessage(), ex);
    } catch (Exception ex) {
      LOG.error("Exception while browsing : {}", path ,ex);
      throw new ServiceFormattedException(ex.getMessage(), ex);
    }
  }
Download entire file
@param path path to file
@param download download as octet strem or as file mime type
@param checkperm used to check if the file can be downloaded. Takes precedence when both download and checkperm
                 is set.
@param headers http headers
@param ui uri info
@return response with file
contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/DownloadService.java