示例#1
0
 /*
  * @see com.painiu.pnfs.File#getInputStream()
  */
 public InputStream getInputStream() throws PNFSException, IOException {
   InputStream in = PNFS.httpGetFile(getPaths());
   if (in == null) {
     throw new IOException("Can not read remote file");
   }
   return in;
 }
示例#2
0
  /*
   * @see com.painiu.pnfs.File#store()
   */
  public void store() throws PNFSException {
    Response rsp = createOpen();

    List<Path> paths = parsePaths(rsp);

    Path path = PNFS.httpPutFile(file, paths);

    if (path == null) {
      throw new PNFSException("Failed to send file to YPFS storage node");
    }

    try {
      createClose(path);
    } catch (PNFSException e) {
      // rollback
      PNFS.httpDeleteFile(path.getPath());
      throw e;
    }
  }
示例#3
0
  protected List<String> getPaths() throws PNFSException {
    Request request = createGetPathsRequest();
    Response rsp = PNFS.request(request);

    Map<String, String> args = rsp.getArgs();
    int num = 0;

    try {
      num = Integer.parseInt(args.get("paths"));
    } catch (NumberFormatException e) {
      throw new PNFSException("invalid response from ypfs server");
    }

    List<String> paths = new ArrayList<String>(num);

    for (int i = 1; i < num + 1; i++) {
      String path = args.get("path" + i);
      if (path != null) {
        paths.add(path);
      }
    }

    return paths;
  }
示例#4
0
 protected Response createClose(Path path) {
   Request request = createCloseRequest(path);
   return PNFS.request(request, 2);
 }
示例#5
0
 protected Response createOpen() {
   Response rsp = PNFS.request(Command.CREATE_OPEN, this);
   setFilename(rsp.getArgs().get("filename"));
   return rsp;
 }
示例#6
0
 /*
  * @see com.painiu.pnfs.File#delete()
  */
 public void delete() throws PNFSException {
   PNFS.delete(this);
 }