Skip to content

Commit

Permalink
close stream after content loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
b3er committed Feb 18, 2022
1 parent a7973a2 commit 29b3364
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.b3er.idea.plugins.arc.browser.base.sevenzip

import com.Ostermiller.util.CircularByteBuffer
import com.github.b3er.idea.plugins.arc.browser.formats.sevenzip.SevenZipArchiveHolder
import net.sf.sevenzipjbinding.ExtractOperationResult
import net.sf.sevenzipjbinding.simple.ISimpleInArchiveItem
import java.io.File
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.b3er.idea.plugins.arc.browser.formats.sevenzip

import com.github.b3er.idea.plugins.arc.browser.base.BaseArchiveFileSystem
import com.github.b3er.idea.plugins.arc.browser.base.sevenzip.SevenZipArchiveHandler
import com.github.b3er.idea.plugins.arc.browser.util.FSUtils
import com.intellij.openapi.fileTypes.FileType
import com.intellij.openapi.vfs.VirtualFileManager
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.github.b3er.idea.plugins.arc.browser.base.sevenzip
package com.github.b3er.idea.plugins.arc.browser.formats.sevenzip

import com.github.b3er.idea.plugins.arc.browser.base.BaseArchiveHandler
import com.github.b3er.idea.plugins.arc.browser.base.nest.SupportsStreamForVirtualFile
import com.github.b3er.idea.plugins.arc.browser.base.sevenzip.SevenZipInputStream
import com.github.b3er.idea.plugins.arc.browser.util.FSUtils
import com.github.b3er.idea.plugins.arc.browser.util.getAndUse
import com.intellij.openapi.util.io.FileTooBigException
Expand All @@ -26,14 +27,16 @@ class SevenZipArchiveHandler(
if (FileUtilRt.isTooLarge(item.size ?: DEFAULT_LENGTH)) {
throw FileTooBigException("$file!/$relativePath")
} else {
ByteArrayOutputStream(
item.size?.toInt()?.coerceAtLeast(DEFAULT_BUFFER_SIZE) ?: SevenZipInputStream.BUFFER_SIZE
).use { stream ->
item.extractSlow {
stream.write(it)
it.size
holder.useStream {
ByteArrayOutputStream(
item.size?.toInt()?.coerceAtLeast(DEFAULT_BUFFER_SIZE) ?: SevenZipInputStream.BUFFER_SIZE
).use { stream ->
item.extractSlow { bytes ->
stream.write(bytes)
bytes.size
}
stream.toByteArray()
}
stream.toByteArray()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.b3er.idea.plugins.arc.browser.base.sevenzip
package com.github.b3er.idea.plugins.arc.browser.formats.sevenzip

import com.github.b3er.idea.plugins.arc.browser.base.sevenzip.ReusableRandomAccessFileStream
import net.sf.sevenzipjbinding.IInArchive
import net.sf.sevenzipjbinding.IInStream
import net.sf.sevenzipjbinding.SevenZip
Expand Down

0 comments on commit 29b3364

Please sign in to comment.