Skip to content

Commit

Permalink
some networking refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtursKadikis committed Jan 22, 2024
1 parent e709e03 commit 48ebee9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@RunWith(AndroidJUnit4.class)
public class ModuleUserProfileTests {
Expand Down
10 changes: 6 additions & 4 deletions sdk/src/main/java/ly/count/android/sdk/ConnectionProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ of this software and associated documentation files (the "Software"), to deal
*/
package ly.count.android.sdk;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -49,6 +51,8 @@ public class ConnectionProcessor implements Runnable {
private static final int CONNECT_TIMEOUT_IN_MILLISECONDS = 30000;
private static final int READ_TIMEOUT_IN_MILLISECONDS = 30000;

private static final String CRLF = "\r\n";
private static final String charset = "UTF-8";
private final StorageProvider storageProvider_;
private final DeviceIdProvider deviceIdProvider_;
final ConfigurationProvider configProvider_;
Expand Down Expand Up @@ -86,7 +90,7 @@ private enum RequestResult {
this.healthTracker = healthTracker;
}

synchronized public URLConnection urlConnectionForServerRequest(String requestData, final String customEndpoint) throws IOException {
synchronized public @NonNull URLConnection urlConnectionForServerRequest(@NonNull String requestData, @Nullable final String customEndpoint) throws IOException {
String urlEndpoint = "/i";
if (customEndpoint != null) {
urlEndpoint = customEndpoint;
Expand Down Expand Up @@ -148,8 +152,6 @@ synchronized public URLConnection urlConnectionForServerRequest(String requestDa
// Just generate some unique random value.
String boundary = Long.toHexString(System.currentTimeMillis());
// Line separator required by multipart/form-data.
String CRLF = "\r\n";
String charset = "UTF-8";
conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
OutputStream output = conn.getOutputStream();
PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, charset), true);
Expand Down Expand Up @@ -181,7 +183,7 @@ synchronized public URLConnection urlConnectionForServerRequest(String requestDa
conn.setDoOutput(true);
conn.setRequestMethod("POST");
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, charset));
writer.write(requestData);
writer.flush();
writer.close();
Expand Down

0 comments on commit 48ebee9

Please sign in to comment.