Skip to content

Commit

Permalink
Pivotal ID # 186496317: Too Many Open Files (#774)
Browse files Browse the repository at this point in the history
https://www.pivotaltracker.com/story/show/186496317

- Improve method signature
- Close InputStream after using it
  • Loading branch information
jhoanmanuelms authored Nov 17, 2023
1 parent e57cabe commit 03730da
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ebi.ac.uk.io.ext.isEmpty
import ebi.ac.uk.io.ext.notExist
import ebi.ac.uk.io.ext.size
import org.apache.commons.codec.digest.DigestUtils
import org.springframework.core.io.InputStreamSource
import java.io.File
import java.io.InputStream
import java.nio.file.FileAlreadyExistsException
Expand Down Expand Up @@ -44,10 +45,12 @@ object FileUtils {
}

fun copyOrReplaceFile(
source: InputStream,
source: InputStreamSource,
target: File,
permissions: Permissions,
) = FileUtilsHelper.copyFile(source, target.toPath(), permissions)
) {
source.inputStream.use { FileUtilsHelper.copyFile(it, target.toPath(), permissions) }
}

fun getOrCreateFolder(
folder: Path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal fun transferTo(basePath: Path, file: MultipartFile) {
val expectedFilePath = basePath.resolve(file.originalFilename!!)
FileUtils.createParentFolders(expectedFilePath, RWXRWX___)
FileUtils.copyOrReplaceFile(
source = file.inputStream,
source = file,
target = expectedFilePath.toFile(),
permissions = Permissions(RW_RW____, RWXRWX___)
)
Expand Down

0 comments on commit 03730da

Please sign in to comment.