From b36d0203f7eeb99e7ae888803b5d987f334cbdd1 Mon Sep 17 00:00:00 2001 From: Ian Preston Date: Tue, 14 Jun 2016 00:51:29 +0100 Subject: [PATCH] Updated to IPFS 0.4.2 API --- src/main/java/org/ipfs/api/IPFS.java | 11 +++++++++-- src/main/java/org/ipfs/api/JSONParser.java | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/ipfs/api/IPFS.java b/src/main/java/org/ipfs/api/IPFS.java index a3eeb4f..f0c8c39 100644 --- a/src/main/java/org/ipfs/api/IPFS.java +++ b/src/main/java/org/ipfs/api/IPFS.java @@ -55,7 +55,10 @@ public List add(List files) throws IOException { for (NamedStreamable f : files) m.addFilePart("file", f); String res = m.finish(); - return JSONParser.parseStream(res).stream().map(x -> MerkleNode.fromJSON((Map) x)).collect(Collectors.toList()); + return JSONParser.parseStream(res).stream() + .skip(1) + .map(x -> MerkleNode.fromJSON((Map) x)) + .collect(Collectors.toList()); } public List ls(Multihash hash) throws IOException { @@ -101,7 +104,11 @@ public Map mount(java.io.File ipfsRoot, java.io.File ipnsRoot) throws IOExceptio // level 2 commands public class Refs { public List local() throws IOException { - return Arrays.asList(new String(retrieve("refs/local")).split("\n")).stream().map(Multihash::fromBase58).collect(Collectors.toList()); + String jsonStream = new String(retrieve("refs/local")); + return JSONParser.parseStream(jsonStream).stream() + .map(m -> (String) (((Map) m).get("Ref"))) + .map(Multihash::fromBase58) + .collect(Collectors.toList()); } } diff --git a/src/main/java/org/ipfs/api/JSONParser.java b/src/main/java/org/ipfs/api/JSONParser.java index 581659a..40e6891 100644 --- a/src/main/java/org/ipfs/api/JSONParser.java +++ b/src/main/java/org/ipfs/api/JSONParser.java @@ -274,6 +274,7 @@ public static List parseStream(String json) return null; int[] pos = new int[1]; List res = new ArrayList<>(); + json = json.trim(); while (pos[0] < json.length()) res.add(parse(json, pos)); return res;