Ejemplo n.º 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;
 }
Ejemplo n.º 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;
    }
  }
Ejemplo n.º 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;
  }
Ejemplo n.º 4
0
 protected Response createClose(Path path) {
   Request request = createCloseRequest(path);
   return PNFS.request(request, 2);
 }
Ejemplo n.º 5
0
 protected Response createOpen() {
   Response rsp = PNFS.request(Command.CREATE_OPEN, this);
   setFilename(rsp.getArgs().get("filename"));
   return rsp;
 }
Ejemplo n.º 6
0
 /*
  * @see com.painiu.pnfs.File#delete()
  */
 public void delete() throws PNFSException {
   PNFS.delete(this);
 }