@@ -484,8 +484,7 @@ private void copyImageResource(ImageRef image, Path targetPath) {
484484 String sourcePath = image .sourcePath ().toString ().replace ("stream" , "" );
485485 targetPath .getParent ().toFile ().mkdirs ();
486486
487- try {
488- InputStream in = TtrpgConfig .class .getResourceAsStream (sourcePath );
487+ try (InputStream in = TtrpgConfig .class .getResourceAsStream (sourcePath )) {
489488 Files .copy (in , targetPath , StandardCopyOption .REPLACE_EXISTING );
490489 } catch (IOException e ) {
491490 errorf ("Unable to copy resource. %s" , e );
@@ -505,10 +504,8 @@ private void copyRemoteImage(ImageRef image, Path targetPath) {
505504 return ;
506505 }
507506
508- try {
509- Tui .instance ().debugf ("copy image %s" , url );
510-
511- ReadableByteChannel readableByteChannel = Channels .newChannel (new URL (url ).openStream ());
507+ Tui .instance ().debugf ("copy image %s" , url );
508+ try (ReadableByteChannel readableByteChannel = Channels .newChannel (new URL (url ).openStream ())) {
512509 try (FileOutputStream fileOutputStream = new FileOutputStream (targetPath .toFile ())) {
513510 fileOutputStream .getChannel ().transferFrom (readableByteChannel , 0 , Long .MAX_VALUE );
514511 }
@@ -653,10 +650,10 @@ public <T> T readJsonValue(JsonNode node, Class<T> classTarget) {
653650 }
654651
655652 public static JsonNode readTreeFromResource (String resource ) {
656- try {
653+ try ( InputStream in = TtrpgConfig . class . getResourceAsStream ( resource )) {
657654 return resource .endsWith (".yaml" )
658- ? Tui .yamlMapper ().readTree (TtrpgConfig . class . getResourceAsStream ( resource ) )
659- : Tui .MAPPER .readTree (TtrpgConfig . class . getResourceAsStream ( resource ) );
655+ ? Tui .yamlMapper ().readTree (in )
656+ : Tui .MAPPER .readTree (in );
660657 } catch (IOException | IllegalArgumentException e ) {
661658 Tui .instance .errorf (e , "Unable to read or parse required resource (%s): %s" , resource , e .toString ());
662659 return null ;
0 commit comments