void (final @Nullable FileType fileType) { final File localIOFile; synchronized (myLock) { LOG.debug("Downloading finished, size = " + myLocalFile.length() + ", file type=" + (fileType != null ? fileType.getName() : "null")); if (fileType != null) { String fileName = myLocalFile.getName(); int dot = fileName.lastIndexOf('.'); String extension = fileType.getDefaultExtension(); if (dot == -1 || !extension.regionMatches(true, 0, fileName, dot + 1, extension.length())) { File newFile = FileUtil.findSequentNonexistentFile(myLocalFile.getParentFile(), fileName, extension); try { FileUtil.rename(myLocalFile, newFile); myLocalFile = newFile; } catch (IOException e) { LOG.debug(e); } } } localIOFile = myLocalFile; } VfsImplUtil.refreshAndFindFileByPath(LocalFileSystem.getInstance(), localIOFile.toString(), localFile -> { LOG.assertTrue(localFile != null, "Virtual local file not found for " + localIOFile.getAbsolutePath()); LOG.debug("Virtual local file: " + localFile + ", size = " + localFile.getLength()); synchronized (myLock) { myLocalVirtualFile = localFile; myPrevLocalFile = null; myState = RemoteFileState.DOWNLOADED; myErrorMessage = null; } for (FileDownloadingListener listener : myListeners) { try { listener.fileDownloaded(localFile); } catch (Throwable t) { LOG.error(t); } } }); }