MCPcopy Index your code
hub / github.com/benfry/processing4 / createInputRaw

Method createInputRaw

core/src/processing/core/PApplet.java:6348–6495  ·  view source on GitHub ↗

Call openStream() without automatic gzip decompression.

(String filename)

Source from the content-addressed store, hash-verified

6346 * Call openStream() without automatic gzip decompression.
6347 */
6348 public InputStream createInputRaw(String filename) {
6349 if (filename == null) return null;
6350
6351 if (sketchPath == null) {
6352 System.err.println("The sketch path is not set.");
6353 throw new RuntimeException("Files must be loaded inside setup() or after it has been called.");
6354 }
6355
6356 if (filename.length() == 0) {
6357 // an error will be called by the parent function
6358 //System.err.println("The filename passed to openStream() was empty.");
6359 return null;
6360 }
6361
6362 // First check whether this looks like a URL
6363 if (filename.contains(":")) { // at least smells like URL
6364 try {
6365 URL url = new URL(filename);
6366 URLConnection conn = url.openConnection();
6367
6368 if (conn instanceof HttpURLConnection httpConn) {
6369 // Will not handle a protocol change (see below)
6370 httpConn.setInstanceFollowRedirects(true);
6371 int response = httpConn.getResponseCode();
6372 // Default won't follow HTTP -> HTTPS redirects for security reasons
6373 // http://stackoverflow.com/a/1884427
6374 if (response >= 300 && response < 400) {
6375 String newLocation = httpConn.getHeaderField("Location");
6376 return createInputRaw(newLocation);
6377 }
6378 return conn.getInputStream();
6379 } else if (conn instanceof JarURLConnection) {
6380 return url.openStream();
6381 }
6382 } catch (MalformedURLException mfue) {
6383 // not a URL, that's fine
6384
6385 } catch (FileNotFoundException fnfe) {
6386 // Added in 0119 b/c Java 1.5 throws FNFE when URL not available.
6387 // https://download.processing.org/bugzilla/403.html
6388
6389 } catch (IOException e) {
6390 // changed for 0117, shouldn't be throwing exception
6391 printStackTrace(e);
6392 //System.err.println("Error downloading from URL " + filename);
6393 return null;
6394 //throw new RuntimeException("Error downloading from URL " + filename);
6395 }
6396 }
6397
6398 InputStream stream;
6399
6400 // Moved this earlier than the getResourceAsStream() checks, because
6401 // calling getResourceAsStream() on a directory lists its contents.
6402 // https://download.processing.org/bugzilla/716.html
6403 try {
6404 // First see if it's in a data folder. This may fail by throwing
6405 // a SecurityException. If so, this whole block will be skipped.

Callers 2

createInputMethod · 0.95
saveStreamMethod · 0.95

Calls 9

printStackTraceMethod · 0.95
dataPathMethod · 0.95
sketchFileMethod · 0.95
sketchPathMethod · 0.95
getClassLoaderMethod · 0.80
printlnMethod · 0.45
containsMethod · 0.45
getNameMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected