Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SPB_Exchange_Repo
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Amelin Konstantin
SPB_Exchange_Repo
Commits
6e748efd
Commit
6e748efd
authored
Jul 11, 2019
by
Amelin Konstantin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add convertion java stream -> scala stream
parent
8c0b17a3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
60 deletions
+58
-60
src/main/scala/Main.scala
+58
-60
No files found.
src/main/scala/Main.scala
View file @
6e748efd
import
com.typesafe.config.
{
Config
,
ConfigFactory
}
import
com.typesafe.config.
{
Config
,
ConfigFactory
}
import
scala.xml._
import
scala.xml._
import
java.nio.file.
{
Files
,
Path
,
Path
s
,
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,66 +68,64 @@ object Main {
...
@@ -68,66 +68,64 @@ object Main {
createDirRes
match
{
createDirRes
match
{
case
Success
(
_
)
=>
case
Success
(
_
)
=>
val
sourceArray
=
{
val
sourceStream
=
paths
for
(
p
<-
paths
)
yield
{
.
flatMap
{
val
name
=
p
.
getFileName
.
toString
p
=>
val
ext
=
name
.
split
(
'.'
).
last
.
toLowerCase
val
name
=
p
.
getFileName
.
toString
val
ext
=
name
.
split
(
'.'
).
last
.
toLowerCase
if
(
ext
==
"zip"
)
Try
{
if
(
ext
==
"zip"
)
val
zip
=
new
ZipFile
(
p
.
toString
)
Try
{
val
zip
=
new
ZipFile
(
p
.
toString
)
zip
.
stream
zip
.
toArray
.
stream
.
map
{
.
iterator
z
=>
z
.
asInstanceOf
[
ZipEntry
]
.
asScala
}
.
toStream
.
map
{
.
map
{
e
=>
e
=>
FileEntry
(
s
"${name}_${e.getName}"
,
//e.getName,
e
.
getLastModifiedTime
,
Some
(
zip
.
getInputStream
(
e
)),
zip
.
getInputStream
(
e
),
Some
(
zip
),
None
)
}
}
match
{
case
Success
(
v
)
=>
v
case
Failure
(
ex
)
=>
Stream
(
FileEntry
(
FileEntry
(
s
"${name}_${e.getName}"
,
name
,
//e.getName,
Files
.
getLastModifiedTime
(
p
),
e
.
getLastModifiedTime
,
None
,
Some
(
zip
.
getInputStream
(
e
)),
Files
.
newInputStream
(
p
),
zip
.
getInputStream
(
e
),
None
,
Some
(
zip
),
Some
(
ex
.
toString
))
None
)
)
}
}
}
match
{
else
case
Success
(
v
)
=>
Stream
(
v
FileEntry
(
case
Failure
(
ex
)
=>
name
,
Array
(
Files
.
getLastModifiedTime
(
p
),
FileEntry
(
Some
(
Files
.
newInputStream
(
p
)),
name
,
Files
.
newInputStream
(
p
),
Files
.
getLastModifiedTime
(
p
),
None
,
None
,
None
)
Files
.
newInputStream
(
p
),
)
None
,
Some
(
ex
.
toString
))
)
}
else
Array
(
FileEntry
(
name
,
Files
.
getLastModifiedTime
(
p
),
Some
(
Files
.
newInputStream
(
p
)),
Files
.
newInputStream
(
p
),
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
<-
source
Array
)
{
for
(
f
<-
source
Stream
)
{
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 {
}
}
}
}
source
Array
source
Stream
.
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
()
}
source
Array
source
Stream
.
filter
{
f
=>
f
.
zip
.
isEmpty
}
.
filter
{
f
=>
f
.
zip
.
isEmpty
}
.
foreach
{
.
foreach
{
f
=>
f
=>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment