@@ -10,6 +10,7 @@ import org.ivdnt.galahad.corpora.documents.Documents
1010import org.ivdnt.galahad.corpora.jobs.Job
1111import org.ivdnt.galahad.exceptions.MergeNotImplementedException
1212import org.ivdnt.galahad.taggers.Tagger
13+ import org.ivdnt.galahad.util.FileMapper
1314import org.ivdnt.galahad.util.createZipFile
1415import java.io.File
1516import java.io.OutputStream
@@ -38,16 +39,16 @@ class CorpusExport private constructor(
3839 }
3940
4041
41- fun formatMapper (doc : Document ): File {
42+ private fun formatMapper (doc : Document , out : OutputStream ) {
4243 try {
4344 // Document conversions.
4445 val docExport = DocumentExport .create(this , doc)
45- return if (shouldMerge && mergeFormatMatches(doc, format)) {
46+ if (shouldMerge && mergeFormatMatches(doc, format)) {
4647 logger.info(" Merging ${doc.name} of format ${doc.metadata.format} " )
47- docExport.merge()
48+ docExport.merge(out )
4849 } else {
4950 logger.info(" Converting ${doc.name} of format ${doc.metadata.format} to $format " )
50- docExport.convert()
51+ docExport.convert(out )
5152 }
5253 } catch (e: MergeNotImplementedException ) {
5354 throw e
@@ -63,13 +64,8 @@ class CorpusExport private constructor(
6364 out : OutputStream ,
6465 ) {
6566 val documents = corpus.documents.readAll().filter { DocumentExport .create(this , it).layer != Layer .EMPTY }
66- val convertedDocs = documents.asSequence().map(::formatMapper)
67- val docsToCmdi = documents.asSequence().map { CmdiMetadata (DocumentExport .create(this , it)).file }
68- val cmdiZip = createZipFile(docsToCmdi, includeCMDI = true )
69- // rename the cmdiZip to "metadata"
70- val dest = createTempDirectory(" metadata" ).toFile().resolve(" metadata.zip" )
71- Files .move(cmdiZip.toPath(), dest.toPath())
72- createZipFile(convertedDocs + dest, out )
67+ val seq: Sequence <FileMapper > = documents.asSequence().map { doc -> doc.name to { out -> formatMapper(doc, out ) } }
68+ createZipFile(seq, out )
7369 }
7470
7571 companion object {
0 commit comments