Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20210728170251
20210728172208
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/3.3.1/SwingJS-site.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/ver/3.3.1/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20210728170251
20210728172208
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
31 changes: 27 additions & 4 deletions sources/net.sf.j2s.java.core/src/javajs/util/Rdr.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,32 @@ public String readNextLine() throws Exception {
return reader.readLine();
}

public static Map<String, Object> readCifData(GenericCifDataParser parser, BufferedReader br) {
return parser.set(null, br, false).getAllCifData();
}
/**
* Read an InputStream in its entirety as a byte array, closing the stream.
*
* @param is
* @return a byte array
*/
public static byte[] streamToBytes(InputStream is) throws IOException {
byte[] bytes = getLimitedStreamBytes(is, -1);
is.close();
return bytes;
}

/**
* Read an InputStream in its entirety as a string, closing the stream.
*
* @param is
* @return a String
* @throws IOException
*/
public static String streamToString(InputStream is) throws IOException {
return new String(streamToBytes(is));
}

public static Map<String, Object> readCifData(GenericCifDataParser parser, BufferedReader br) {
return parser.set(null, br, false).getAllCifData();
}

///////////

Expand Down Expand Up @@ -327,7 +350,7 @@ public static BufferedReader getBR(String string) {

public static BufferedInputStream toBIS(Object o) {
return (AU.isAB(o) ? getBIS((byte[]) o)
: o instanceof SB ? getBIS(Rdr.getBytesFromSB((SB) o))
: o instanceof SB ? getBIS(getBytesFromSB((SB) o))
: o instanceof String ? getBIS(((String) o).getBytes()) : null);
}

Expand Down
27 changes: 2 additions & 25 deletions sources/net.sf.j2s.java.core/src/swingjs/JSUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private static Object getFileContents(Object uriOrJSFile, boolean asBytes, JSFun
try {
URL url = new URL(uri);
BufferedInputStream stream = (BufferedInputStream) url.getContent();
return (asBytes ? streamToBytes(stream) : streamToString(stream));
return (asBytes ? Rdr.streamToBytes(stream) : Rdr.streamToString(stream));
} catch (Exception e) {
}
}
Expand Down Expand Up @@ -253,7 +253,7 @@ static String ensureString(Object data) {
return data.toString();
if (data instanceof InputStream)
try {
return streamToString((InputStream) data);
return Rdr.streamToString((InputStream) data);
} catch (IOException e) {
}
return null;
Expand Down Expand Up @@ -1270,29 +1270,6 @@ public String getJ2SPath() {
return (String) getAppletAttribute("_j2sFullPath");
}

/**
* Read an InputStream in its entirety as a string, closing the stream.
*
* @param is
* @return a String
* @throws IOException
*/
public static String streamToString(InputStream is) throws IOException {
return new String(streamToBytes(is));
}

/**
* Read an InputStream in its entirety as a byte array. Closes the stream.
*
* @param is
* @return a byte array
*/
public static byte[] streamToBytes(InputStream is) throws IOException {
byte[] bytes = Rdr.getLimitedStreamBytes(is, -1);
is.close();
return bytes;
}




Expand Down
4 changes: 2 additions & 2 deletions sources/net.sf.j2s.java.core/src/swingjs/xml/JSJAXBClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import javax.xml.namespace.QName;

import javajs.util.PT;
import swingjs.JSUtil;
import javajs.util.Rdr;
import swingjs.api.Interface;

class JSJAXBClass implements Cloneable {
Expand Down Expand Up @@ -113,7 +113,7 @@ private static void getPackageInfo(Class<?> javaClass) {
if (is != null) {
String data;
try {
data = JSUtil.streamToString(is);
data = Rdr.streamToString(is);
packageAccessorType = parseAccessorType(data);
data = PT.getQuotedAttribute(data, "namespace");
if (data != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void parse(InputSource source, DefaultHandler handler) throws SAXExceptio
private String getString(InputSource source) throws IOException {
Reader rdr = source.getCharacterStream();
if (rdr == null) {
return Rdr.fixUTF(JSUtil.streamToBytes(source.getByteStream()));
return Rdr.fixUTF(Rdr.streamToBytes(source.getByteStream()));
}
if (!(rdr instanceof BufferedReader))
rdr = new BufferedReader(rdr);
Expand Down
5 changes: 3 additions & 2 deletions sources/net.sf.j2s.java.core/src/test/Test_JSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.List;
import java.util.Map;

import javajs.util.Rdr;
import swingjs.JSUtil;

public class Test_JSON extends Test_ {
Expand Down Expand Up @@ -43,7 +44,7 @@ public static void main(String[] args) {
* data = data["1cbs"][0].title;
*/
if (data instanceof InputStream) {
data = JSUtil.streamToString((InputStream) data);
data = Rdr.streamToString((InputStream) data);
}
System.out.println(data);

Expand All @@ -52,7 +53,7 @@ public static void main(String[] args) {
JSUtil.setAjax(url);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
data = connection.getInputStream();
data = JSUtil.streamToString((InputStream) data);
data = Rdr.streamToString((InputStream) data);
System.out.println(data);


Expand Down
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.java.core/src/test/Test_URL.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static void main(String[] args) {
connection.setReadTimeout(10000);

InputStream is = url.openStream();
String s = JSUtil.streamToString(is);
String s = Rdr.streamToString(is);
is.close();
System.out.println(s);
assert (s.equals("{\"ping\":1}\n"));
Expand Down