Commit 6e748efd by Amelin Konstantin

Add convertion java stream -> scala stream

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