All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jetbrains.plugin.structure.jar.CachingJarFileSystemProvider.kt Maven / Gradle / Ivy

Go to download

Base library for parsing JetBrains plugins. Used by other JetBrains Plugins structure libraries.

There is a newer version: 3.290
Show newest version
package com.jetbrains.plugin.structure.jar

import com.jetbrains.plugin.structure.base.utils.withSuperScheme
import java.net.URI
import java.nio.file.FileSystem
import java.nio.file.Path
import java.util.concurrent.ConcurrentHashMap

/**
 * File system provider that maintains open file systems in an internal cache.
 */
class CachingJarFileSystemProvider : JarFileSystemProvider, AutoCloseable {
  private val fsCache: MutableMap = ConcurrentHashMap()

  private val delegateJarFileSystemProvider = UriJarFileSystemProvider { it.toUri().withSuperScheme(JAR_SCHEME) }

  override fun getFileSystem(jarPath: Path): FileSystem {
    val jarUri = jarPath.toJarFileUri()
    try {
      return fsCache.computeIfAbsent(jarUri) { delegateJarFileSystemProvider.getFileSystem(jarPath) }
    } catch (e: Throwable) {
      throw JarArchiveCannotBeOpenException(jarPath, jarUri, e)
    }
  }

  override fun close(jarPath: Path) {
    val jarUri = jarPath.toJarFileUri()
    fsCache[jarUri]?.let { fs ->
      fs.close()
      fsCache.remove(jarUri)
    }
  }

  override fun close() {
    fsCache.clear()
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy