Skip to content

Instantly share code, notes, and snippets.

@koral--
Last active September 21, 2017 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koral--/373ba87d1c558b3faf50afb46a302159 to your computer and use it in GitHub Desktop.
Save koral--/373ba87d1c558b3faf50afb46a302159 to your computer and use it in GitHub Desktop.
Too many open files
package pl.droidsonroids.edgetest
import android.content.res.AssetFileDescriptor
import android.support.test.InstrumentationRegistry
import org.junit.Assert
import org.junit.Test
class TooManyOpenFilesTest {
//asset named "test" required
@Test
fun tooManyOpenFilesDemo() {
val context = InstrumentationRegistry.getContext()
val assets = context.assets
val descriptors = mutableListOf<AssetFileDescriptor>()
try {
for (i in 0..1024) {
descriptors.add(assets.openFd("test"))
}
} catch (e: Exception) {
e.printStackTrace() //java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
}
try {
context.openFileOutput("test", 0)
} catch (e: Exception) {
e.printStackTrace() //java.io.FileNotFoundException: /data/user/0/pl.droidsonroids.edgetest/files/test (Too many open files)
}
val sharedPreferences = context.getSharedPreferences("test", 0)
Assert.assertTrue(sharedPreferences.edit().putBoolean("test", true).commit())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment