org.whispersystems.signalservice.internal.push.http.OutputStreamFactory Java Examples

The following examples show how to use org.whispersystems.signalservice.internal.push.http.OutputStreamFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PushAttachmentData.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public PushAttachmentData(String contentType, InputStream data, long dataSize,
                          OutputStreamFactory outputStreamFactory,
                          ProgressListener listener, CancelationSignal cancelationSignal,
                          ResumableUploadSpec resumableUploadSpec)
{
  this.contentType             = contentType;
  this.data                    = data;
  this.dataSize                = dataSize;
  this.outputStreamFactory     = outputStreamFactory;
  this.resumableUploadSpec     = resumableUploadSpec;
  this.listener                = listener;
  this.cancelationSignal       = cancelationSignal;
}
 
Example #2
Source File: PushAttachmentData.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public PushAttachmentData(String contentType, InputStream data, long dataSize,
                          OutputStreamFactory outputStreamFactory, ProgressListener listener)
{
  this.contentType         = contentType;
  this.data                = data;
  this.dataSize            = dataSize;
  this.outputStreamFactory = outputStreamFactory;
  this.listener            = listener;
}
 
Example #3
Source File: PushAttachmentData.java    From libsignal-service-java with GNU General Public License v3.0 5 votes vote down vote up
public PushAttachmentData(String contentType, InputStream data, long dataSize,
                          OutputStreamFactory outputStreamFactory, ProgressListener listener)
{
  this.contentType         = contentType;
  this.data                = data;
  this.dataSize            = dataSize;
  this.outputStreamFactory = outputStreamFactory;
  this.listener            = listener;
}
 
Example #4
Source File: PushServiceSocket.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private byte[] uploadToCdn0(String path, String acl, String key, String policy, String algorithm,
                            String credential, String date, String signature,
                            InputStream data, String contentType, long length,
                            OutputStreamFactory outputStreamFactory, ProgressListener progressListener,
                            CancelationSignal cancelationSignal)
    throws PushNetworkException, NonSuccessfulResponseCodeException
{
  ConnectionHolder connectionHolder = getRandom(cdnClientsMap.get(0), random);
  OkHttpClient     okHttpClient     = connectionHolder.getClient()
                                                      .newBuilder()
                                                      .connectTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS)
                                                      .readTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS)
                                                      .build();

  DigestingRequestBody file = new DigestingRequestBody(data, outputStreamFactory, contentType, length, progressListener, cancelationSignal, 0);

  RequestBody requestBody = new MultipartBody.Builder()
                                             .setType(MultipartBody.FORM)
                                             .addFormDataPart("acl", acl)
                                             .addFormDataPart("key", key)
                                             .addFormDataPart("policy", policy)
                                             .addFormDataPart("Content-Type", contentType)
                                             .addFormDataPart("x-amz-algorithm", algorithm)
                                             .addFormDataPart("x-amz-credential", credential)
                                             .addFormDataPart("x-amz-date", date)
                                             .addFormDataPart("x-amz-signature", signature)
                                             .addFormDataPart("file", "file", file)
                                             .build();

  Request.Builder request = new Request.Builder()
                                       .url(connectionHolder.getUrl() + "/" + path)
                                       .post(requestBody);

  if (connectionHolder.getHostHeader().isPresent()) {
    request.addHeader("Host", connectionHolder.getHostHeader().get());
  }

  Call call = okHttpClient.newCall(request.build());

  synchronized (connections) {
    connections.add(call);
  }

  try {
    Response response;

    try {
      response = call.execute();
    } catch (IOException e) {
      throw new PushNetworkException(e);
    }

    if (response.isSuccessful()) return file.getTransmittedDigest();
    else                         throw new NonSuccessfulResponseCodeException("Response: " + response);
  } finally {
    synchronized (connections) {
      connections.remove(call);
    }
  }
}
 
Example #5
Source File: PushServiceSocket.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private byte[] uploadToCdn2(String resumableUrl, InputStream data, String contentType, long length, OutputStreamFactory outputStreamFactory, ProgressListener progressListener, CancelationSignal cancelationSignal) throws IOException {
  ConnectionHolder connectionHolder = getRandom(cdnClientsMap.get(2), random);
  OkHttpClient     okHttpClient     = connectionHolder.getClient()
                                                      .newBuilder()
                                                      .connectTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS)
                                                      .readTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS)
                                                      .build();

  ResumeInfo           resumeInfo = getResumeInfo(resumableUrl, length);
  DigestingRequestBody file       = new DigestingRequestBody(data, outputStreamFactory, contentType, length, progressListener, cancelationSignal, resumeInfo.contentStart);

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

  Request.Builder request = new Request.Builder().url(resumableUrl)
                                                 .put(file)
                                                 .addHeader("Content-Range", resumeInfo.contentRange);

  if (connectionHolder.getHostHeader().isPresent()) {
    request.header("host", connectionHolder.getHostHeader().get());
  }

  Call call = okHttpClient.newCall(request.build());

  synchronized (connections) {
    connections.add(call);
  }

  try {
    Response response;

    try {
      response = call.execute();
    } catch (IOException e) {
      throw new PushNetworkException(e);
    }

    if (response.isSuccessful()) return file.getTransmittedDigest();
    else                         throw new NonSuccessfulResponseCodeException("Response: " + response);
  } finally {
    synchronized (connections) {
      connections.remove(call);
    }
  }
}
 
