Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1031,9 +1031,7 @@ private AttachmentDigest uploadToCdn2(String resumableUrl, InputStream data, Str

if (resumeInfo.contentStart == length) {
Log.w(TAG, "Resume start point == content length");
try (NowhereBufferedSink buffer = new NowhereBufferedSink()) {
file.writeTo(buffer);
}
file.writeToNowhere();
return file.getAttachmentDigest();
}

Expand Down Expand Up @@ -1103,9 +1101,7 @@ private AttachmentDigest uploadToCdn3(String resumableUrl,

if (resumeInfo.contentStart == length) {
Log.w(TAG, "Resume start point == content length");
try (NowhereBufferedSink buffer = new NowhereBufferedSink()) {
file.writeTo(buffer);
}
file.writeToNowhere();
return file.getAttachmentDigest();
} else if (resumeInfo.contentStart != 0) {
Log.w(TAG, "Resuming previous attachment upload");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.whispersystems.signalservice.internal.crypto.AttachmentDigest
import java.io.ByteArrayOutputStream
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream

/**
* This [RequestBody] encrypts the data written to it before it is sent.
Expand All @@ -40,10 +41,26 @@ class DigestingRequestBody(
return contentType.toMediaTypeOrNull()
}

/**
* nowhereOutputStream allows a programmer to write out data into the void. This has no memory
* implications, as we don't actually store bytes.
*/
private val nowhereOutputStream = OutputStream.nullOutputStream()

@Throws(IOException::class)
fun writeToNowhere() {
writeToImpl(nowhereOutputStream)
}

@Throws(IOException::class)
override fun writeTo(sink: BufferedSink) {
writeToImpl(sink.outputStream())
}

@Throws(IOException::class)
private fun writeToImpl(outputStream: OutputStream) {
val digestStream = ByteArrayOutputStream()
val inner = SkippingOutputStream(contentStart, NonClosingOutputStream(sink.outputStream()))
val inner = SkippingOutputStream(contentStart, NonClosingOutputStream(outputStream))
val isIncremental = incremental && outputStreamFactory is AttachmentCipherOutputStreamFactory
val sizeChoice: ChunkSizeChoice = ChunkSizeChoice.inferChunkSize(contentLength.toInt())
val outputStream: DigestingOutputStream = if (isIncremental) {
Expand Down