@@ -207,7 +207,7 @@ private static Object getFileContents(Object uriOrJSFile, boolean asBytes, JSFun
207207 try {
208208 URL url = new URL (uri );
209209 BufferedInputStream stream = (BufferedInputStream ) url .getContent ();
210- return (asBytes ? Rdr . getStreamAsBytes (stream , null ) : Rdr . streamToUTF8String (stream ));
210+ return (asBytes ? streamToBytes (stream ) : streamToString (stream ));
211211 } catch (Exception e ) {
212212 }
213213 }
@@ -248,11 +248,14 @@ static String ensureString(Object data) {
248248 if (data == null )
249249 return null ;
250250 if (data instanceof byte [])
251- return Rdr . bytesToUTF8String ((byte []) data );
251+ return new String ((byte []) data ); // was Rdr.bytesToUTF8String
252252 if (data instanceof String || data instanceof SB )
253253 return data .toString ();
254254 if (data instanceof InputStream )
255- return Rdr .streamToUTF8String (new BufferedInputStream ((InputStream ) data ));
255+ try {
256+ return streamToString ((InputStream ) data );
257+ } catch (IOException e ) {
258+ }
256259 return null ;
257260 }
258261
@@ -1267,6 +1270,29 @@ public String getJ2SPath() {
12671270 return (String ) getAppletAttribute ("_j2sFullPath" );
12681271 }
12691272
1273+ /**
1274+ * Read an InputStream in its entirety as a string, closing the stream.
1275+ *
1276+ * @param is
1277+ * @return a String
1278+ * @throws IOException
1279+ */
1280+ public static String streamToString (InputStream is ) throws IOException {
1281+ return new String (streamToBytes (is ));
1282+ }
1283+
1284+ /**
1285+ * Read an InputStream in its entirety as a byte array. Closes the stream.
1286+ *
1287+ * @param is
1288+ * @return a byte array
1289+ */
1290+ public static byte [] streamToBytes (InputStream is ) throws IOException {
1291+ byte [] bytes = Rdr .getLimitedStreamBytes (is , -1 );
1292+ is .close ();
1293+ return bytes ;
1294+ }
1295+
12701296
12711297
12721298
0 commit comments