Ejemplo n.º 1
0
 /** DFS client read bytes starting from the specified position. */
 private void dfsClientReadFileFromPosition(Path corruptedFile)
     throws UnresolvedLinkException, IOException {
   DFSInputStream in = dfs.dfs.open(corruptedFile.toUri().getPath());
   byte[] buf = new byte[buffersize];
   int startPosition = 2;
   int nRead = 0; // total number of bytes read
   try {
     do {
       nRead = in.read(startPosition, buf, 0, buf.length);
       startPosition += buf.length;
     } while (nRead > 0);
   } catch (BlockMissingException bme) {
     LOG.debug("DfsClientReadFile caught BlockMissingException.");
   }
 }
Ejemplo n.º 2
0
  /** Ask dfs client to read the file */
  private void dfsClientReadFile(Path corruptedFile) throws IOException, UnresolvedLinkException {
    DFSInputStream in = dfs.dfs.open(corruptedFile.toUri().getPath());
    byte[] buf = new byte[buffersize];
    int nRead = 0; // total number of bytes read

    try {
      do {
        nRead = in.read(buf, 0, buf.length);
      } while (nRead > 0);
    } catch (ChecksumException ce) {
      // caught ChecksumException if all replicas are bad, ignore and continue.
      LOG.debug("DfsClientReadFile caught ChecksumException.");
    } catch (BlockMissingException bme) {
      // caught BlockMissingException, ignore.
      LOG.debug("DfsClientReadFile caught BlockMissingException.");
    }
  }
Ejemplo n.º 3
0
  @SuppressWarnings("unchecked")
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    final String path = ServletUtil.getDecodedPath(request, "/streamFile");
    final String rawPath = ServletUtil.getRawPath(request, "/streamFile");
    final String filename = JspHelper.validatePath(path);
    final String rawFilename = JspHelper.validatePath(rawPath);
    if (filename == null) {
      response.setContentType("text/plain");
      PrintWriter out = response.getWriter();
      out.print("Invalid input");
      return;
    }

    Enumeration<String> reqRanges = request.getHeaders("Range");
    if (reqRanges != null && !reqRanges.hasMoreElements()) {
      reqRanges = null;
    }

    DFSClient dfs;
    try {
      dfs = getDFSClient(request);
    } catch (InterruptedException e) {
      response.sendError(400, e.getMessage());
      return;
    }

    DFSInputStream in = null;
    OutputStream out = null;

    try {
      in = dfs.open(filename);
      out = response.getOutputStream();
      final long fileLen = in.getFileLength();
      if (reqRanges != null) {
        List<InclusiveByteRange> ranges = InclusiveByteRange.satisfiableRanges(reqRanges, fileLen);
        StreamFile.sendPartialData(in, out, response, fileLen, ranges);
      } else {
        // No ranges, so send entire file
        response.setHeader("Content-Disposition", "attachment; filename=\"" + rawFilename + "\"");
        response.setContentType("application/octet-stream");
        response.setHeader(CONTENT_LENGTH, "" + fileLen);
        StreamFile.copyFromOffset(in, out, 0L, fileLen);
      }
      in.close();
      in = null;
      out.close();
      out = null;
      dfs.close();
      dfs = null;
    } catch (IOException ioe) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("response.isCommitted()=" + response.isCommitted(), ioe);
      }
      throw ioe;
    } finally {
      IOUtils.cleanup(LOG, in);
      IOUtils.cleanup(LOG, out);
      IOUtils.cleanup(LOG, dfs);
    }
  }