Example #6
Source File: PushAttachmentData.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public OutputStreamFactory getOutputStreamFactory() {
  return outputStreamFactory;
}
 
Example #7
Source File: ProfileAvatarData.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public ProfileAvatarData(InputStream data, long dataLength, String contentType, OutputStreamFactory outputStreamFactory) {
  this.data                = data;
  this.dataLength          = dataLength;
  this.contentType         = contentType;
  this.outputStreamFactory = outputStreamFactory;
}
 
Example #8
Source File: ProfileAvatarData.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public OutputStreamFactory getOutputStreamFactory() {
  return outputStreamFactory;
}
 
Example #9
Source File: PushAttachmentData.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
public OutputStreamFactory getOutputStreamFactory() {
  return outputStreamFactory;
}
 
Example #10
Source File: ProfileAvatarData.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
public ProfileAvatarData(InputStream data, long dataLength, String contentType, OutputStreamFactory outputStreamFactory) {
  this.data                = data;
  this.dataLength          = dataLength;
  this.contentType         = contentType;
  this.outputStreamFactory = outputStreamFactory;
}
 
Example #11
Source File: ProfileAvatarData.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
public OutputStreamFactory getOutputStreamFactory() {
  return outputStreamFactory;
}
 
Example #12
Source File: PushServiceSocket.java    From libsignal-service-java with GNU General Public License v3.0 4 votes vote down vote up
private byte[] uploadToCdn(String path, String acl, String key, String policy, String algorithm,
                           String credential, String date, String signature,
                           InputStream data, String contentType, long length,
                           OutputStreamFactory outputStreamFactory, ProgressListener progressListener)
    throws PushNetworkException, NonSuccessfulResponseCodeException
{
  ConnectionHolder connectionHolder = getRandom(cdnClients, random);
  OkHttpClient     okHttpClient     = connectionHolder.getClient()
                                                      .newBuilder()
                                                      .connectTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS)
                                                      .readTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS)
                                                      .build();

  DigestingRequestBody file = new DigestingRequestBody(data, outputStreamFactory, contentType, length, progressListener);

  RequestBody requestBody = new MultipartBody.Builder()
      .setType(MultipartBody.FORM)
      .addFormDataPart("acl", acl)
      .addFormDataPart("key", key)
      .addFormDataPart("policy", policy)
      .addFormDataPart("Content-Type", contentType)
      .addFormDataPart("x-amz-algorithm", algorithm)
      .addFormDataPart("x-amz-credential", credential)
      .addFormDataPart("x-amz-date", date)
      .addFormDataPart("x-amz-signature", signature)
      .addFormDataPart("file", "file", file)
      .build();

  Request.Builder request = new Request.Builder()
                                       .url(connectionHolder.getUrl() + "/" + path)
                                       .post(requestBody);

  if (connectionHolder.getHostHeader().isPresent()) {
    request.addHeader("Host", connectionHolder.getHostHeader().get());
  }

  Call call = okHttpClient.newCall(request.build());

  synchronized (connections) {
    connections.add(call);
  }

  try {
    Response response;

    try {
      response = call.execute();
    } catch (IOException e) {
      throw new PushNetworkException(e);
    }

    if (response.isSuccessful()) return file.getTransmittedDigest();
    else                         throw new NonSuccessfulResponseCodeException("Response: " + response);
  } finally {
    synchronized (connections) {
      connections.remove(call);
    }
  }
}
 
Example #13
Source File: PushAttachmentData.java    From libsignal-service-java with GNU General Public License v3.0 4 votes vote down vote up
public OutputStreamFactory getOutputStreamFactory() {
  return outputStreamFactory;
}
 
Example #14
Source File: ProfileAvatarData.java    From libsignal-service-java with GNU General Public License v3.0 4 votes vote down vote up
public ProfileAvatarData(InputStream data, long dataLength, String contentType, OutputStreamFactory outputStreamFactory) {
  this.data                = data;
  this.dataLength          = dataLength;
  this.contentType         = contentType;
  this.outputStreamFactory = outputStreamFactory;
}
 
Example #15
Source File: ProfileAvatarData.java    From libsignal-service-java with GNU General Public License v3.0 4 votes vote down vote up
public OutputStreamFactory getOutputStreamFactory() {
  return outputStreamFactory;
}