Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions shark/shark-graph/src/main/java/shark/HeapObject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ sealed class HeapObject {
* The name of the class of this array, identical to [Class.getName].
*/
val arrayClassName: String
get() = "${primitiveType.name.toLowerCase(Locale.US)}[]"
get() = "${primitiveType.name.lowercase(Locale.US)}[]"

/**
* The class of this array.
Expand Down Expand Up @@ -651,7 +651,7 @@ sealed class HeapObject {
companion object {

internal val primitiveTypesByPrimitiveArrayClassName =
PrimitiveType.values().associateBy { "${it.name.toLowerCase(Locale.US)}[]" }
PrimitiveType.values().associateBy { "${it.name.lowercase(Locale.US)}[]" }

private val primitiveWrapperClassNames = setOf<String>(
Boolean::class.javaObjectType.name, Char::class.javaObjectType.name,
Expand Down
9 changes: 3 additions & 6 deletions shark/shark-hprof/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ dependencies {
implementation(libs.kotlin.stdlib)
// compileOnly ensures this dependency is not exposed through this artifact's pom.xml in Maven Central.
// Okio is a required dependency, but we're making it required on the "shark" artifact which is the main artifact that
// should generally be used. The shark artifact depends on Okio 2.x (ensure compatibility with modern Okio). Depending on 1.x here
// enables us to ensure binary compatibility with Okio 1.x and allow us to use the deprecated (error level) Okio APIs to keep that
// compatibility.
// See https://github.com/square/leakcanary/issues/1624
compileOnly(libs.okio1)
testImplementation(libs.okio1)
// should generally be used. The shark artifact depends on Okio 2.x (ensure compatibility with modern Okio).
compileOnly(libs.okio2)
testImplementation(libs.okio2)

testImplementation(libs.assertjCore)
testImplementation(libs.junit)
Expand Down
5 changes: 3 additions & 2 deletions shark/shark-hprof/src/main/java/shark/FileSourceProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import java.io.RandomAccessFile
import kotlin.math.min
import okio.Buffer
import okio.BufferedSource
import okio.Okio
import okio.buffer
import okio.source

class FileSourceProvider(private val file: File) : DualSourceProvider {
override fun openStreamingSource(): BufferedSource = Okio.buffer(Okio.source(file.inputStream()))
override fun openStreamingSource(): BufferedSource = file.inputStream().source().buffer()

override fun openRandomAccessSource(): RandomAccessSource {

Expand Down
5 changes: 3 additions & 2 deletions shark/shark-hprof/src/main/java/shark/HprofHeader.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package shark

import okio.BufferedSource
import okio.Okio
import okio.buffer
import okio.source
import java.io.File

/**
Expand Down Expand Up @@ -37,7 +38,7 @@ data class HprofHeader(
if (fileLength == 0L) {
throw IllegalArgumentException("Hprof file is 0 byte length")
}
return Okio.buffer(Okio.source(hprofFile.inputStream())).use {
return hprofFile.inputStream().source().buffer().use {
parseHeaderOf(it)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package shark

import okio.BufferedSink
import okio.Okio
import okio.buffer
import okio.sink
import shark.HprofRecord.HeapDumpEndRecord
import shark.HprofRecord.HeapDumpRecord.ObjectRecord.PrimitiveArrayDumpRecord.BooleanArrayDump
import shark.HprofRecord.HeapDumpRecord.ObjectRecord.PrimitiveArrayDumpRecord.ByteArrayDump
Expand Down Expand Up @@ -38,7 +39,7 @@ class HprofPrimitiveArrayStripper {
): File {
stripPrimitiveArrays(
hprofSourceProvider = FileSourceProvider(inputHprofFile),
hprofSink = Okio.buffer(Okio.sink(outputHprofFile.outputStream()))
hprofSink = outputHprofFile.outputStream().sink().buffer()
)
return outputHprofFile
}
Expand Down
11 changes: 6 additions & 5 deletions shark/shark-hprof/src/main/java/shark/HprofWriter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import java.io.Closeable
import java.io.File
import okio.Buffer
import okio.BufferedSink
import okio.Okio
import okio.buffer
import okio.sink
import shark.GcRoot.Debugger
import shark.GcRoot.Finalizing
import shark.GcRoot.InternedString
Expand Down Expand Up @@ -422,13 +423,13 @@ class HprofWriter private constructor(
) {
flushHeapBuffer()
workBuffer.block()
writeTagHeader(tag, workBuffer.size())
writeTagHeader(tag, workBuffer.size)
writeAll(workBuffer)
}

private fun BufferedSink.flushHeapBuffer() {
if (workBuffer.size() > 0) {
writeTagHeader(HprofRecordTag.HEAP_DUMP.tag, workBuffer.size())
if (workBuffer.size > 0) {
writeTagHeader(HprofRecordTag.HEAP_DUMP.tag, workBuffer.size)
writeAll(workBuffer)
writeTagHeader(HprofRecordTag.HEAP_DUMP_END.tag, 0)
}
Expand Down Expand Up @@ -460,7 +461,7 @@ class HprofWriter private constructor(
hprofFile: File,
hprofHeader: HprofHeader = HprofHeader()
): HprofWriter {
return openWriterFor(Okio.buffer(Okio.sink(hprofFile.outputStream())), hprofHeader)
return openWriterFor(hprofFile.outputStream().sink().buffer(), hprofHeader)
}

fun openWriterFor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class RandomAccessHprofReader private constructor(
mutableByteCount -= bytesRead
}
return withRecordReader(reader).apply {
check(buffer.size() == 0L) {
"Buffer not fully consumed: ${buffer.size()} bytes left"
check(buffer.size == 0L) {
"Buffer not fully consumed: ${buffer.size} bytes left"
}
}
}
Expand All @@ -69,4 +69,4 @@ class RandomAccessHprofReader private constructor(
return RandomAccessHprofReader(hprofSourceProvider.openRandomAccessSource(), hprofHeader)
}
}
}
}
6 changes: 3 additions & 3 deletions shark/shark-hprof/src/main/java/shark/RandomAccessSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package shark

import okio.Buffer
import okio.BufferedSource
import okio.Okio
import okio.Source
import okio.Timeout
import okio.buffer
import java.io.Closeable
import java.io.IOException

Expand All @@ -17,7 +17,7 @@ interface RandomAccessSource : Closeable {
): Long

fun asStreamingSource(): BufferedSource {
return Okio.buffer(object : Source {
return (object : Source {
var position = 0L

override fun timeout() = Timeout.NONE
Expand All @@ -40,6 +40,6 @@ interface RandomAccessSource : Closeable {
position += bytesRead
return bytesRead
}
})
}).buffer()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import okio.Buffer
import okio.BufferedSource
import okio.Okio
import okio.Source
import okio.buffer
import okio.source

/**
* A [DualSourceProvider] that invokes [throwIfCanceled] before every read, allowing
Expand All @@ -17,16 +19,16 @@ class ThrowingCancelableFileSourceProvider(
) : DualSourceProvider {

override fun openStreamingSource(): BufferedSource {
val realSource = Okio.source(file.inputStream())
return Okio.buffer(object : Source by realSource {
val realSource = file.inputStream().source()
return (object : Source by realSource {
override fun read(
sink: Buffer,
byteCount: Long
): Long {
throwIfCanceled.run()
return realSource.read(sink, byteCount)
}
})
}).buffer()
}

override fun openRandomAccessSource(): RandomAccessSource {
Expand Down
4 changes: 2 additions & 2 deletions shark/shark/src/main/java/shark/LeakTraceObject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ data class LeakTraceObject(
val classSimpleName: String get() = className.lastSegment('.')

val typeName
get() = type.name.toLowerCase(Locale.US)
get() = type.name.lowercase(Locale.US)

override fun toString(): String {
val firstLinePrefix = ""
Expand Down Expand Up @@ -113,4 +113,4 @@ data class LeakTraceObject(
return String.format("%.1f %sB", bytes / unit.toDouble().pow(exp.toDouble()), pre)
}
}
}
}