@@ -692,7 +692,9 @@ private static byte[] get(URL target, int timeout) throws IOException {
692
692
} catch (SocketTimeoutException e ) {
693
693
throw new RuntimeException (String .format ("timeout (%d ms) has been exceeded" , timeout ));
694
694
} catch (IOException e ) {
695
- String err = new String (readFully (conn .getErrorStream ()));
695
+ String err = Optional .ofNullable (conn .getErrorStream ())
696
+ .map (s ->new String (readFully (s )))
697
+ .orElse (e .getMessage ());
696
698
throw new RuntimeException ("IOException contacting IPFS daemon.\n Trailer: " + conn .getHeaderFields ().get ("Trailer" ) + " " + err , e );
697
699
}
698
700
}
@@ -765,13 +767,18 @@ private static byte[] post(URL target, byte[] body, Map<String, String> headers,
765
767
return readFully (in );
766
768
}
767
769
768
- private static final byte [] readFully (InputStream in ) throws IOException {
769
- ByteArrayOutputStream resp = new ByteArrayOutputStream ();
770
- byte [] buf = new byte [4096 ];
771
- int r ;
772
- while ((r =in .read (buf )) >= 0 )
773
- resp .write (buf , 0 , r );
774
- return resp .toByteArray ();
770
+ private static final byte [] readFully (InputStream in ) {
771
+ try {
772
+ ByteArrayOutputStream resp = new ByteArrayOutputStream ();
773
+ byte [] buf = new byte [4096 ];
774
+ int r ;
775
+ while ((r =in .read (buf )) >= 0 )
776
+ resp .write (buf , 0 , r );
777
+ return resp .toByteArray ();
778
+
779
+ } catch (IOException ex ) {
780
+ throw new RuntimeException ("Error reading InputStrean" , ex );
781
+ }
775
782
}
776
783
777
784
private static boolean detectSSL (MultiAddress multiaddress ) {
0 commit comments