@@ -662,6 +662,13 @@ public String chcid(String path) throws IOException {
662662 return retrieveString ("files/chcid?args=" + arg );
663663 }
664664
665+ public String chcid (String path , Optional <Integer > cidVersion , Optional <String > hash ) throws IOException {
666+ String arg = URLEncoder .encode (path , "UTF-8" );
667+ String cid = cidVersion .isPresent () ? "&cid-version=" + cidVersion .get () : "" ;
668+ String hashFunc = hash .isPresent () ? "&hash=" + hash .get () : "" ;
669+ return retrieveString ("files/chcid?args=" + arg + cid + hashFunc );
670+ }
671+
665672 public String cp (String source , String dest , boolean parents ) throws IOException {
666673 return retrieveString ("files/cp?arg=" + URLEncoder .encode (source , "UTF-8" ) + "&arg=" +
667674 URLEncoder .encode (dest , "UTF-8" ) + "&parents=" + parents );
@@ -695,10 +702,11 @@ public String mkdir(String path, boolean parents) throws IOException {
695702 return retrieveString ("files/mkdir?arg=" + arg + "&parents=" + parents );
696703 }
697704
698- public String mkdir (String path , boolean parents , int cidVersion , Multihash hash ) throws IOException {
705+ public String mkdir (String path , boolean parents , Optional < Integer > cidVersion , Optional < String > hash ) throws IOException {
699706 String arg = URLEncoder .encode (path , "UTF-8" );
700- return retrieveString ("files/mkdir?arg=" + arg + "&parents=" + parents + "&cid-version=" +
701- cidVersion + "&hash=" + hash );
707+ String cid = cidVersion .isPresent () ? "&cid-version=" + cidVersion .get () : "" ;
708+ String hashFunc = hash .isPresent () ? "&hash=" + hash .get () : "" ;
709+ return retrieveString ("files/mkdir?arg=" + arg + "&parents=" + parents + cid + hashFunc );
702710 }
703711
704712 public String mv (String source , String dest ) throws IOException {
@@ -725,7 +733,11 @@ public Map stat(String path) throws IOException {
725733 String arg = URLEncoder .encode (path , "UTF-8" );
726734 return retrieveMap ("files/stat?arg=" + arg );
727735 }
728-
736+ public Map stat (String path , Optional <String > format , boolean withLocal ) throws IOException {
737+ String arg = URLEncoder .encode (path , "UTF-8" );
738+ String formatStr = format .isPresent () ? "&format=" + format .get () : "" ;
739+ return retrieveMap ("files/stat?arg=" + arg + formatStr + "&with-local=" + withLocal );
740+ }
729741 public String write (String path , NamedStreamable uploadFile , boolean create , boolean parents ) throws IOException {
730742 String arg = URLEncoder .encode (path , "UTF-8" );
731743 String rpcParams = "files/write?arg=" + arg + "&create=" + create + "&parents=" + parents ;
@@ -738,6 +750,19 @@ public String write(String path, NamedStreamable uploadFile, boolean create, boo
738750 }
739751 return m .finish ();
740752 }
753+
754+ public String write (String path , NamedStreamable uploadFile , WriteFilesArgs args ) throws IOException {
755+ String arg = URLEncoder .encode (path , "UTF-8" );
756+ String rpcParams = "files/write?arg=" + arg + "&" + args .toQueryString ();
757+ URL target = new URL (protocol ,host ,port ,apiVersion + rpcParams );
758+ Multipart m = new Multipart (target .toString (),"UTF-8" );
759+ if (uploadFile .isDirectory ()) {
760+ throw new IllegalArgumentException ("Input must be a file" );
761+ } else {
762+ m .addFilePart ("file" , Paths .get ("" ), uploadFile );
763+ }
764+ return m .finish ();
765+ }
741766 }
742767
743768 public class FileStore {
@@ -746,12 +771,12 @@ public Map dups() throws IOException {
746771 return retrieveMap ("filestore/dups" );
747772 }
748773
749- public Map ls () throws IOException {
750- return retrieveMap ("filestore/ls" );
774+ public Map ls (boolean fileOrder ) throws IOException {
775+ return retrieveMap ("filestore/ls?file-order=" + fileOrder );
751776 }
752777
753- public Map verify () throws IOException {
754- return retrieveMap ("filestore/verify" );
778+ public Map verify (boolean fileOrder ) throws IOException {
779+ return retrieveMap ("filestore/verify?file-order=" + fileOrder );
755780 }
756781 }
757782
@@ -779,6 +804,9 @@ public String reprovide() throws IOException {
779804 public Map stat () throws IOException {
780805 return retrieveMap ("bitswap/stat" );
781806 }
807+ public Map stat (boolean verbose , boolean humanReadable ) throws IOException {
808+ return retrieveMap ("bitswap/stat?verbose=" + verbose + "&human=" + humanReadable );
809+ }
782810 public Map wantlist (Multihash peerId ) throws IOException {
783811 return retrieveMap ("bitswap/wantlist?peer=" + peerId );
784812 }
0 commit comments