Skip to content

Commit

Permalink
Revert "use blocks with transferTo (#1157)"
Browse files Browse the repository at this point in the history
This reverts commit 25378d3.
  • Loading branch information
jsarabia committed Jul 15, 2024
1 parent 6535ab0 commit 69ec7da
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,17 @@ class InitializeArtwork @Inject constructor(
}
}

private fun copyBibleArtworkContainers(
artwork: List<String> = listOf("en_art_wa.zip", "en_art_sp.zip")
) {
private fun copyBibleArtworkContainers(artwork: List<String> = listOf("en_art_wa.zip", "en_art_sp.zip")) {
for (art in artwork) {
if (!File(directoryProvider.resourceContainerDirectory, art).exists()) {
log.info("Copying bible artwork")
ClassLoader
.getSystemResourceAsStream("content/$art").use { ifs ->
ClassLoader.getSystemResourceAsStream("content/$art")
.transferTo(
File(
directoryProvider.resourceContainerDirectory.absolutePath,
art
).outputStream().use { ofs ->
ifs.transferTo(ofs)
}
}
).outputStream()
)
} else {
log.info("Artwork not initialized but $art exists in rc directory")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,8 @@ class InitializeMarker @Inject constructor(
private fun importOtterMarker(): Completable {
val pluginsDir = directoryProvider.audioPluginDirectory
val jar = File(pluginsDir, "OratureMarker.jar")
ClassLoader
.getSystemResourceAsStream("plugins/jars/markerapp")
?.use { ifs ->
FileOutputStream(jar).use { ofs ->
ifs.transferTo(ofs)
}
}
ClassLoader.getSystemResourceAsStream("plugins/jars/markerapp")
?.transferTo(FileOutputStream(jar))
return pluginRepository.insert(
AudioPluginData(
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,13 @@ class InitializePlugins @Inject constructor(
private fun copyOcenaudioPlugin() {
if (!File(directoryProvider.audioPluginDirectory, "ocenaudio.yaml").exists()) {
log.info("Copying ocenaudio plugin")
ClassLoader
.getSystemResourceAsStream("plugins/ocenaudio.yaml")?.use { ifs ->
ClassLoader.getSystemResourceAsStream("plugins/ocenaudio.yaml")
.transferTo(
File(
directoryProvider.audioPluginDirectory.absolutePath,
"ocenaudio.yaml"
).outputStream().use { ofs ->
ifs.transferTo(ofs)
}
}
).outputStream()
)
} else {
log.info("Ocenaudio plugin not initialized but ocenaudio.yaml exists in plugins directory")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,8 @@ class InitializeRecorder @Inject constructor(
private fun importOtterRecorder(): Completable {
val pluginsDir = directoryProvider.audioPluginDirectory
val jar = File(pluginsDir, "OratureRecorder.jar")
ClassLoader
.getSystemResourceAsStream("plugins/jars/recorderapp")
?.use { ifs ->
FileOutputStream(jar).use { ofs ->
ifs.transferTo(ofs)
}
}
ClassLoader.getSystemResourceAsStream("plugins/jars/recorderapp")
?.transferTo(FileOutputStream(jar))
return pluginRepository.insert(
AudioPluginData(
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ class InitializeVersification @Inject constructor(
directoryProvider.versificationDirectory.listFiles()?.forEach { file ->
if (file.extension == "json") {
logger.info("Inserting versification: ${file.name}")
versificationRepository.insertVersification(file.nameWithoutExtension, file)
.blockingAwait()
versificationRepository.insertVersification(file.nameWithoutExtension, file).blockingAwait()
}
}
}.subscribeOn(Schedulers.io())
Expand All @@ -61,24 +60,20 @@ class InitializeVersification @Inject constructor(
if (!File(directoryProvider.versificationDirectory, ULB_VERSIFICATION_FILE).exists()) {
directoryProvider.versificationDirectory.mkdirs()
logger.info("Copying ulb versification")
ClassLoader
.getSystemResourceAsStream(ULB_VERSIFICATION_RESOURCE_PATH)?.use { ifs ->
ClassLoader.getSystemResourceAsStream(ULB_VERSIFICATION_RESOURCE_PATH)
.transferTo(
File(
directoryProvider.versificationDirectory.absolutePath,
ULB_VERSIFICATION_FILE
).outputStream().use { ofs ->
ifs.transferTo(ofs)
}
}
ClassLoader
.getSystemResourceAsStream(ULB_VERSIFICATION_RESOURCE_PATH)?.use { ifs ->
).outputStream()
)
ClassLoader.getSystemResourceAsStream(ULB_VERSIFICATION_RESOURCE_PATH)
.transferTo(
File(
directoryProvider.versificationDirectory.absolutePath,
UFW_VERSIFICATION_FILE
).outputStream().use { ofs ->
ifs.transferTo(ofs)
}
}
).outputStream()
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ class ImportProjectUseCase @Inject constructor() {
it.import(file, callback, options)
}
.onErrorReturn {
logger.error(
"Failed to import project file: $file. See exception detail below.",
it
)
logger.error("Failed to import project file: $file. See exception detail below.", it)
ImportResult.FAILED
}
}
Expand All @@ -100,12 +97,7 @@ class ImportProjectUseCase @Inject constructor() {
getEmbeddedSource(language)
}
.subscribeOn(Schedulers.io())
.doOnError {
logger.error(
"Failed to get embedded source file for ${language.slug}",
it
)
}
.doOnError { logger.error("Failed to get embedded source file for ${language.slug}", it) }
.flatMap { sourceFile ->
import(sourceFile, null, null)
}
Expand All @@ -116,21 +108,13 @@ class ImportProjectUseCase @Inject constructor() {
val resourceName = glSources.find { it.languageCode == language.slug }?.name
val pathToSource = SOURCE_PATH_TEMPLATE.format(resourceName)

val sourceFile = javaClass
.classLoader
.getResource(pathToSource)
.openStream()
.use { input ->
val tempFile = File.createTempFile(
resourceName,
".zip",
directoryProvider.tempDirectory
)
tempFile.outputStream().use { output ->
input.transferTo(output)
}
tempFile
val sourceFile = javaClass.classLoader.getResource(pathToSource).openStream().use { input ->
val tempFile = File.createTempFile(resourceName, ".zip", directoryProvider.tempDirectory)
tempFile.outputStream().use { output ->
input.transferTo(output)
}
tempFile
}

return sourceFile
}
Expand All @@ -152,7 +136,6 @@ class ImportProjectUseCase @Inject constructor() {
ProjectFormat.RESOURCE_CONTAINER -> {
rcImporterProvider.get().getSourceMetadata(file)
}

else -> Maybe.empty()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ class SourceProjectExporter @Inject constructor(
rc,
tempFile.outputStream()
)
rc.accessor.write("metadata.json") { ofs ->
tempFile.inputStream().use { ifs -> ifs.transferTo(ofs) }
rc.accessor.write("metadata.json") {
tempFile.inputStream().transferTo(it)
}
tempFile.deleteIfExists()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ abstract class RCImporter(

return Single
.fromCallable {
outFile.outputStream().use { ofs ->
stream.transferTo(ofs)
}
stream.transferTo(outFile.outputStream())
}
.flatMap {
import(outFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,7 @@ class ProjectFilesAccessor(
val ext = it.substringAfterLast(".")
when (dir) {
RcConstants.SOURCE_DIR -> OratureFileFormat.isSupported(ext)
RcConstants.SOURCE_AUDIO_DIR -> AudioFileFormat.isSupported(ext) || AudioMetadataFileFormat.isSupported(
ext
)

RcConstants.SOURCE_AUDIO_DIR -> AudioFileFormat.isSupported (ext) || AudioMetadataFileFormat.isSupported(ext)
else -> false
}
}
Expand All @@ -199,11 +196,7 @@ class ProjectFilesAccessor(

if (!outFile.exists()) {
val stream = fileReader.stream(path)
stream.use { ifs ->
outFile.outputStream().use { ofs ->
ifs.transferTo(ofs)
}
}
stream.transferTo(outFile.outputStream())
}
}
}
Expand Down Expand Up @@ -309,11 +302,7 @@ class ProjectFilesAccessor(
fun copySelectedTakesFile(fileReader: IFileReader) {
val outFile = projectDir.resolve(RcConstants.SELECTED_TAKES_FILE)
if (!outFile.exists()) {
fileReader.stream(RcConstants.SELECTED_TAKES_FILE).use { ifs ->
outFile.outputStream().use { ofs ->
ifs.transferTo(ofs)
}
}
fileReader.stream(RcConstants.SELECTED_TAKES_FILE).transferTo(outFile.outputStream())
}
}

Expand Down Expand Up @@ -383,7 +372,7 @@ class ProjectFilesAccessor(
fun writeTakeCheckingStatus(
fileWriter: IFileWriter,
workbook: Workbook,
takeFilter: (String) -> Boolean = { true }
takeFilter: (String) -> Boolean = { true }
): Completable {
return fetchTakes(workbook)
.filter { takeFilter(it.name) }
Expand Down Expand Up @@ -473,11 +462,7 @@ class ProjectFilesAccessor(
}
}

fun getChapterContent(
projectSlug: String,
chapterNumber: Int,
showVerseNumber: Boolean = true
): List<Content> {
fun getChapterContent(projectSlug: String, chapterNumber: Int, showVerseNumber: Boolean = true): List<Content> {
val chapterContent = arrayListOf<Content>()

ResourceContainer.load(sourceMetadata.path).use { rc ->
Expand Down Expand Up @@ -508,7 +493,7 @@ class ProjectFilesAccessor(
chapterContent.add(content)

// the rest of bridged verses should be marked bridged
for (i in vm.startingVerse + 1..vm.endingVerse) {
for (i in vm.startingVerse+1..vm.endingVerse) {
chapterContent.add(
Content(
sort = chapterContent.size,
Expand All @@ -531,11 +516,7 @@ class ProjectFilesAccessor(
return chapterContent
}

fun getChapterText(
projectSlug: String,
chapterNumber: Int,
showVerseNumber: Boolean = true
): List<String> {
fun getChapterText(projectSlug: String, chapterNumber: Int, showVerseNumber: Boolean = true): List<String> {
val chapterText = arrayListOf<String>()

ResourceContainer.load(sourceMetadata.path).use { rc ->
Expand Down Expand Up @@ -578,8 +559,7 @@ class ProjectFilesAccessor(
val chap = chapters.find { it.number == chapterNumber }
chap?.let {
for (i in startVerse..endVerse) {
val verse =
it.getChildMarkers(VMarker::class.java).find { it.startingVerse == i }
val verse = it.getChildMarkers(VMarker::class.java).find { it.startingVerse == i }
verse?.let {
chunkText.add("${it.verseNumber}. ${it.getText()}")
}
Expand Down Expand Up @@ -752,10 +732,7 @@ class ProjectFilesAccessor(
}
}

private fun deletedTakeFilePaths(
workbook: Workbook,
workbookRepository: IWorkbookRepository
): List<String> {
private fun deletedTakeFilePaths(workbook: Workbook, workbookRepository: IWorkbookRepository): List<String> {
val deletedTakes = workbookRepository
.getSoftDeletedTakes(workbook.source)
.blockingGet()
Expand Down Expand Up @@ -826,20 +803,15 @@ class ProjectFilesAccessor(
fun copyChunkFile(fileReader: IFileReader) {
val outFile = projectDir.resolve(RcConstants.CHUNKS_FILE)
if (!outFile.exists() && fileReader.exists(RcConstants.CHUNKS_FILE)) {
fileReader.stream(RcConstants.CHUNKS_FILE).use { ifs ->
outFile.outputStream().use { ofs ->
ifs.transferTo(ofs)
}
}
fileReader.stream(RcConstants.CHUNKS_FILE).transferTo(outFile.outputStream())
}
}

fun getProjectMode(): ProjectMode? {
val file = projectDir.resolve(RcConstants.PROJECT_MODE_FILE)
return if (file.exists() && file.length() > 0) {
val mapper = ObjectMapper(JsonFactory()).registerKotlinModule()
val serialized: SerializableProjectMode =
mapper.readValue(file, object : TypeReference<SerializableProjectMode>() {})
val serialized: SerializableProjectMode = mapper.readValue(file, object : TypeReference<SerializableProjectMode>() {})
serialized.mode
} else {
null
Expand All @@ -864,11 +836,7 @@ class ProjectFilesAccessor(
fun copyProjectModeFile(fileReader: IFileReader) {
val modeFile = projectDir.resolve(RcConstants.PROJECT_MODE_FILE)
if (fileReader.exists(RcConstants.PROJECT_MODE_FILE)) {
fileReader.stream(RcConstants.PROJECT_MODE_FILE).use { ifs ->
modeFile.outputStream().use { ofs ->
ifs.transferTo(ofs)
}
}
fileReader.stream(RcConstants.PROJECT_MODE_FILE).transferTo(modeFile.outputStream())
}
}

Expand Down

0 comments on commit 69ec7da

Please sign in to comment.