@@ -692,7 +692,9 @@ private static byte[] get(URL target, int timeout) throws IOException {
692692 } catch (SocketTimeoutException e ) {
693693 throw new RuntimeException (String .format ("timeout (%d ms) has been exceeded" , timeout ));
694694 } 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 ());
696698 throw new RuntimeException ("IOException contacting IPFS daemon.\n Trailer: " + conn .getHeaderFields ().get ("Trailer" ) + " " + err , e );
697699 }
698700 }
@@ -765,13 +767,18 @@ private static byte[] post(URL target, byte[] body, Map<String, String> headers,
765767 return readFully (in );
766768 }
767769
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+ }
775782 }
776783
777784 private static boolean detectSSL (MultiAddress multiaddress ) {
0 commit comments