use of org.whispersystems.signalservice.api.crypto.DigestingOutputStream in project libsignal-service-java by signalapp.
the class DigestingRequestBody method writeTo.
@Override
public void writeTo(BufferedSink sink) throws IOException {
DigestingOutputStream outputStream = outputStreamFactory.createFor(sink.outputStream());
byte[] buffer = new byte[8192];
int read;
long total = 0;
while ((read = inputStream.read(buffer, 0, buffer.length)) != -1) {
outputStream.write(buffer, 0, read);
total += read;
if (progressListener != null) {
progressListener.onAttachmentProgress(contentLength, total);
}
}
outputStream.flush();
digest = outputStream.getTransmittedDigest();
}
use of org.whispersystems.signalservice.api.crypto.DigestingOutputStream in project libsignal-service-java by signalapp.
the class PushServiceSocket method uploadAttachment.
private byte[] uploadAttachment(String method, String url, InputStream data, long dataSize, OutputStreamFactory outputStreamFactory, ProgressListener listener) throws IOException {
URL uploadUrl = new URL(url);
HttpsURLConnection connection = (HttpsURLConnection) uploadUrl.openConnection();
connection.setDoOutput(true);
if (dataSize > 0) {
connection.setFixedLengthStreamingMode(Util.toIntExact(dataSize));
} else {
connection.setChunkedStreamingMode(0);
}
connection.setRequestMethod(method);
connection.setRequestProperty("Content-Type", "application/octet-stream");
connection.setRequestProperty("Connection", "close");
connection.connect();
try {
DigestingOutputStream out = outputStreamFactory.createFor(connection.getOutputStream());
byte[] buffer = new byte[4096];
int read, written = 0;
while ((read = data.read(buffer)) != -1) {
out.write(buffer, 0, read);
written += read;
if (listener != null) {
listener.onAttachmentProgress(dataSize, written);
}
}
out.flush();
data.close();
out.close();
if (connection.getResponseCode() != 200) {
throw new IOException("Bad response: " + connection.getResponseCode() + " " + connection.getResponseMessage());
}
return out.getTransmittedDigest();
} finally {
connection.disconnect();
}
}
use of org.whispersystems.signalservice.api.crypto.DigestingOutputStream 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();
}
use of org.whispersystems.signalservice.api.crypto.DigestingOutputStream 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();
}
Aggregations