Package org.apache.hadoop.hdfs

Examples of org.apache.hadoop.hdfs.DFSInputStream


      PrintWriter out = response.getWriter();
      out.print("Invalid input");
      return;
    }
    DFSClient dfs = null;
    DFSInputStream in = null;
    OutputStream os = null;
    try {
      dfs = getDFSClient(request);
    } catch (IOException e) {
      // Can not connect to NN; redirect to a different datanode
      List<DatanodeID> candidates = JspHelper.bestNode(
          getDatanodes(request), false);
      try {
        response.sendRedirect(
            createUri(filename,
                      candidates.toArray(new DatanodeID[candidates.size()]),
                      getUGI(request),
                      request).toURL().toString());
        return;
      } catch (URISyntaxException ue) {
        throw new ServletException(ue);
      }
    } catch (InterruptedException e) {
      response.sendError(400, e.getMessage());
      return;
    }
    in = dfs.open(filename);
    long contentLength = in.getFileLength();
    if (pos != null) {
      contentLength -= pos;
      in.seek(pos);
    }
   
    os = response.getOutputStream();
    response.setHeader("Content-Disposition", "attachment; filename=\"" +
                       filename + "\"");
    response.setHeader("isUnderConstruction",
                       in.isUnderConstruction() ? "true" : "false");
    response.setContentType("application/octet-stream");
    response.setHeader(
      HftpFileSystem.CONTENT_LENGTH_FIELD,
      String.valueOf(contentLength)
    );
   
    byte buf[] = new byte[4096];
    try {
      int bytesRead;
      while ((bytesRead = in.read(buf)) != -1) {
        os.write(buf, 0, bytesRead);
      }
    } catch (IOException ioe) {
      DataNode.LOG.warn("Failed to server request: " + request, ioe);
    } finally {
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hdfs.DFSInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.