mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ICS: loadContent -> read, remove unused listSubFiles
This commit is contained in:
@@ -63,7 +63,7 @@ abstract class XmlElementStorage protected constructor(protected val fileSpec: S
|
||||
protected open fun dataLoadedFromProvider(element: Element?) {
|
||||
}
|
||||
|
||||
private fun loadDataFromProvider() = JDOMUtil.load(provider!!.loadContent(fileSpec, roamingType))
|
||||
private fun loadDataFromProvider() = JDOMUtil.load(provider!!.read(fileSpec, roamingType))
|
||||
|
||||
private fun loadState(element: Element): StateMap {
|
||||
beforeElementLoaded(element)
|
||||
|
||||
@@ -109,6 +109,9 @@ class ApplicationStoreTest {
|
||||
private fun writeConfig(fileName: String, Language("XML") data: String) = testAppConfig.writeChild(fileName, data)
|
||||
|
||||
private class MyStreamProvider : StreamProvider {
|
||||
override fun processChildren(path: String, roamingType: RoamingType, filter: (String) -> Boolean, processor: (String, InputStream, Boolean) -> Boolean) {
|
||||
}
|
||||
|
||||
public val data: MutableMap<RoamingType, MutableMap<String, String>> = THashMap()
|
||||
|
||||
override fun write(fileSpec: String, content: ByteArray, size: Int, roamingType: RoamingType) {
|
||||
@@ -124,7 +127,7 @@ class ApplicationStoreTest {
|
||||
return map
|
||||
}
|
||||
|
||||
override fun loadContent(fileSpec: String, roamingType: RoamingType): InputStream? {
|
||||
override fun read(fileSpec: String, roamingType: RoamingType): InputStream? {
|
||||
val data = getMap(roamingType).get(fileSpec) ?: return null
|
||||
return ByteArrayInputStream(data.toByteArray())
|
||||
}
|
||||
|
||||
@@ -13,13 +13,13 @@ class MockStreamProvider(private val myBaseDir: File) : StreamProvider {
|
||||
FileUtil.writeToFile(File(myBaseDir, fileSpec), content, 0, size)
|
||||
}
|
||||
|
||||
override fun loadContent(fileSpec: String, roamingType: RoamingType): InputStream? {
|
||||
override fun read(fileSpec: String, roamingType: RoamingType): InputStream? {
|
||||
val file = File(myBaseDir, fileSpec)
|
||||
//noinspection IOResourceOpenedButNotSafelyClosed
|
||||
return if (file.exists()) FileInputStream(file) else null
|
||||
}
|
||||
|
||||
override fun listSubFiles(fileSpec: String, roamingType: RoamingType): Collection<String> {
|
||||
private fun listSubFiles(fileSpec: String, roamingType: RoamingType): Collection<String> {
|
||||
if (roamingType !== RoamingType.PER_USER) {
|
||||
return emptyList()
|
||||
}
|
||||
@@ -32,6 +32,22 @@ class MockStreamProvider(private val myBaseDir: File) : StreamProvider {
|
||||
return names
|
||||
}
|
||||
|
||||
/**
|
||||
* You must close passed input stream.
|
||||
*/
|
||||
override fun processChildren(path: String, roamingType: RoamingType, filter: (name: String) -> Boolean, processor: (name: String, input: InputStream, readOnly: Boolean) -> Boolean) {
|
||||
for (name in listSubFiles(path, roamingType)) {
|
||||
if (!filter(name)) {
|
||||
continue
|
||||
}
|
||||
|
||||
val input = read("$path/$name", roamingType)
|
||||
if (input != null && !processor(name, input, false)) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun delete(fileSpec: String, roamingType: RoamingType) {
|
||||
FileUtil.delete(File(myBaseDir, fileSpec))
|
||||
}
|
||||
|
||||
+2
-25
@@ -16,7 +16,6 @@
|
||||
package com.intellij.openapi.components.impl.stores
|
||||
|
||||
import com.intellij.openapi.components.RoamingType
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
|
||||
public interface StreamProvider {
|
||||
@@ -32,34 +31,12 @@ public interface StreamProvider {
|
||||
*/
|
||||
public fun write(fileSpec: String, content: ByteArray, size: Int, roamingType: RoamingType)
|
||||
|
||||
public fun loadContent(fileSpec: String, roamingType: RoamingType): InputStream?
|
||||
|
||||
public open fun listSubFiles(fileSpec: String, roamingType: RoamingType): Collection<String> = emptyList()
|
||||
public fun read(fileSpec: String, roamingType: RoamingType): InputStream?
|
||||
|
||||
/**
|
||||
* You must close passed input stream.
|
||||
*/
|
||||
public open fun processChildren(path: String, roamingType: RoamingType, filter: (name: String) -> Boolean, processor: (name: String, input: InputStream, readOnly: Boolean) -> Boolean) {
|
||||
for (name in listSubFiles(path, roamingType)) {
|
||||
if (!filter(name)) {
|
||||
continue
|
||||
}
|
||||
|
||||
val input: InputStream?
|
||||
try {
|
||||
input = loadContent("$path/$name", roamingType)
|
||||
}
|
||||
catch (e: IOException) {
|
||||
StorageUtil.LOG.error(e)
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
if (input != null && !processor(name, input, false)) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
public fun processChildren(path: String, roamingType: RoamingType, filter: (name: String) -> Boolean, processor: (name: String, input: InputStream, readOnly: Boolean) -> Boolean)
|
||||
|
||||
/**
|
||||
* Delete file or directory
|
||||
|
||||
@@ -37,14 +37,6 @@ import kotlin.concurrent.write
|
||||
public abstract class BaseRepositoryManager(protected val dir: File) : RepositoryManager {
|
||||
protected val lock: ReentrantReadWriteLock = ReentrantReadWriteLock()
|
||||
|
||||
override fun listSubFileNames(path: String): Collection<String> {
|
||||
val files = File(dir, path).list()
|
||||
if (files == null || files.size() == 0) {
|
||||
return listOf()
|
||||
}
|
||||
return listOf(*files)
|
||||
}
|
||||
|
||||
override fun processChildren(path: String, filter: (name: String) -> Boolean, processor: (name: String, inputStream: InputStream) -> Boolean) {
|
||||
var files: Array<out File>? = null
|
||||
lock.read {
|
||||
|
||||
@@ -198,8 +198,6 @@ class IcsManager(dir: File) {
|
||||
override val enabled: Boolean
|
||||
get() = repositoryActive
|
||||
|
||||
override fun listSubFiles(fileSpec: String, roamingType: RoamingType): MutableCollection<String> = repositoryManager.listSubFileNames(buildPath(fileSpec, roamingType, null)) as MutableCollection<String>
|
||||
|
||||
override fun processChildren(path: String, roamingType: RoamingType, filter: (name: String) -> Boolean, processor: (name: String, input: InputStream, readOnly: Boolean) -> Boolean) {
|
||||
val fullPath = buildPath(path, roamingType, null)
|
||||
|
||||
@@ -229,7 +227,7 @@ class IcsManager(dir: File) {
|
||||
|
||||
protected open fun isAutoCommit(fileSpec: String, roamingType: RoamingType): Boolean = true
|
||||
|
||||
override fun loadContent(fileSpec: String, roamingType: RoamingType): InputStream? {
|
||||
override fun read(fileSpec: String, roamingType: RoamingType): InputStream? {
|
||||
return repositoryManager.read(buildPath(fileSpec, roamingType, projectId))
|
||||
}
|
||||
|
||||
|
||||
@@ -45,8 +45,6 @@ public interface RepositoryManager {
|
||||
|
||||
public fun delete(path: String)
|
||||
|
||||
public fun listSubFileNames(path: String): Collection<String>
|
||||
|
||||
public fun processChildren(path: String, filter: (name: String) -> Boolean, processor: (name: String, inputStream: InputStream) -> Boolean)
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user