Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ trait CobolProcessor {
* @param inputStream the input stream containing raw COBOL records.
* @param outputStream the output stream where processed records will be written.
* @param rawRecordProcessor the processor that processes each raw record.
* @return The number of records processed.
*/
def process(inputStream: SimpleStream,
outputStream: OutputStream)
(rawRecordProcessor: RawRecordProcessor): Unit
(rawRecordProcessor: RawRecordProcessor): Long

}

Expand All @@ -56,7 +57,7 @@ object CobolProcessor {
new CobolProcessor {
override def process(inputStream: SimpleStream,
outputStream: OutputStream)
(rawRecordProcessor: RawRecordProcessor): Unit = {
(rawRecordProcessor: RawRecordProcessor): Long = {
val recordExtractor = getRecordExtractor(readerParameters, inputStream)

val dataStream = inputStream.copyStream()
Expand Down Expand Up @@ -116,7 +117,7 @@ object CobolProcessor {

reader.recordExtractor(0, dataStream, headerStream) match {
case Some(extractor) => extractor
case None =>
case None =>
throw new IllegalArgumentException(s"Cannot create a record extractor for the given reader parameters. " +
"Please check the copybook and the reader parameters."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ object StreamProcessor {
* @param recordExtractor the extractor that extracts raw records from the input stream.
* @param recordProcessor the per-record processing logic implementation.
* @param outputStream the output stream where the processed records will be written.
* @return The number of records processed.
*/
def processStream(copybook: Copybook,
options: Map[String, String],
inputStream: SimpleStream,
recordExtractor: RawRecordExtractor,
recordProcessor: RawRecordProcessor,
outputStream: OutputStream): Unit = {
outputStream: OutputStream): Long = {
var recordCount = 0L
while (recordExtractor.hasNext) {
recordCount += 1
val record = recordExtractor.next()
val recordSize = record.length

Expand All @@ -61,5 +64,6 @@ object StreamProcessor {
val footer = inputStream.next(footerSize.toInt)
outputStream.write(footer)
}
recordCount
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ class CobolProcessorBuilderSuite extends AnyWordSpec {
}
}

builder.build().process(is, os)(processor)
val count = builder.build().process(is, os)(processor)

val outputArray = os.toByteArray

assert(count == 4)
assert(outputArray.head == -16)
assert(outputArray(1) == -15)
assert(outputArray(2) == -14)
Expand Down
Loading