Skip to content

Commit

Permalink
- Allowing for any serializer library
Browse files Browse the repository at this point in the history
- Removing IO Utils dependency
  • Loading branch information
adroitandroid committed May 18, 2017
1 parent 76177ae commit a18cdff
Show file tree
Hide file tree
Showing 4 changed files with 878 additions and 869 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ repositories {
dependencies {
compile 'com.android.support:support-annotations:23.1.1'
compile 'com.arasthel:asyncjob-library:1.0.3'
compile 'commons-io:commons-io:2.4'
apt 'com.bluelinelabs:logansquare-compiler:1.0.6'
compile 'com.bluelinelabs:logansquare:1.0.6'
}
15 changes: 12 additions & 3 deletions src/main/java/com/peak/salut/BackgroundDataJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

import com.arasthel.asyncjob.AsyncJob;

import org.apache.commons.io.IOUtils;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.net.Socket;


Expand All @@ -29,7 +28,17 @@ public void doOnBackground() {
Log.v(Salut.TAG, "A device is sending data...");

BufferedInputStream dataStreamFromOtherDevice = new BufferedInputStream(clientSocket.getInputStream());
data = new String(IOUtils.toByteArray(dataStreamFromOtherDevice));

// http://stackoverflow.com/a/35446009/4411645
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = dataStreamFromOtherDevice.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
// StandardCharsets.UTF_8.name() > JDK 7
data = result.toString("UTF-8");

dataStreamFromOtherDevice.close();

Log.d(Salut.TAG, "\nSuccessfully received data.\n");
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/com/peak/salut/BackgroundDataSendJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import android.util.Log;

import com.arasthel.asyncjob.AsyncJob;
import com.bluelinelabs.logansquare.LoganSquare;
import com.peak.salut.Callbacks.SalutCallback;

import org.apache.commons.io.Charsets;

import java.io.BufferedOutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.charset.Charset;

public class BackgroundDataSendJob implements AsyncJob.OnBackgroundJob {

Expand Down Expand Up @@ -42,9 +40,9 @@ public void doOnBackground() {
Log.d(Salut.TAG, "Connected, transferring data...");
BufferedOutputStream dataStreamToOtherDevice = new BufferedOutputStream(dataSocket.getOutputStream());

String dataToSend = LoganSquare.serialize(data);
String dataToSend = salutInstance.serialize(data);

dataStreamToOtherDevice.write(dataToSend.getBytes(Charsets.UTF_8));
dataStreamToOtherDevice.write(dataToSend.getBytes(Charset.forName("UTF-8")));
dataStreamToOtherDevice.flush();
dataStreamToOtherDevice.close();

Expand Down
Loading

0 comments on commit a18cdff

Please sign in to comment.