private static boolean refresh(@NotNull VirtualFile file) throws IOException {
  Long loadedTimeStamp=file.getUserData(TIMESTAMP_KEY);
  SoftReference<BufferedImage> imageRef=file.getUserData(BUFFERED_IMAGE_REF_KEY);
  if (loadedTimeStamp == null || loadedTimeStamp.longValue() != file.getTimeStamp() || SoftReference.dereference(imageRef) == null) {
    try {
      final byte[] content=file.contentsToByteArray();
      if (ICO_FORMAT.equalsIgnoreCase(file.getExtension())) {
        try {
          final BufferedImage image=ICO_IMAGE_PARSER.getBufferedImage(new ByteSourceArray(content),null);
          file.putUserData(FORMAT_KEY,ICO_FORMAT);
          file.putUserData(BUFFERED_IMAGE_REF_KEY,new SoftReference<BufferedImage>(image));
          return true;
        }
 catch (        ImageReadException ignore) {
        }
      }
      InputStream inputStream=new ByteArrayInputStream(content,0,content.length);
      ImageInputStream imageInputStream=ImageIO.createImageInputStream(inputStream);
      try {
        Iterator<ImageReader> imageReaders=ImageIO.getImageReaders(imageInputStream);
        if (imageReaders.hasNext()) {
          ImageReader imageReader=imageReaders.next();
          try {
            file.putUserData(FORMAT_KEY,imageReader.getFormatName());
            ImageReadParam param=imageReader.getDefaultReadParam();
            imageReader.setInput(imageInputStream,true,true);
            int minIndex=imageReader.getMinIndex();
            BufferedImage image=imageReader.read(minIndex,param);
            file.putUserData(BUFFERED_IMAGE_REF_KEY,new SoftReference<BufferedImage>(image));
            return true;
          }
  finally {
            imageReader.dispose();
          }
        }
      }
  finally {
        imageInputStream.close();
      }
    }
  finally {
      file.putUserData(TIMESTAMP_KEY,file.getTimeStamp());
    }
  }
  return false;
}

private static boolean refresh ( @ NotNull VirtualFile file ) throws IOException { Long loadedTimeStamp = file . getUserData ( TIMESTAMP_KEY ) ; SoftReference < BufferedImage > imageRef = file . getUserData ( BUFFERED_IMAGE_REF_KEY ) ; if ( loadedTimeStamp == null || loadedTimeStamp . longValue ( ) != file . getTimeStamp ( ) || SoftReference . dereference ( imageRef ) == null ) { try { final byte [ ] content = file . contentsToByteArray ( ) ; if ( ICO_FORMAT . equalsIgnoreCase ( file . getExtension ( ) ) ) { try { final BufferedImage image = ICO_IMAGE_PARSER . getBufferedImage ( new ByteSourceArray ( content ) , null ) ; file . putUserData ( FORMAT_KEY , ICO_FORMAT ) ; file . putUserData ( BUFFERED_IMAGE_REF_KEY , new SoftReference < BufferedImage > ( image ) ) ; return true ; } catch ( ImageReadException ignore ) { } } InputStream inputStream = new ByteArrayInputStream ( content , 0 , content . length ) ; ImageInputStream imageInputStream = ImageIO . createImageInputStream ( inputStream ) ; try { Iterator < ImageReader > imageReaders = ImageIO . getImageReaders ( imageInputStream ) ; if ( imageReaders . hasNext ( ) ) { ImageReader imageReader = imageReaders . next ( ) ; try { file . putUserData ( FORMAT_KEY , imageReader . getFormatName ( ) ) ; ImageReadParam param = imageReader . getDefaultReadParam ( ) ; imageReader . setInput ( imageInputStream , true , true ) ; int minIndex = imageReader . getMinIndex ( ) ; BufferedImage image = imageReader . read ( minIndex , param ) ; file . putUserData ( BUFFERED_IMAGE_REF_KEY , new SoftReference < BufferedImage > ( image ) ) ; return true ; } finally { imageReader . dispose ( ) ; } } } finally { imageInputStream . close ( ) ; } } finally { file . putUserData ( TIMESTAMP_KEY , file . getTimeStamp ( ) ) ; } } return false ; }
load image data for file and put user data attributes into file .
