|
5 | 5 | import java.awt.Toolkit; |
6 | 6 | import java.io.BufferedInputStream; |
7 | 7 | import java.io.BufferedReader; |
| 8 | +import java.io.ByteArrayInputStream; |
8 | 9 | import java.io.File; |
9 | 10 | import java.io.IOException; |
10 | 11 | import java.io.InputStream; |
@@ -201,8 +202,30 @@ public static String getJavaResource(String resourceName, boolean isJavaPath, |
201 | 202 | : path.endsWith(".css") ? processCSS(sdata, path) : path |
202 | 203 | .endsWith(".js") ? processJS(sdata, resourceName) : sdata); |
203 | 204 | } |
| 205 | + |
| 206 | + public static InputStream getCachedResourceAsStream(String name) { |
| 207 | + |
| 208 | + |
| 209 | +// , isjavapath false, docachetrue, doprocefalse) |
| 210 | + |
| 211 | + System.out.println("JSUtil getting Java resource " + name); |
| 212 | + String path = J2S.getResourcePath(name, false); |
| 213 | + if (path == null) |
| 214 | + return null; |
| 215 | + InputStream stream; |
| 216 | + Object data = getCachedFileData(path); |
| 217 | + if (data == null) { |
| 218 | + stream = getResourceAsStream(name); |
| 219 | + data = /** @j2sNative stream.$in.buf ||*/null; |
| 220 | + } else { |
| 221 | + stream = new BufferedInputStream(new ByteArrayInputStream((byte[]) data)); |
| 222 | + } |
| 223 | + if (stream != null && useCache) |
| 224 | + cacheFileData(path, data); |
| 225 | + return stream; |
| 226 | + } |
204 | 227 |
|
205 | | - static void cacheFileData(String path, Object data) { |
| 228 | + public static void cacheFileData(String path, Object data) { |
206 | 229 | if (data == null) { |
207 | 230 | System.out.println("JSUtil releasing cached bytes for " + path); |
208 | 231 | getFileCache().remove(path); |
@@ -437,7 +460,8 @@ public static void saveFile(String fileName, Object data, String mimeType, Strin |
437 | 460 | public static InputStream getResourceAsStream(String name) { |
438 | 461 | return Toolkit.getDefaultToolkit().getClass().getClassLoader().getResourceAsStream(name); |
439 | 462 | } |
440 | | - |
| 463 | + |
| 464 | + |
441 | 465 | /** |
442 | 466 | * All classes created by Clazz have static class loaders which are just minimal |
443 | 467 | * objects in Clazz var inF. |
|
0 commit comments