@@ -209,29 +209,29 @@ public MerkleNode _new(Optional<String> template) throws IOException {
209
209
public MerkleNode patch (Multihash base , String command , Optional <byte []> data , Optional <String > name , Optional <Multihash > target ) throws IOException {
210
210
if (!ObjectPatchTypes .contains (command ))
211
211
throw new IllegalStateException ("Illegal Object.patch command type: " +command );
212
- String targetPath = "object/patch?arg=" + base .toBase58 () + "&arg=" + command ;
212
+ String targetPath = "object/patch/" + command + " ?arg=" + base .toBase58 ();
213
213
if (name .isPresent ())
214
214
targetPath += "&arg=" + name .get ();
215
215
if (target .isPresent ())
216
216
targetPath += "&arg=" + target .get ().toBase58 ();
217
217
218
218
switch (command ) {
219
219
case "add-link" :
220
- if (!name . isPresent () || ! target .isPresent ())
220
+ if (!target .isPresent ())
221
221
throw new IllegalStateException ("add-link requires name and target!" );
222
- return MerkleNode .fromJSON (retrieveMap (targetPath ));
223
222
case "rm-link" :
224
223
if (!name .isPresent ())
225
- throw new IllegalStateException ("rm- link requires name!" );
224
+ throw new IllegalStateException ("link name is required !" );
226
225
return MerkleNode .fromJSON (retrieveMap (targetPath ));
227
226
case "set-data" :
228
- if (!data .isPresent ())
229
- throw new IllegalStateException ("set-data requires data!" );
230
- return MerkleNode .fromJSON (postMap (targetPath , data .get (), Collections .EMPTY_MAP ));
231
227
case "append-data" :
232
228
if (!data .isPresent ())
233
- throw new IllegalStateException ("append-data requires data!" );
234
- return MerkleNode .fromJSON (postMap (targetPath , data .get (), Collections .EMPTY_MAP ));
229
+ throw new IllegalStateException ("set-data requires data!" );
230
+ Multipart m = new Multipart ("http://" + host + ":" + port + version +"object/patch/" +command +"?arg=" +base .toBase58 ()+"&stream-channels=true" , "UTF-8" );
231
+ m .addFilePart ("file" , new NamedStreamable .ByteArrayWrapper (data .get ()));
232
+ String res = m .finish ();
233
+ return MerkleNode .fromJSON (JSONParser .parse (res ));
234
+
235
235
default :
236
236
throw new IllegalStateException ("Unimplemented" );
237
237
}
@@ -419,14 +419,18 @@ private static byte[] get(URL target) throws IOException {
419
419
conn .setRequestMethod ("GET" );
420
420
conn .setRequestProperty ("Content-Type" , "application/json" );
421
421
422
- InputStream in = conn .getInputStream ();
423
- ByteArrayOutputStream resp = new ByteArrayOutputStream ();
422
+ try {
423
+ InputStream in = conn .getInputStream ();
424
+ ByteArrayOutputStream resp = new ByteArrayOutputStream ();
424
425
425
- byte [] buf = new byte [4096 ];
426
- int r ;
427
- while ((r =in .read (buf )) >= 0 )
428
- resp .write (buf , 0 , r );
429
- return resp .toByteArray ();
426
+ byte [] buf = new byte [4096 ];
427
+ int r ;
428
+ while ((r = in .read (buf )) >= 0 )
429
+ resp .write (buf , 0 , r );
430
+ return resp .toByteArray ();
431
+ } catch (IOException e ) {
432
+ throw new RuntimeException ("Trailer: " + conn .getHeaderFields ().get ("Trailer" ), e );
433
+ }
430
434
}
431
435
432
436
private Map postMap (String path , byte [] body , Map <String , String > headers ) throws IOException {
0 commit comments