88import java .io .File ;
99import java .io .FileOutputStream ;
1010import java .io .IOException ;
11+ import java .io .InputStream ;
1112
1213import com .genexus .util .GXFile ;
1314import org .apache .logging .log4j .Logger ;
@@ -23,14 +24,16 @@ private static String getImageAbsolutePath(String imageFile){
2324 return imageFile .startsWith (defaultPath )? imageFile : defaultPath + imageFile .replace ("/" , File .separator );
2425 }
2526
27+ private static InputStream getInputStream (String imageFile ) throws IOException {
28+ return new GXFile (imageFile ).getStream ();
29+ }
2630 public static long getFileSize (String imageFile ){
2731 return new File (getImageAbsolutePath (imageFile )).length ();
2832 }
2933
3034 public static int getImageHeight (String imageFile ) {
31- try {
32- BufferedImage image = ImageIO .read (new File (getImageAbsolutePath (imageFile )));
33- return image .getHeight ();
35+ try (InputStream is = getInputStream (imageFile )) {
36+ return ImageIO .read (is ).getHeight ();
3437 }
3538 catch (IOException e ) {
3639 log .error ("getImageHeight " + imageFile + " failed" , e );
@@ -39,9 +42,8 @@ public static int getImageHeight(String imageFile) {
3942 }
4043
4144 public static int getImageWidth (String imageFile ) {
42- try {
43- BufferedImage image = ImageIO .read (new File (getImageAbsolutePath (imageFile )));
44- return image .getWidth ();
45+ try (InputStream is = getInputStream (imageFile )) {
46+ return ImageIO .read (is ).getWidth ();
4547 }
4648 catch (IOException e ) {
4749 log .error ("getImageWidth " + imageFile + " failed" , e );
0 commit comments