@@ -679,7 +679,9 @@ private static byte[] get(URL target) throws IOException {
679679 } catch (ConnectException e ) {
680680 throw new RuntimeException ("Couldn't connect to IPFS daemon at " +target +"\n Is IPFS running?" );
681681 } 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 ());
683685 throw new RuntimeException ("IOException contacting IPFS daemon.\n Trailer: " + conn .getHeaderFields ().get ("Trailer" ) + " " + err , e );
684686 }
685687 }
@@ -756,13 +758,18 @@ private static byte[] post(URL target, byte[] body, Map<String, String> headers)
756758 return readFully (in );
757759 }
758760
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+ }
766773 }
767774
768775 private static boolean detectSSL (MultiAddress multiaddress ) {
0 commit comments