Thanks to visit codestin.com
Credit goes to github.com

Skip to content

SimpleHTTPClient and j2sClazz new String TextDecoder #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 28, 2021
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 @@
20210720163506
20210728102503
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 @@
20210720163506
20210728102503
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
34 changes: 20 additions & 14 deletions sources/net.sf.j2s.java.core/src/javajs/http/SimpleHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,22 +287,28 @@ public HttpRequest clearFormParts(String name) {
}

private byte[] toBytes(Object data) {
try {
if (data == null || data instanceof byte[]) {
} else if (data instanceof File) {
FileInputStream fis = new FileInputStream((File) data);
data = getBytes(fis);
fis.close();
} else if (data instanceof InputStream) {
InputStream is = (InputStream) data;
data = getBytes(is);
is.close();
} else {
data = data.toString().getBytes();
if (data == null || data instanceof byte[]) {
return (byte[]) data;
}
if (data instanceof File) {
try (FileInputStream fis = new FileInputStream((File) data)) {
return getBytes(fis);
}
catch (IOException e) {
e.printStackTrace();
return null;
}
}
if (data instanceof InputStream) {
try (InputStream is = (InputStream) data) {
return getBytes(is);
}
catch (IOException e) {
e.printStackTrace();
return null;
}
} catch (IOException e) {
}
return (byte[]) data;
return data.toString().getBytes();
}

@Override
Expand Down
77 changes: 58 additions & 19 deletions sources/net.sf.j2s.java.core/src/test/Test_String.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ public class Test_String extends Test_ {

public static void main(String[] args) {

System.out.println("abcde".indexOf(99));
String sb = new String(new byte[] { 97, 98, 99 });
System.out.println(sb);
assert (sb.equals("abc"));
sb = new String(new byte[] { 97, 98, 99 }, 1, 2);
System.out.println(sb);
assert (sb.equals("bc"));
assert("abcde".indexOf(99) == 2);
assert ("test".contentEquals(new StringBuffer("test")));
int ii = "test\2ing".charAt(4);
switch (ii | 'd') {
Expand All @@ -22,32 +28,61 @@ public static void main(String[] args) {
assert (false);
}

CharBuffer cb = CharBuffer.allocate(10);
CharBuffer cb = CharBuffer.allocate(4);
cb.mark();
cb.put('a');
cb.put('b');
cb.put('c');

String sb = new String(new byte[] { 97, 98, 99 });
System.out.println(sb);
assert (sb.equals("abc"));

cb.reset();
StringBuffer sbb;
sbb = new StringBuffer("testing");
sbb.insert(0, cb);

System.out.println(sbb);
assert(sbb.toString().equals("abc\0testing"));
System.out.println(">" + cb.toString() + "<");
cb.reset();
cb.position(2);
System.out.println(">" + cb.toString() + "<");
assert(cb.toString().equals("c\0"));
sbb = new StringBuffer("testing");
sbb.insert(0, cb);

sbb.insert(3, cb, 0, 1);
System.out.println(sbb);

assert(sbb.toString().equals("tescting"));
sb = "ab\u2520c";
System.out.println(sb);
try {
byte[] b = sb.getBytes("UTF-8");
String s = "" + b[2] + b[3] + b[4];
System.out.println(s);
assert(s.equals("-30-108-96"));
s = new String(b, "UTF-8");
System.out.println(s);
assert(s.equals(sb));
b = sb.getBytes("UTF8"); // no BOM

b = sb.getBytes("UTF-16BE"); // no BOM
s = "" + b[2] + b[3] + b[4];
System.out.println(s);
assert(s.equals("09837"));
s = new String(b, "UTF-16BE");
System.out.println(s);
assert(s.equals(sb));

b = sb.getBytes("UTF-16"); // includes BOM -2, -1
s = "" + b[2] + b[3] + b[4];
System.out.println(s);
assert(s.equals("0970"));
s = new String(b, "UTF-16");
System.out.println(s);
assert(s.equals(sb));

b = sb.getBytes("UTF-16LE"); // no BOM
s = "" + b[2] + b[3] + b[4];
System.out.println(s);
assert(s.equals("98032"));
s = new String(b, "UTF-16LE");
System.out.println(s);
assert(s.equals(sb));

} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down Expand Up @@ -81,16 +116,18 @@ public static void main(String[] args) {
for (int j = 0; j < n; j++)
s += i;
}
System.out.println("ms " + (System.currentTimeMillis() - t0) + "\t s+= len=" + s.length());

System.out.println("\nms " + (System.currentTimeMillis() - t0) + "\t s+= len=" + s.length());
System.out.println("java : ms 14825 s+= len=388900");

t0 = System.currentTimeMillis();
StringBuffer Sb = new StringBuffer();
for (int i = 0; i < 10000; i++) {
for (int j = 0; j < 100; j++)
Sb.append(i);
}
s = Sb.toString();
System.out.println("ms " + (System.currentTimeMillis() - t0) + "\t one StringBuffer len=" + s.length());
System.out.println("\nms " + (System.currentTimeMillis() - t0) + "\t one StringBuffer len=" + s.length());
System.out.println("java : ms 91 one StringBuffer len=3889000");

t0 = System.currentTimeMillis();
StringBuilder S = new StringBuilder();
Expand All @@ -99,7 +136,8 @@ public static void main(String[] args) {
S.append(i);
}
s = S.toString();
System.out.println("ms " + (System.currentTimeMillis() - t0) + "\t one StringBuilder len=" + s.length());
System.out.println("\nms " + (System.currentTimeMillis() - t0) + "\t one StringBuilder len=" + s.length());
System.out.println("java : ms 76 one StringBuilder len=3889000");

t0 = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
Expand All @@ -109,8 +147,8 @@ public static void main(String[] args) {
}
s = SB.toString();
}
System.out.println("ms " + (System.currentTimeMillis() - t0) + "\t many StringBuilder len=" + s.length());

System.out.println("\nms " + (System.currentTimeMillis() - t0) + "\t many StringBuilder len=" + s.length());
System.out.println("java : ms 76 many StringBuilder len=400");

t0 = System.currentTimeMillis();
SB b = new SB();
Expand All @@ -119,7 +157,8 @@ public static void main(String[] args) {
b.appendI(i);
}
s = b.toString();
System.out.println("ms " + (System.currentTimeMillis() - t0) + "\t javajs.util.SB len=" + s.length());
System.out.println("\nms " + (System.currentTimeMillis() - t0) + "\t javajs.util.SB len=" + s.length());
System.out.println("java : ms 85 javajs.util.SB len=3889000");

//Output prior to optimization of AbstractStringBuilder:
//
Expand Down
24 changes: 24 additions & 0 deletions sources/net.sf.j2s.java.core/srcjs/js/devnotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@ j2sClazz and j2sApplet older development notes
j2sClazz.js (formerly j2s.lib.js)
-----------

// BH 2020.12.31 3.3.1-v1 full 64-bit long support; BigDecimal, BigInteger fully 64-bit

// BH 2020.12.19 3.2.10-v1 preliminary work aiming to back long with [r,m,s].
// should be fully backward compatible;
// supports the 3.2.10 transpiler.
// BH 2020.12.11 fixing interface extended override of interface default
// BH 2020.12.06 changing Long maxval to 0x1FFFFFFFFFFFFF from 0x20000000000000
// BH 2020.12.06 better error checking for TYPE.parseTYPE(string)
// BH 2020.07.27 fix for inner class array names
// BH 2020.06.18 better test for instanceof Object[]
// BH 2020.06.03 sets user.home and user.dir to /TEMP/swingjs, and user.name to "swingjs"
// BH 2020.04.01 2.2.0-v1e fixes missing C$.superclazz when class loaded from core
// BH 2020.03.19 3.2.9-v1c fixes new String("xxx") !== "xxx"
// BH 2020.03.11 3.2.9-v1b fixes numerous subtle issues with boxed primitives Integer, Float, etc.
// BH 2020.03.07 3.2.9-v1a fixes array.hashCode() to be System.identityHashCode(array).
// BH 2020.02.18 3.2.8-v2 upgrades String, Integer, ClassLoader, Package, various Exceptions
// BH 2020.02.12 3.2.8-v1 new Throwable().getStackTrace() should not include j2sClazz methods
// BH 2020.02.02 3.2.7-v5 fixes array.getClass().getName() and getArrayClass() for short -- should be [S, not [H, for Java
// BH 2019.12.29 3.2.6 fixes Float.parseFloat$S("NaN") [and Double]
// BH 2019.12.23 3.2.6 update of System
// BH 2019.12.19 3.2.6 revision of $clinit$
// BH 2019.12.16 3.2.5-v4 adds ClassLoader static methods for system resources (just j2s/...)
// BH 2019.12.15 3.2.5-v4 Character.prototype.valueOf() missing
// BH 2019.12.14 3.2.5-v3 Clazz._4Name initialization should be full static initialization
// BH 2019.12.03 3.2.5.v2 Object.class instanceof java.lang.Class
// BH 2019.11.26 3.2.5.v1 errant if (args) in newInstance
// BH 2019.11.07 3.2.5.v0 full encapsulation
Expand Down
Loading