Skip to content

Commit

Permalink
Replace io usages
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Jan 6, 2022
1 parent 890ead7 commit 89b1781
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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)
}
}
Expand All @@ -120,4 +119,4 @@ class DatabaseMigrationTest {
companion object {
const val DB_V24 = "leaks-v24.db"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {

Expand All @@ -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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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(") ")
Expand Down

0 comments on commit 89b1781

Please sign in to comment.