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