Skip to content

Commit 6a089b3

Browse files
committed
ported fix from PApplet, added printStackTrace()
1 parent 93fd886 commit 6a089b3

File tree

1 file changed

+32
-21
lines changed

1 file changed

+32
-21
lines changed

core/src/processing/core/PApplet.java

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,17 +1508,17 @@ protected PGraphics makeGraphics(int w, int h,
15081508
try {
15091509
pg = (PGraphics) constructor.newInstance();
15101510
} catch (InvocationTargetException e) {
1511-
e.printStackTrace();
1511+
printStackTrace(e);
15121512
throw new RuntimeException(e.getMessage());
15131513
} catch (IllegalAccessException e) {
1514-
e.printStackTrace();
1514+
printStackTrace(e);
15151515
throw new RuntimeException(e.getMessage());
15161516
} catch (InstantiationException e) {
1517-
e.printStackTrace();
1517+
printStackTrace(e);
15181518
throw new RuntimeException(e.getMessage());
15191519
} catch (IllegalArgumentException e) {
15201520
// TODO Auto-generated catch block
1521-
e.printStackTrace();
1521+
printStackTrace(e);
15221522
}
15231523
}
15241524
}
@@ -2716,7 +2716,6 @@ static public Process exec(String[] argv) {
27162716
try {
27172717
return Runtime.getRuntime().exec(argv);
27182718
} catch (Exception e) {
2719-
e.printStackTrace();
27202719
throw new RuntimeException("Could not open " + join(argv, ' '));
27212720
}
27222721
}
@@ -2725,6 +2724,15 @@ static public Process exec(String[] argv) {
27252724
//////////////////////////////////////////////////////////////
27262725

27272726

2727+
/**
2728+
* Better way of handling e.printStackTrace() calls so that they can be
2729+
* handled by subclasses as necessary.
2730+
*/
2731+
protected void printStackTrace(Throwable t) {
2732+
t.printStackTrace();
2733+
}
2734+
2735+
27282736
/**
27292737
* Function for an applet/application to kill itself and
27302738
* display an error. Mostly this is here to be improved later.
@@ -2823,16 +2831,16 @@ public void method(String name) {
28232831
method.invoke(this, new Object[] { });
28242832

28252833
} catch (IllegalArgumentException e) {
2826-
e.printStackTrace();
2834+
printStackTrace(e);
28272835
} catch (IllegalAccessException e) {
2828-
e.printStackTrace();
2836+
printStackTrace(e);
28292837
} catch (InvocationTargetException e) {
28302838
e.getTargetException().printStackTrace();
28312839
} catch (NoSuchMethodException nsme) {
28322840
System.err.println("There is no public " + name + "() method " +
28332841
"in the class " + getClass().getName());
28342842
} catch (Exception e) {
2835-
e.printStackTrace();
2843+
printStackTrace(e);
28362844
}
28372845
}
28382846

@@ -3959,7 +3967,7 @@ public XML createXML(String name) {
39593967
try {
39603968
return new XML(name);
39613969
} catch (Exception e) {
3962-
e.printStackTrace();
3970+
printStackTrace(e);
39633971
return null;
39643972
}
39653973
}
@@ -3983,7 +3991,7 @@ public XML loadXML(String filename, String options) {
39833991
try {
39843992
return new XML(createInput(filename), options);
39853993
} catch (Exception e) {
3986-
e.printStackTrace();
3994+
printStackTrace(e);
39873995
return null;
39883996
}
39893997
}
@@ -3998,7 +4006,7 @@ public XML parseXML(String xmlString, String options) {
39984006
try {
39994007
return XML.parse(xmlString, options);
40004008
} catch (Exception e) {
4001-
e.printStackTrace();
4009+
printStackTrace(e);
40024010
return null;
40034011
}
40044012
}
@@ -4145,7 +4153,7 @@ public Table loadTable(String filename, String options) {
41454153
return new Table(createInput(filename), options);
41464154

41474155
} catch (IOException e) {
4148-
e.printStackTrace();
4156+
printStackTrace(e);
41494157
return null;
41504158
}
41514159
}
@@ -4161,7 +4169,7 @@ public boolean saveTable(Table table, String filename, String options) {
41614169
table.save(saveFile(filename), options);
41624170
return true;
41634171
} catch (IOException e) {
4164-
e.printStackTrace();
4172+
printStackTrace(e);
41654173
}
41664174
return false;
41674175
}
@@ -4681,15 +4689,18 @@ static public PrintWriter createWriter(OutputStream output) {
46814689
*/
46824690
public InputStream createInput(String filename) {
46834691
InputStream input = createInputRaw(filename);
4684-
if ((input != null) && filename.toLowerCase().endsWith(".gz")) {
4692+
final String lower = filename.toLowerCase();
4693+
if ((input != null) &&
4694+
(lower.endsWith(".gz") || lower.endsWith(".svgz"))) {
46854695
try {
4686-
return new GZIPInputStream(input);
4696+
// buffered has to go *around* the GZ, otherwise 25x slower
4697+
return new BufferedInputStream(new GZIPInputStream(input));
46874698
} catch (IOException e) {
4688-
e.printStackTrace();
4699+
printStackTrace(e);
46894700
return null;
46904701
}
46914702
}
4692-
return input;
4703+
return new BufferedInputStream(input);
46934704
}
46944705

46954706

@@ -4746,7 +4757,7 @@ public InputStream createInputRaw(String filename) {
47464757

47474758
} catch (IOException e) {
47484759
// changed for 0117, shouldn't be throwing exception
4749-
e.printStackTrace();
4760+
printStackTrace(e);
47504761
//System.err.println("Error downloading from URL " + filename);
47514762
return null;
47524763
//throw new RuntimeException("Error downloading from URL " + filename);
@@ -4880,9 +4891,9 @@ static public InputStream createInput(File file) {
48804891
try {
48814892
InputStream input = new FileInputStream(file);
48824893
if (file.getName().toLowerCase().endsWith(".gz")) {
4883-
return new GZIPInputStream(input);
4894+
return new BufferedInputStream(new GZIPInputStream(input));
48844895
}
4885-
return input;
4896+
return new BufferedInputStream(input);
48864897

48874898
} catch (IOException e) {
48884899
System.err.println("Could not createInput() for " + file);
@@ -5067,7 +5078,7 @@ public OutputStream createOutput(String filename) {
50675078
return fos;
50685079

50695080
} catch (IOException e) {
5070-
e.printStackTrace();
5081+
printStackTrace(e);
50715082
}
50725083
return null;
50735084
}

0 commit comments

Comments
 (0)