Commit 6e748efd by Amelin Konstantin

Add convertion java stream -> scala stream

parent 8c0b17a3
import com.typesafe.config.{Config, ConfigFactory}
import scala.xml._
import java.nio.file.{Files, Path, Paths, StandardOpenOption}
import java.nio.file.{Files, Paths, StandardOpenOption}
import java.io.InputStream
import java.nio.file.attribute.FileTime
import java.util.zip.{ZipEntry, ZipFile}
import java.util.zip.ZipFile
import java.time.LocalDateTime
import scala.util.{Failure, Success, Try}
import scala.collection.JavaConverters._
import xmlvalid._
import templates._
......@@ -35,10 +36,9 @@ object Main {
.filter {
p => !Files.isDirectory(p)
}
.toArray
.map {
_.asInstanceOf[Path]
}
.iterator
.asScala
.toStream
val start = LocalDateTime.now.toString.replace(":", ".")
......@@ -68,8 +68,9 @@ object Main {
createDirRes match {
case Success(_) =>
val sourceArray = {
for (p <- paths) yield {
val sourceStream = paths
.flatMap {
p =>
val name = p.getFileName.toString
val ext = name.split('.').last.toLowerCase
......@@ -79,10 +80,9 @@ object Main {
zip
.stream
.toArray
.map {
z => z.asInstanceOf[ZipEntry]
}
.iterator
.asScala
.toStream
.map {
e =>
FileEntry(
......@@ -98,7 +98,7 @@ object Main {
case Success(v) =>
v
case Failure(ex) =>
Array(
Stream(
FileEntry(
name,
Files.getLastModifiedTime(p),
......@@ -109,7 +109,7 @@ object Main {
)
}
else
Array(
Stream(
FileEntry(
name,
Files.getLastModifiedTime(p),
......@@ -119,15 +119,13 @@ object Main {
None)
)
}
}
.flatten
.sortWith { (a, b) =>
(a.modified.compareTo(b.modified) == 0 && a.name <= b.name) || (a.modified.compareTo(b.modified) < 0)
}
Try {
for (f <- sourceArray) {
for (f <- sourceStream) {
val now = LocalDateTime.now.toString
f.msg match {
......@@ -170,13 +168,13 @@ object Main {
}
}
sourceArray
sourceStream
.filter { f => f.zip.nonEmpty }
.groupBy { f => f.zip.get }
.keys
.foreach { _.close() }
sourceArray
sourceStream
.filter { f => f.zip.isEmpty }
.foreach {
f =>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment