Skip to content

Commit 742c1a4

Browse files
committed
prevent Windows CR problems, also fix encoding for i/o
1 parent 63039a6 commit 742c1a4

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

core/methods/methods.jar

-131 Bytes
Binary file not shown.

core/methods/src/PAppletMethods.java

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void execute() throws BuildException {
3636
throw new BuildException("dir parameter must be set!");
3737
}
3838

39-
System.out.println("using basedir " + baseDir);
39+
//System.out.println("using basedir " + baseDir);
4040
File graphicsFile = new File(baseDir, "PGraphics.java");
4141
File appletFile = new File(baseDir, "PApplet.java");
4242
File imageFile = new File(baseDir, "PImage.java");
@@ -59,17 +59,19 @@ public void execute() throws BuildException {
5959
}
6060

6161
// Looking good, let's do this!
62-
ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
63-
PrintStream out = new PrintStream(outBytes);
62+
//ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
63+
//PrintStream out = new PrintStream(outBytes, "UTF-8");
64+
StringBuffer out = new StringBuffer();
6465
StringBuffer content = new StringBuffer();
6566

6667
try{
6768
BufferedReader applet = createReader(appletFile);
6869
String line;
6970
while ((line = applet.readLine()) != null) {
70-
out.println(line);
71+
out.append(line);
72+
out.append('\n'); // to avoid Windows CRs
7173
content.append(line);
72-
content.append('\n');
74+
content.append('\n'); // for efficiency
7375

7476
if (line.indexOf("public functions for processing.core") >= 0) {
7577
break;
@@ -86,34 +88,38 @@ public void execute() throws BuildException {
8688
process(out, graphicsFile);
8789
process(out, imageFile);
8890

89-
out.println("}");
91+
out.append('}');
92+
out.append('\n');
9093

91-
} catch (IOException e) {
92-
e.printStackTrace();
94+
//} catch (IOException e) {
95+
//e.printStackTrace();
9396

94-
} catch(Exception ex) {
95-
ex.printStackTrace();
97+
} catch (Exception e) {
98+
//ex.printStackTrace();
99+
throw new BuildException(e);
96100
}
97-
out.flush();
101+
//out.flush();
98102

99-
if (content.toString().equals(outBytes.toString())) {
103+
String outString = out.toString();
104+
if (content.toString().equals(outString)) {
100105
System.out.println("No changes to PApplet API.");
101106
} else {
102107
System.out.println("Updating PApplet with API changes " +
103108
"from PImage or PGraphics.");
104109
try {
105-
PrintStream temp = new PrintStream(appletFile);
106-
temp.print(outBytes.toString());
110+
PrintStream temp = new PrintStream(appletFile, "UTF-8");
111+
temp.print(outString);
107112
temp.flush();
108113
temp.close();
109-
} catch (FileNotFoundException e) {
110-
e.printStackTrace();
114+
} catch (IOException e) {
115+
//e.printStackTrace();
116+
throw new BuildException(e);
111117
}
112118
}
113119
}
114120

115121

116-
private void process(PrintStream out, File input) throws IOException {
122+
private void process(StringBuffer out, File input) throws IOException {
117123
BufferedReader in = createReader(input);
118124
int comments = 0;
119125
String line = null;
@@ -184,20 +190,22 @@ private void process(PrintStream out, File input) throws IOException {
184190
line = line.replaceAll(Pattern.quote(";"), " {\n");
185191

186192
//out.println("\n\n" + line);
187-
out.println();
188-
out.println();
193+
out.append('\n');
194+
out.append('\n');
189195
// end has its own newline
190196
//out.print(commentBuffer.toString()); // TODO disabled for now XXXX
191-
out.print(commentBuffer.toString()); // duplicates all comments
197+
out.append(commentBuffer.toString()); // duplicates all comments
192198
commentBuffer.setLength(0);
193-
out.println(line);
199+
out.append(line);
200+
out.append('\n');
194201

195202
decl += line;
196203
while(line.indexOf(')') == -1) {
197204
line = in.readLine();
198205
decl += line;
199206
line = line.replaceAll("\\;\\s*$", " {\n");
200-
out.println(line);
207+
out.append(line);
208+
out.append('\n');
201209
}
202210

203211
result = Pattern.compile(".*?\\s(\\S+)\\(.*?").matcher(decl);
@@ -240,10 +248,13 @@ private void process(PrintStream out, File input) throws IOException {
240248
rline += ");";
241249

242250
if (!gotStatic && returns.equals("")) {
243-
out.println(rline);
251+
out.append(rline);
252+
out.append('\n');
244253
}
245-
out.println(gline);
246-
out.println(" }");
254+
out.append(gline);
255+
out.append('\n');
256+
out.append(" }");
257+
out.append('\n');
247258

248259
} else {
249260
commentBuffer.setLength(0);

0 commit comments

Comments
 (0)