Replace io usages
MODIFY
leakcanary-android-core/src/androidTest/java/leakcanary/DatabaseMigrationTest.kt
leakcanary-android-core/src/androidTest/java/leakcanary/DatabaseMigrationTest.kt
@@ -10,7 +10,6 @@ import shark.HeapAnalysis
import shark.HeapAnalysisSuccess
import shark.LeakTrace.GcRootType.JAVA_FRAME
import shark.LeakTrace.GcRootType.STICKY_CLASS
-import java.io.FileOutputStream
class DatabaseMigrationTest {
@@ -94,7 +93,7 @@ class DatabaseMigrationTest {
.use { input ->
val databaseFile = context.getDatabasePath(LeaksDbHelper.DATABASE_NAME)
databaseFile.parentFile!!.mkdirs()
- FileOutputStream(databaseFile).use { output ->
+ databaseFile.outputStream().use { output ->
input.copyTo(output)
}
}

MODIFY
leakcanary-android-core/src/main/java/leakcanary/internal/activity/screen/RenderHeapDumpScreen.kt
leakcanary-android-core/src/main/java/leakcanary/internal/activity/screen/RenderHeapDumpScreen.kt
@@ -12,6 +12,9 @@ import android.view.ViewTreeObserver.OnGlobalLayoutListener
import android.widget.ImageView
import android.widget.Toast
import com.squareup.leakcanary.core.R
+import java.io.File
+import java.io.FileOutputStream
+import java.io.IOException
import leakcanary.internal.InternalLeakCanary
import leakcanary.internal.LeakCanaryFileProvider
import leakcanary.internal.activity.db.executeOnIo
@@ -21,9 +24,6 @@ import leakcanary.internal.navigation.inflate
import leakcanary.internal.navigation.onCreateOptionsMenu
import leakcanary.internal.utils.humanReadableByteCount
import shark.SharkLog
-import java.io.File
-import java.io.FileOutputStream
-import java.io.IOException
internal class RenderHeapDumpScreen(
private val heapDumpFile: File
@@ -136,7 +136,7 @@ internal class RenderHeapDumpScreen(
): Boolean {
var outStream: FileOutputStream? = null
return try {
- outStream = FileOutputStream(imageFile)
+ outStream = imageFile.outputStream()
source.compress(Bitmap.CompressFormat.PNG, 100, outStream)
true
} catch (e: IOException) {

MODIFY
leakcanary-android-instrumentation/src/androidTest/java/leakcanary/ProfiledTest.kt
leakcanary-android-instrumentation/src/androidTest/java/leakcanary/ProfiledTest.kt
@@ -2,6 +2,7 @@ package leakcanary
import android.util.Log
import androidx.test.platform.app.InstrumentationRegistry
+import java.io.File
import leakcanary.Profiler.runWithProfilerSampling
import org.junit.Ignore
import org.junit.Test
@@ -10,8 +11,6 @@ import shark.AndroidReferenceMatchers
import shark.HeapAnalyzer
import shark.KeyedWeakReferenceFinder
import shark.SharkLog
-import java.io.File
-import java.io.FileOutputStream
class ProfiledTest {
@@ -26,7 +25,7 @@ class ProfiledTest {
val heapDumpFile = File(context.filesDir, "ProfiledTest.hprof")
context.assets.open(fileName)
- .copyTo(FileOutputStream(heapDumpFile))
+ .copyTo(heapDumpFile.outputStream())
runWithProfilerSampling {
val analyzer = HeapAnalyzer { step -> Log.d("LeakCanary", step.name) }

MODIFY
leakcanary-android-release/src/main/java/leakcanary/ProcessInfo.kt
leakcanary-android-release/src/main/java/leakcanary/ProcessInfo.kt
@@ -10,12 +10,11 @@ import android.os.Process
import android.os.SystemClock
import android.system.Os
import android.system.OsConstants
+import java.io.File
+import java.io.FileReader
import leakcanary.ProcessInfo.AvailableRam.BelowThreshold
import leakcanary.ProcessInfo.AvailableRam.LowRamDevice
import leakcanary.ProcessInfo.AvailableRam.Memory
-import java.io.BufferedReader
-import java.io.File
-import java.io.FileReader
interface ProcessInfo {
@@ -110,7 +109,7 @@ interface ProcessInfo {
// Android 10. Median time: 0.13ms
private fun readProcessStartTicks(pid: Int): Long {
val path = "/proc/$pid/stat"
- val stat = BufferedReader(FileReader(path)).use { reader ->
+ val stat = FileReader(path).buffered().use { reader ->
reader.readLine()
}
val fields = stat.substringAfter(") ")

Replace io usages