mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Show buffer copy
This commit is contained in:
@@ -124,11 +124,9 @@ class BinaryAttachment : Parcelable {
|
||||
if (!isCompressed) {
|
||||
// Encrypt the new gzipped temp file
|
||||
val fileBinaryCompress = File(concreteDataFile.parent, concreteDataFile.name + "_temp")
|
||||
GZIPOutputStream(buildOutputStream(fileBinaryCompress, cipherKey)).use { outputStream ->
|
||||
getInputDataStream(cipherKey).use { inputStream ->
|
||||
inputStream.readAllBytes(bufferSize) { buffer ->
|
||||
outputStream.write(buffer)
|
||||
}
|
||||
GZIPOutputStream(buildOutputStream(fileBinaryCompress, cipherKey)).use { outputStream ->
|
||||
inputStream.copyTo(outputStream, bufferSize)
|
||||
}
|
||||
}
|
||||
// Remove ungzip file
|
||||
@@ -148,11 +146,9 @@ class BinaryAttachment : Parcelable {
|
||||
if (isCompressed) {
|
||||
// Encrypt the new ungzipped temp file
|
||||
val fileBinaryDecompress = File(concreteDataFile.parent, concreteDataFile.name + "_temp")
|
||||
buildOutputStream(fileBinaryDecompress, cipherKey).use { outputStream ->
|
||||
getUnGzipInputDataStream(cipherKey).use { inputStream ->
|
||||
inputStream.readAllBytes(bufferSize) { buffer ->
|
||||
outputStream.write(buffer)
|
||||
}
|
||||
buildOutputStream(fileBinaryDecompress, cipherKey).use { outputStream ->
|
||||
inputStream.copyTo(outputStream, bufferSize)
|
||||
}
|
||||
}
|
||||
// Remove gzip file
|
||||
@@ -225,6 +221,12 @@ class BinaryAttachment : Parcelable {
|
||||
init {
|
||||
length = 0
|
||||
}
|
||||
|
||||
override fun beforeWrite(n: Int) {
|
||||
super.beforeWrite(n)
|
||||
length = byteCount
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
super.close()
|
||||
length = byteCount
|
||||
|
||||
@@ -400,9 +400,9 @@ class AttachmentFileNotificationService: LockNotificationService() {
|
||||
var dataUploaded = 0L
|
||||
val fileSize = contentResolver.openFileDescriptor(attachmentFromDownloadUri, "r")?.statSize ?: 0
|
||||
UriUtil.getUriInputStream(contentResolver, attachmentFromDownloadUri)?.let { inputStream ->
|
||||
BufferedInputStream(inputStream).use { attachmentBufferedInputStream ->
|
||||
Database.getInstance().loadedCipherKey?.let { binaryCipherKey ->
|
||||
binaryAttachment.getGzipOutputDataStream(binaryCipherKey).use { outputStream ->
|
||||
BufferedInputStream(inputStream).use { attachmentBufferedInputStream ->
|
||||
attachmentBufferedInputStream.readAllBytes(bufferSize) { buffer ->
|
||||
outputStream.write(buffer)
|
||||
dataUploaded += buffer.size
|
||||
|
||||
@@ -32,7 +32,19 @@ import java.util.*
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
fun InputStream.readAllBytes(bufferSize: Int, readBytes: (bytesRead: ByteArray) -> Unit) {
|
||||
readBytes.invoke(readBytes(bufferSize))
|
||||
val buffer = ByteArray(bufferSize)
|
||||
var read = 0
|
||||
while (read != -1) {
|
||||
read = this.read(buffer, 0, buffer.size)
|
||||
if (read != -1) {
|
||||
val optimizedBuffer: ByteArray = if (buffer.size == read) {
|
||||
buffer
|
||||
} else {
|
||||
buffer.copyOf(read)
|
||||
}
|
||||
readBytes.invoke(optimizedBuffer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user