Skip to content

Commit

Permalink
Fix native parsing from Java InputStream (#114)
Browse files Browse the repository at this point in the history
We checked if more bytes are available in the InputStream using .available()... which absolutely not how Java byte streams work, I have no idea how I made this mistake. Anyway, the proto lib checks this for us, so we can also simplify the code a bit.
  • Loading branch information
Ostrzyciel authored Jul 14, 2024
1 parent 832268b commit 543be31
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ object JellyReader extends ReaderRIOT:
val decoder = JenaConverterFactory.anyStatementDecoder(Some(supportedOptions))
output.start()
try {
while in.available() > 0 do
val frame = RdfStreamFrame.parseDelimitedFrom(in)
frame match
case Some(f) =>
for row <- f.rows do
decoder.ingestRow(row) match
case Some(st: Triple) => output.triple(st)
case Some(st: Quad) => output.quad(st)
case None => ()
case None => ()
Iterator.continually(RdfStreamFrame.parseDelimitedFrom(in))
.takeWhile(_.isDefined)
.foreach { maybeFrame =>
val frame = maybeFrame.get
for row <- frame.rows do
decoder.ingestRow(row) match
case Some(st: Triple) => output.triple(st)
case Some(st: Quad) => output.quad(st)
case None => ()
}
}
finally {
output.finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ final class JellyParser extends AbstractRDFParser:

rdfHandler.startRDF()
try {
while in.available() > 0 do
val frame = RdfStreamFrame.parseDelimitedFrom(in)
frame match
case Some(f) =>
for row <- f.rows do
decoder.ingestRow(row) match
case Some(st) => rdfHandler.handleStatement(st)
case None => ()
case None => ()
Iterator.continually(RdfStreamFrame.parseDelimitedFrom(in))
.takeWhile(_.isDefined)
.foreach { maybeFrame =>
val frame = maybeFrame.get
for row <- frame.rows do
decoder.ingestRow(row) match
case Some(st) => rdfHandler.handleStatement(st)
case None => ()
}
}
finally {
rdfHandler.endRDF()
Expand Down

0 comments on commit 543be31

Please sign in to comment.