Skip to content

Commit 64af08b

Browse files
committed
Add LogReaderSingleSequence
1 parent 085b850 commit 64af08b

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

build.gradle.kts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
13
plugins {
24
kotlin("jvm") version "1.3.21"
35
}
@@ -6,7 +8,7 @@ group = "org.athenian"
68
version = "1.0-SNAPSHOT"
79

810
repositories {
9-
mavenCentral(),
11+
mavenCentral()
1012
mavenLocal()
1113
}
1214

@@ -16,4 +18,4 @@ dependencies {
1618

1719
tasks.withType<KotlinCompile> {
1820
kotlinOptions.jvmTarget = "1.8"
19-
}
21+
}

src/main/kotlin/org/athenian/LazyLogReader.kt renamed to src/main/kotlin/org/athenian/LogReaderMultipleSequences.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fun getBytesColumn(data: Sequence<String>) =
2626
sequence {
2727
for (line in data) {
2828
val cols = line.split(" ")
29-
if (cols.isEmpty() || cols.size != 19)
29+
if (cols.size != 19)
3030
continue
3131
val bytes = cols[9]
3232
yield(bytes)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.athenian
2+
3+
import java.io.File
4+
5+
fun main() {
6+
val file = File("data/access.log")
7+
val lines =
8+
sequence {
9+
val data = file.bufferedReader().lineSequence()
10+
for (line in data) {
11+
yield(line)
12+
}
13+
}
14+
val bytes =
15+
lines
16+
.map { it.split(" ") }
17+
.filter { it.size == 19 }
18+
.map { it[9] }
19+
.filter { it != "-" }
20+
.map { it.toInt() }
21+
val total = bytes.sum()
22+
println("Total bytes: $total")
23+
}
24+

0 commit comments

Comments
 (0)