(String path)
| 2364 | } |
| 2365 | |
| 2366 | public static ByteBuffer openAsByteBuffer(String path) { |
| 2367 | if (path==null || path.equals("")) { |
| 2368 | OpenDialog od = new OpenDialog("Open as ByteBuffer", ""); |
| 2369 | String directory = od.getDirectory(); |
| 2370 | String name = od.getFileName(); |
| 2371 | if (name==null) return null; |
| 2372 | path = directory + name; |
| 2373 | } |
| 2374 | File file = new File(path); |
| 2375 | if (!file.exists()) { |
| 2376 | error("OpenAsByteBuffer", "File not found"); |
| 2377 | return null; |
| 2378 | } |
| 2379 | int len = (int)file.length(); |
| 2380 | byte[] buffer = new byte[len]; |
| 2381 | try { |
| 2382 | InputStream in = new BufferedInputStream(new FileInputStream(path)); |
| 2383 | DataInputStream dis = new DataInputStream(in); |
| 2384 | dis.readFully(buffer); |
| 2385 | dis.close(); |
| 2386 | } |
| 2387 | catch (Exception e) { |
| 2388 | error("OpenAsByteBuffer", e.getMessage()); |
| 2389 | return null; |
| 2390 | } |
| 2391 | return ByteBuffer.wrap(buffer); |
| 2392 | } |
| 2393 | |
| 2394 | /** Creates a new image. |
| 2395 | * @param title image name |
nothing calls this directly
no test coverage detected