I have a Java system like this: /** * Returns an image specified at the path on the…
Private research annotation
Sign in to add a private research label or note.
- User
I have a Java system like this:
code/** * Returns an image specified at the path on the current texture pack, or if it's missing, the texture on the default texture pack. * * @param path texture path * @return image at the specified path on the current texture pack, or the default image if missing */ public static BufferedImage loadImage(String path) { try { return ImageIO.read(getResource(path)); } catch(IOException e) { System.err.println("Failed to load image at " + path + ". Loading from default texture pack"); e.printStackTrace(); try { return ImageIO.read(new File(DEFAULT_RESOURCE_PACK_FOLDER + path)); } catch(IOException e1) { System.err.println("Failed to load image at " + path + " from default texture pack. Loading from internal resource"); e1.printStackTrace(); try { return ImageIO.read(FileUtils.getInternalResource(path)); } catch(IOException e2) { System.err.println("thats not supposed to happen"); e2.printStackTrace(); return GLTexture.TEST_IMAGE; } } } } /** * Reads a resource as a {@link JsonObject}. Returns the default {@link JsonObject} if failed. * * @param path path to the file * @return string representation of the resource */ public static JsonObject getResourceAsJSON(String path) { try { return JsonUtils.parse(FileUtils.loadAsString(getResource(path))); } catch(JsonParseException e) { System.err.println("Failed to parse JSON at " + path + ". Loading from default texture pack"); e.printStackTrace(); try { return JsonUtils.parse(FileUtils.loadAsString(new File(DEFAULT_RESOURCE_PACK_FOLDER + path))); } catch(JsonParseException | FileNotFoundException e1) { System.err.println("Failed to parse JSON at " + path + " from default texture pack. Loading from internal resource"); e1.printStackTrace(); try { return JsonUtils.parse(FileUtils.getInternalResourceAsString(path)); } catch(JsonParseException e2) { System.err.println("thats not supposed to happen"); e2.printStackTrace(); return null; } } } } - Assistant