Call openStream() without automatic gzip decompression.
(String filename)
| 7126 | * Call openStream() without automatic gzip decompression. |
| 7127 | */ |
| 7128 | public InputStream createInputRaw(String filename) { |
| 7129 | if (filename == null) return null; |
| 7130 | |
| 7131 | if (sketchPath == null) { |
| 7132 | System.err.println("The sketch path is not set."); |
| 7133 | throw new RuntimeException("Files must be loaded inside setup() or after it has been called."); |
| 7134 | } |
| 7135 | |
| 7136 | if (filename.length() == 0) { |
| 7137 | // an error will be called by the parent function |
| 7138 | //System.err.println("The filename passed to openStream() was empty."); |
| 7139 | return null; |
| 7140 | } |
| 7141 | |
| 7142 | // First check whether this looks like a URL |
| 7143 | if (filename.contains(":")) { // at least smells like URL |
| 7144 | try { |
| 7145 | URL url = new URL(filename); |
| 7146 | URLConnection conn = url.openConnection(); |
| 7147 | |
| 7148 | if (conn instanceof HttpURLConnection) { |
| 7149 | HttpURLConnection httpConn = (HttpURLConnection) conn; |
| 7150 | // Will not handle a protocol change (see below) |
| 7151 | httpConn.setInstanceFollowRedirects(true); |
| 7152 | int response = httpConn.getResponseCode(); |
| 7153 | // Default won't follow HTTP -> HTTPS redirects for security reasons |
| 7154 | // http://stackoverflow.com/a/1884427 |
| 7155 | if (response >= 300 && response < 400) { |
| 7156 | String newLocation = httpConn.getHeaderField("Location"); |
| 7157 | return createInputRaw(newLocation); |
| 7158 | } |
| 7159 | return conn.getInputStream(); |
| 7160 | } else if (conn instanceof JarURLConnection) { |
| 7161 | return url.openStream(); |
| 7162 | } |
| 7163 | } catch (MalformedURLException mfue) { |
| 7164 | // not a url, that's fine |
| 7165 | |
| 7166 | } catch (FileNotFoundException fnfe) { |
| 7167 | // Added in 0119 b/c Java 1.5 throws FNFE when URL not available. |
| 7168 | // http://dev.processing.org/bugs/show_bug.cgi?id=403 |
| 7169 | |
| 7170 | } catch (IOException e) { |
| 7171 | // changed for 0117, shouldn't be throwing exception |
| 7172 | printStackTrace(e); |
| 7173 | //System.err.println("Error downloading from URL " + filename); |
| 7174 | return null; |
| 7175 | //throw new RuntimeException("Error downloading from URL " + filename); |
| 7176 | } |
| 7177 | } |
| 7178 | |
| 7179 | InputStream stream = null; |
| 7180 | |
| 7181 | // Moved this earlier than the getResourceAsStream() checks, because |
| 7182 | // calling getResourceAsStream() on a directory lists its contents. |
| 7183 | // http://dev.processing.org/bugs/show_bug.cgi?id=716 |
| 7184 | try { |
| 7185 | // First see if it's in a data folder. This may fail by throwing |
no test coverage detected