Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8ca4918

Browse files
author
zhourenjian@gmail.com
committed
Use Charset object instead of charset string and upper case UTF-8 to avoid a Java bottleneck
1 parent78f29bc commit8ca4918

File tree

6 files changed

+50
-37
lines changed

6 files changed

+50
-37
lines changed

‎sources/net.sf.j2s.ajax/ajaxcore/net/sf/j2s/ajax/HttpRequest.java‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
importjava.io.UnsupportedEncodingException;
2121
importjava.net.HttpURLConnection;
2222
importjava.net.URL;
23+
importjava.nio.charset.Charset;
2324
importjava.util.Iterator;
2425
importjava.util.List;
2526
importjava.util.Map;
@@ -137,6 +138,9 @@ public static interface IXHRReceiving {
137138

138139
publicstaticStringDEFAULT_USER_AGENT ="Java2Script/2.0.2";
139140

141+
protectedstaticCharsetUTF_8 =Charset.forName("UTF-8");
142+
protectedstaticCharsetISO_8859_1 =Charset.forName("ISO-8859-1");
143+
140144
protectedintstatus;
141145
protectedStringstatusText;
142146
protectedintreadyState;
@@ -220,18 +224,21 @@ public String getResponseText() {
220224
}
221225
}
222226
if (charset !=null) {
223-
try {
224-
responseText =baos.toString(charset);
225-
}catch (UnsupportedEncodingExceptione) {
227+
if ("UTF-8".equalsIgnoreCase(charset)) {
228+
responseText =newString (baos.toByteArray(),UTF_8);
229+
}elseif ("ISO-8859-1".equalsIgnoreCase(charset)) {
230+
responseText =newString (baos.toByteArray(),ISO_8859_1);
231+
}else {
232+
try {
233+
responseText =baos.toString(charset);
234+
}catch (UnsupportedEncodingExceptione) {
235+
responseText =baos.toString();
236+
}
226237
}
227238
}
228239
}
229240
if (responseText ==null) {
230-
try {
231-
responseText =baos.toString("iso-8859-1");
232-
}catch (UnsupportedEncodingExceptione) {
233-
responseText =baos.toString();
234-
}
241+
responseText =newString (baos.toByteArray(),ISO_8859_1);
235242
}
236243
returnresponseText;
237244
}
@@ -264,7 +271,7 @@ public Document getResponseXML() {
264271
dbf.setAttribute("http://xml.org/sax/features/namespaces",Boolean.TRUE);
265272
try {
266273
DocumentBuilderdb =dbf.newDocumentBuilder();
267-
ByteArrayInputStreambiStream =newByteArrayInputStream(responseContent.getBytes("utf-8"));
274+
ByteArrayInputStreambiStream =newByteArrayInputStream(responseContent.getBytes(UTF_8));
268275
responseXML =db.parse(biStream);
269276
}catch (Exceptione) {
270277
e.printStackTrace();

‎sources/net.sf.j2s.ajax/ajaxpipe/net/sf/j2s/ajax/SimplePipeHttpServlet.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ protected void doPipe(final HttpServletResponse resp, String key, char type, Str
152152
* Client send in "notify" request to execute #notifyPipeStatus, see below comments
153153
*/
154154
booleanupdated =SimplePipeHelper.notifyPipeStatus(key,true);// update it!
155-
resp.setContentType("text/javascript; charset=utf-8");
155+
resp.setContentType("text/javascript; charset=UTF-8");
156156
writer =resp.getWriter();
157157
writer.write("$p1p3b$ (\"");// $p1p3b$ = net.sf.j2s.ajax.SimplePipeRequest.pipeNotifyCallBack
158158
writer.write(key);
@@ -162,7 +162,7 @@ protected void doPipe(final HttpServletResponse resp, String key, char type, Str
162162
return;
163163
}
164164
if (SimplePipeRequest.PIPE_TYPE_SUBDOMAIN_QUERY ==type) {// subdomain query
165-
resp.setContentType("text/html; charset=utf-8");
165+
resp.setContentType("text/html; charset=UTF-8");
166166
writer =resp.getWriter();
167167
StringBuilderbuilder =newStringBuilder();
168168
builder.append("<html><head><title></title></head><body>\r\n");
@@ -196,7 +196,7 @@ protected void doPipe(final HttpServletResponse resp, String key, char type, Str
196196
}
197197
booleanisScripting =SimplePipeRequest.PIPE_TYPE_SCRIPT ==type;
198198
if (isScripting) {// iframe
199-
resp.setContentType("text/html; charset=utf-8");
199+
resp.setContentType("text/html; charset=UTF-8");
200200
writer =resp.getWriter();
201201
StringBuilderbuilder =newStringBuilder();
202202
builder.append("<html><head><title></title></head><body>\r\n");
@@ -213,9 +213,9 @@ protected void doPipe(final HttpServletResponse resp, String key, char type, Str
213213
writer.flush();
214214
}else {
215215
if (SimplePipeRequest.PIPE_TYPE_QUERY ==type ||isContinuum) {
216-
resp.setContentType("text/plain; charset=utf-8");
216+
resp.setContentType("text/plain; charset=UTF-8");
217217
}else {
218-
resp.setContentType("text/javascript; charset=utf-8");
218+
resp.setContentType("text/javascript; charset=UTF-8");
219219
}
220220
writer =resp.getWriter();
221221
}

‎sources/net.sf.j2s.ajax/ajaxrpc/net/sf/j2s/ajax/SimpleRPCHttpServlet.java‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
264264
resp.setHeader("Pragma","no-cache");
265265
resp.setHeader("Cache-Control","no-cache");
266266
resp.setDateHeader("Expires",0);
267-
resp.setContentType("text/plain; charset=utf-8");
268-
//resp.setCharacterEncoding("utf-8");
267+
resp.setContentType("text/plain; charset=UTF-8");
268+
//resp.setCharacterEncoding("UTF-8");
269269
PrintWriterwriter =resp.getWriter();
270270
SimpleRPCRunnableclonedRunnable =null;
271271
try {
@@ -370,8 +370,8 @@ public boolean ignoreDefaultFields() {
370370
resp.setDateHeader("Expires",0);
371371

372372
if (isScriptReuest) {// cross site script response
373-
resp.setContentType("text/javascript; charset=utf-8");
374-
//resp.setCharacterEncoding("utf-8");
373+
resp.setContentType("text/javascript; charset=UTF-8");
374+
//resp.setCharacterEncoding("UTF-8");
375375
PrintWriterwriter =resp.getWriter();
376376
writer.write("net.sf.j2s.ajax.SimpleRPCRequest.xssNotify(");
377377
writer.write("\"" +requestID +"\",\"");
@@ -385,8 +385,8 @@ public boolean ignoreDefaultFields() {
385385
}
386386

387387
// normal text response
388-
resp.setContentType("text/plain; charset=utf-8");
389-
//resp.setCharacterEncoding("utf-8");
388+
resp.setContentType("text/plain; charset=UTF-8");
389+
//resp.setCharacterEncoding("UTF-8");
390390
PrintWriterwriter =resp.getWriter();
391391
writer.write(serialize);
392392
runnable.ajaxOut();
@@ -404,7 +404,7 @@ private String prepareScriptRequest(HttpServletRequest req, HttpServletResponse
404404
// make sure that servlet support cross site script request
405405
if (!supportXSSRequest()) {
406406
resp.setContentType("text/javascript");
407-
//resp.setCharacterEncoding("utf-8");
407+
//resp.setCharacterEncoding("UTF-8");
408408
resp.getWriter().write("net.sf.j2s.ajax.SimpleRPCRequest" +
409409
".xssNotify(\"" +scriptRequestID +"\",\"unsupported\");");
410410
returnnull;
@@ -436,7 +436,7 @@ private String prepareScriptRequest(HttpServletRequest req, HttpServletResponse
436436
// check whether servlet can deal the requests
437437
if (partsCount >maxXSSRequestParts()) {
438438
resp.setContentType("text/javascript");
439-
//resp.setCharacterEncoding("utf-8");
439+
//resp.setCharacterEncoding("UTF-8");
440440
resp.getWriter().write("net.sf.j2s.ajax.SimpleRPCRequest" +
441441
".xssNotify(\"" +scriptRequestID +"\",\"exceedrequestlimit\");");
442442
returnnull;
@@ -488,7 +488,7 @@ private String prepareScriptRequest(HttpServletRequest req, HttpServletResponse
488488
}
489489
if (toContinue) {
490490
resp.setContentType("text/javascript");
491-
//resp.setCharacterEncoding("utf-8");
491+
//resp.setCharacterEncoding("UTF-8");
492492
resp.getWriter().write("net.sf.j2s.ajax.SimpleRPCRequest" +
493493
".xssNotify(\"" +scriptRequestID +"\",\"continue\"" +
494494
((curPart ==1) ?",\"" +session.getId() +"\");" :");"));

‎sources/net.sf.j2s.ajax/ajaxrpc/net/sf/j2s/ajax/SimpleSerializable.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ public class SimpleSerializable implements Cloneable {
6868
privatestaticSet<String>classMissed =newHashSet<String>();
6969

7070
@J2SIgnore
71-
protectedstaticCharsetUTF_8 =Charset.forName("utf-8");
71+
publicstaticCharsetUTF_8 =Charset.forName("UTF-8");
7272

7373
@J2SIgnore
74-
protectedstaticCharsetISO_8859_1 =Charset.forName("iso-8859-1");
74+
publicstaticCharsetISO_8859_1 =Charset.forName("ISO-8859-1");
7575

7676
privateintsimpleVersion;
7777

‎sources/net.sf.j2s.ajax/generator/net/sf/j2s/ajax/SimpleSource4ObjectiveC.java‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class SimpleSource4ObjectiveC {
3535
staticStringauthor ="Author";
3636
staticStringcompany ="Company";
3737
staticStringconstantPrefix ="C_";
38-
38+
staticbooleansupportsARC =false;
3939

4040
privatestaticStringwrapString(Strings) {
4141
if (s ==null) {
@@ -894,10 +894,15 @@ public static String generateImplementation(SimpleSerializable s) {
894894
@SuppressWarnings("deprecation")
895895
publicstaticvoidmain(String[]args) {
896896
if (args ==null ||args.length <2 +3) {
897-
System.out.println("Usage: " +SimpleSource4ObjectiveC.class.getName() +" <sources folder> <author> <orgization or company> <constant prefix> <factory name> <class> [class ...]");
897+
System.out.println("Usage: " +SimpleSource4ObjectiveC.class.getName() +"[--arc] <sources folder> <author> <orgization or company> <constant prefix> <factory name> <class> [class ...]");
898898
return;
899899
}
900-
StringtargetFolder =args[0];
900+
intindexStarting =0;
901+
if ("--arc".equals(args[0])) {
902+
supportsARC =true;
903+
indexStarting =1;
904+
}
905+
StringtargetFolder =args[indexStarting];
901906
Filef =newFile(targetFolder);
902907
if (f.exists()) {
903908
if (!f.isDirectory()) {
@@ -912,12 +917,13 @@ public static void main(String[] args) {
912917
}
913918
}
914919
folder =f.getName();
915-
author =args[1];
916-
company =args[2];
917-
constantPrefix =args[3];
920+
author =args[indexStarting +1];
921+
company =args[indexStarting +2];
922+
constantPrefix =args[indexStarting +3];
918923

919-
StringfactoryClazz =args[4];
920-
for (inti =1 +4;i <args.length;i++) {
924+
StringfactoryClazz =args[indexStarting +4];
925+
intclassStartingIndex =indexStarting +5;
926+
for (inti =classStartingIndex;i <args.length;i++) {
921927
Stringj2sSimpleClazz =args[i];
922928
try {
923929
Class<?>clazz =Class.forName(j2sSimpleClazz);
@@ -985,7 +991,7 @@ public static void main(String[] args) {
985991
source.append("#import\"SimpleFactory.h\"\r\n");
986992
source.append("\r\n");
987993

988-
for (inti =1 +4;i <args.length;i++) {
994+
for (inti =classStartingIndex;i <args.length;i++) {
989995
Stringj2sSimpleClazz =args[i];
990996
try {
991997
Class<?>clazz =Class.forName(j2sSimpleClazz);
@@ -1066,7 +1072,7 @@ public static void main(String[] args) {
10661072
source.append("- (id) createInstanceByClassName:(NSString *) className {\r\n");
10671073
SourceUtils.insertLineComment(source,"\t",index++,false);
10681074

1069-
for (inti =1 +4;i <args.length;i++) {
1075+
for (inti =classStartingIndex;i <args.length;i++) {
10701076
Stringj2sSimpleClazz =args[i];
10711077
try {
10721078
Class<?>clazz =Class.forName(j2sSimpleClazz);
@@ -1135,7 +1141,7 @@ public static void main(String[] args) {
11351141
source.append("- (id) getClassFullName:(NSString *) className {\r\n");
11361142
SourceUtils.insertLineComment(source,"\t",index++,false);
11371143

1138-
for (inti =1 +4;i <args.length;i++) {
1144+
for (inti =classStartingIndex;i <args.length;i++) {
11391145
Stringj2sSimpleClazz =args[i];
11401146
try {
11411147
Class<?>clazz =Class.forName(j2sSimpleClazz);

‎sources/net.sf.j2s.ajax/generator/net/sf/j2s/ajax/SourceUtils.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public static void updateSourceContent(File file, String source) {
188188
FileOutputStreamfos =null;
189189
try {
190190
fos =newFileOutputStream(file);
191-
fos.write(source.getBytes("utf-8"));
191+
fos.write(source.getBytes("UTF-8"));
192192
}catch (IOExceptione) {
193193
e.printStackTrace();
194194
}finally {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp