Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
nomad-lab-base
Commits
a042b99c
Commit
a042b99c
authored
Jul 15, 2018
by
Ihrig, Arvid Conrad (ari)
Browse files
Integrated Pipeline: refactored TreeParser implementations, moved common logic to trait
parent
70582cb8
Changes
3
Hide whitespace changes
Inline
Side-by-side
integrated-pipeline/src/main/scala/eu/nomad_lab/integrated_pipeline/ParsingTaskGenerator.scala
View file @
a042b99c
...
...
@@ -2,6 +2,7 @@ package eu.nomad_lab.integrated_pipeline
import
java.io.InputStream
import
java.nio.file.Path
import
java.util.NoSuchElementException
import
eu.nomad_lab.integrated_pipeline.messages.
{
FileParsingTask
,
FileTreeScanTask
}
import
eu.nomad_lab.parsers.
{
CandidateParser
,
ParserCollection
}
...
...
@@ -12,6 +13,33 @@ import eu.nomad_lab.parsers.{ CandidateParser, ParserCollection }
*/
trait
ParsingTaskGenerator
extends
Iterator
[
FileParsingTask
]
{
protected
[
this
]
def
findNextParsingCandidate
()
:
Option
[
FileParsingTask
]
private
var
nextRequest
:
Option
[
FileParsingTask
]
=
None
private
var
searchStarted
:
Boolean
=
false
def
hasNext
:
Boolean
=
{
if
(!
searchStarted
)
{
nextRequest
=
findNextParsingCandidate
()
searchStarted
=
true
}
nextRequest
.
isDefined
}
def
next
()
:
FileParsingTask
=
{
if
(!
searchStarted
)
{
nextRequest
=
findNextParsingCandidate
()
searchStarted
=
true
}
val
toReturn
=
nextRequest
nextRequest
=
findNextParsingCandidate
()
if
(
toReturn
.
isDefined
)
{
toReturn
.
get
}
else
{
throw
new
NoSuchElementException
(
"No more elements in this iterator"
)
}
}
def
scanInputStream
(
parsers
:
ParserCollection
,
input
:
InputStream
,
internalFilePath
:
String
)
:
Seq
[
CandidateParser
]
=
{
val
buf
=
Array
.
fill
[
Byte
](
8
*
1024
)(
0
)
...
...
integrated-pipeline/src/main/scala/eu/nomad_lab/integrated_pipeline/io_integrations/DirectoryTreeParsingTaskGenerator.scala
View file @
a042b99c
...
...
@@ -18,21 +18,8 @@ class DirectoryTreeParsingTaskGenerator(request: FileTreeScanTask, parserCollect
require
(
request
.
treeType
==
TreeType
.
Directory
,
"file tree to process must be a directory"
)
private
val
basePath
=
request
.
treeBasePath
private
val
fileIterator
=
Files
.
walk
(
basePath
).
iterator
().
asScala
.
filter
(
Files
.
isRegularFile
(
_
))
private
var
nextRequest
:
Option
[
FileParsingTask
]
=
findNextParsingCandidate
()
override
def
hasNext
=
nextRequest
.
isDefined
override
def
next
()
:
FileParsingTask
=
{
val
toReturn
=
nextRequest
nextRequest
=
findNextParsingCandidate
()
if
(
toReturn
.
isDefined
)
{
toReturn
.
get
}
else
{
throw
new
NoSuchElementException
(
"No more elements in this iterator"
)
}
}
@tailrec
private
def
findNextParsingCandidate
()
:
Option
[
FileParsingTask
]
=
{
@tailrec
final
protected
[
this
]
override
def
findNextParsingCandidate
()
:
Option
[
FileParsingTask
]
=
{
if
(
fileIterator
.
hasNext
)
{
val
file
=
fileIterator
.
next
()
val
internalFilePath
=
basePath
.
relativize
(
file
)
...
...
integrated-pipeline/src/main/scala/eu/nomad_lab/integrated_pipeline/io_integrations/ZipTreeParsingTaskGenerator.scala
View file @
a042b99c
...
...
@@ -18,25 +18,12 @@ class ZipTreeParsingTaskGenerator(request: FileTreeScanTask, parserCollection: P
private
val
zipFile
=
new
ZipFile
(
request
.
treeBasePath
.
toFile
)
private
val
zipEntries
:
java.util.Enumeration
[
ZipArchiveEntry
]
=
zipFile
.
getEntries
private
var
nextRequest
:
Option
[
FileParsingTask
]
=
findNextParsingCandidate
()
override
def
hasNext
:
Boolean
=
nextRequest
.
isDefined
override
def
finalize
()
:
Unit
=
{
zipFile
.
close
()
}
override
def
next
()
:
FileParsingTask
=
{
val
toReturn
=
nextRequest
nextRequest
=
findNextParsingCandidate
()
if
(
toReturn
.
isDefined
)
{
toReturn
.
get
}
else
{
throw
new
NoSuchElementException
(
"No more elements in this iterator"
)
}
}
@tailrec
private
def
findNextParsingCandidate
()
:
Option
[
FileParsingTask
]
=
{
@tailrec
protected
[
this
]
final
override
def
findNextParsingCandidate
()
:
Option
[
FileParsingTask
]
=
{
if
(
zipEntries
.
hasMoreElements
)
{
val
zipEntry
:
ZipArchiveEntry
=
zipEntries
.
nextElement
()
val
internalFilePath
=
Paths
.
get
(
zipEntry
.
getName
)
...
...
Write
Preview
Supports
Markdown
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