Skip to content

Commit 79c294e

Browse files
committed
Refactor stream handling in guess read
1 parent 22bb293 commit 79c294e

File tree

1 file changed

+4
-10
lines changed
  • core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io

1 file changed

+4
-10
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/guess.kt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,21 +206,15 @@ internal fun DataFrame.Companion.read(
206206
formats: List<SupportedDataFrameFormat> = supportedFormats.filterIsInstance<SupportedDataFrameFormat>(),
207207
): ReadAnyFrame {
208208
if (format != null) return format to format.readDataFrame(stream, header = header)
209-
val input = NotCloseableStream(if (stream.markSupported()) stream else BufferedInputStream(stream))
210-
try {
211-
val readLimit = 10000
212-
input.mark(readLimit)
213-
209+
stream.use { input ->
210+
val byteArray = input.readBytes() // read 8192 bytes
214211
formats.sortedBy { it.testOrder }.forEach {
215212
try {
216-
input.reset()
217-
return it to it.readDataFrame(input, header = header)
218-
} catch (e: Exception) {
213+
return it to it.readDataFrame(byteArray.inputStream(), header = header)
214+
} catch (_: Exception) {
219215
}
220216
}
221217
throw IllegalArgumentException("Unknown stream format")
222-
} finally {
223-
input.doClose()
224218
}
225219
}
226220

0 commit comments

Comments
 (0)