Search in sources :

Example 1 with SkippingOutputStream

use of org.whispersystems.signalservice.api.crypto.SkippingOutputStream in project Signal-Android by WhisperSystems.

the class DigestingRequestBody method writeTo.

@Override
public void writeTo(BufferedSink sink) throws IOException {
    DigestingOutputStream outputStream = outputStreamFactory.createFor(new SkippingOutputStream(contentStart, sink.outputStream()));
    byte[] buffer = new byte[8192];
    int read;
    long total = 0;
    while ((read = inputStream.read(buffer, 0, buffer.length)) != -1) {
        if (cancelationSignal != null && cancelationSignal.isCanceled()) {
            throw new IOException("Canceled!");
        }
        outputStream.write(buffer, 0, read);
        total += read;
        if (progressListener != null) {
            progressListener.onAttachmentProgress(contentLength, total);
        }
    }
    outputStream.flush();
    digest = outputStream.getTransmittedDigest();
}
Also used : DigestingOutputStream(org.whispersystems.signalservice.api.crypto.DigestingOutputStream) SkippingOutputStream(org.whispersystems.signalservice.api.crypto.SkippingOutputStream) IOException(java.io.IOException)

Example 2 with SkippingOutputStream

use of org.whispersystems.signalservice.api.crypto.SkippingOutputStream in project Signal-Android by signalapp.

the class DigestingRequestBody method writeTo.

@Override
public void writeTo(BufferedSink sink) throws IOException {
    DigestingOutputStream outputStream = outputStreamFactory.createFor(new SkippingOutputStream(contentStart, sink.outputStream()));
    byte[] buffer = new byte[8192];
    int read;
    long total = 0;
    while ((read = inputStream.read(buffer, 0, buffer.length)) != -1) {
        if (cancelationSignal != null && cancelationSignal.isCanceled()) {
            throw new IOException("Canceled!");
        }
        outputStream.write(buffer, 0, read);
        total += read;
        if (progressListener != null) {
            progressListener.onAttachmentProgress(contentLength, total);
        }
    }
    outputStream.flush();
    digest = outputStream.getTransmittedDigest();
}
Also used : DigestingOutputStream(org.whispersystems.signalservice.api.crypto.DigestingOutputStream) SkippingOutputStream(org.whispersystems.signalservice.api.crypto.SkippingOutputStream) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 DigestingOutputStream (org.whispersystems.signalservice.api.crypto.DigestingOutputStream)2 SkippingOutputStream (org.whispersystems.signalservice.api.crypto.SkippingOutputStream)2