@@ -679,7 +679,9 @@ private static byte[] get(URL target) throws IOException {
679
679
} catch (ConnectException e ) {
680
680
throw new RuntimeException ("Couldn't connect to IPFS daemon at " +target +"\n Is IPFS running?" );
681
681
} catch (IOException e ) {
682
- String err = new String (readFully (conn .getErrorStream ()));
682
+ String err = Optional .ofNullable (conn .getErrorStream ())
683
+ .map (s ->new String (readFully (s )))
684
+ .orElse (e .getMessage ());
683
685
throw new RuntimeException ("IOException contacting IPFS daemon.\n Trailer: " + conn .getHeaderFields ().get ("Trailer" ) + " " + err , e );
684
686
}
685
687
}
@@ -756,13 +758,18 @@ private static byte[] post(URL target, byte[] body, Map<String, String> headers)
756
758
return readFully (in );
757
759
}
758
760
759
- private static final byte [] readFully (InputStream in ) throws IOException {
760
- ByteArrayOutputStream resp = new ByteArrayOutputStream ();
761
- byte [] buf = new byte [4096 ];
762
- int r ;
763
- while ((r =in .read (buf )) >= 0 )
764
- resp .write (buf , 0 , r );
765
- return resp .toByteArray ();
761
+ private static final byte [] readFully (InputStream in ) {
762
+ try {
763
+ ByteArrayOutputStream resp = new ByteArrayOutputStream ();
764
+ byte [] buf = new byte [4096 ];
765
+ int r ;
766
+ while ((r =in .read (buf )) >= 0 )
767
+ resp .write (buf , 0 , r );
768
+ return resp .toByteArray ();
769
+
770
+ } catch (IOException ex ) {
771
+ throw new RuntimeException ("Error reading InputStrean" , ex );
772
+ }
766
773
}
767
774
768
775
private static boolean detectSSL (MultiAddress multiaddress ) {
0 commit comments