Skip to content

Commit

Permalink
refactor(android): remove deprecated properties on stream callbacks
Browse files Browse the repository at this point in the history
This removes the errorState and errorDescription properties that have been deprecated since sdk
3.0.0

BREAKING CHANGE: Removes deprecated stream callback properties
  • Loading branch information
sgtcoolguy committed Dec 9, 2019
1 parent 41fe06b commit 4b48db8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,18 @@ public static void readAsync(final KrollObject krollObject, final TiStream sourc
public void run()
{
int bytesRead = -1;
int errorState = 0;
String errorDescription = "";
int code = 0;
String error = "";

try {
bytesRead = sourceStream.readSync(buffer, offset, length);

} catch (IOException e) {
e.printStackTrace();
errorState = 1;
errorDescription = e.getMessage();
code = 1;
error = e.getMessage();
}

resultsCallback.callAsync(krollObject,
buildRWCallbackArgs(sourceStream, bytesRead, errorState, errorDescription));
resultsCallback.callAsync(krollObject, buildRWCallbackArgs(sourceStream, bytesRead, code, error));
}
})
.start();
Expand Down Expand Up @@ -279,34 +277,29 @@ public static void writeAsync(final KrollObject krollObject, final TiStream outp
public void run()
{
int bytesWritten = -1;
int errorState = 0;
String errorDescription = "";
int code = 0;
String error = "";

try {
bytesWritten = outputStream.writeSync(buffer, offset, length);

} catch (IOException e) {
e.printStackTrace();
errorState = 1;
errorDescription = e.getMessage();
code = 1;
error = e.getMessage();
}

resultsCallback.callAsync(
krollObject, buildRWCallbackArgs(outputStream, bytesWritten, errorState, errorDescription));
resultsCallback.callAsync(krollObject, buildRWCallbackArgs(outputStream, bytesWritten, code, error));
}
})
.start();
}

public static KrollDict buildRWCallbackArgs(TiStream sourceStream, int bytesProcessed, int errorState,
String errorDescription)
public static KrollDict buildRWCallbackArgs(TiStream sourceStream, int bytesProcessed, int code, String error)
{
KrollDict callbackArgs = new KrollDict();
callbackArgs.put("source", sourceStream);
callbackArgs.put("bytesProcessed", bytesProcessed);
callbackArgs.put("errorState", errorState);
callbackArgs.put("errorDescription", errorDescription);
callbackArgs.putCodeAndMessage(errorState, errorDescription);
callbackArgs.putCodeAndMessage(code, error);

return callbackArgs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ public Object readAll(Object args[]) throws IOException
public void run()
{
int offset = 0;
int errorState = 0;
String errorDescription = "";
int code = 0;
String error = "";

if (fbuffer.getLength() < 1024) {
fbuffer.resize(1024);
Expand All @@ -141,13 +141,12 @@ public void run()
readAllSync(fsourceStream, fbuffer, offset);

} catch (IOException e) {
errorState = 1;
errorDescription = e.getMessage();
code = 1;
error = e.getMessage();
}

fResultsCallback.callAsync(getKrollObject(),
TiStreamHelper.buildRWCallbackArgs(fsourceStream, fbuffer.getLength(),
errorState, errorDescription));
fResultsCallback.callAsync(getKrollObject(), TiStreamHelper.buildRWCallbackArgs(
fsourceStream, fbuffer.getLength(), code, error));
}
})
.start();
Expand Down Expand Up @@ -247,20 +246,20 @@ public int writeStream(Object args[]) throws IOException
public void run()
{
int totalBytesWritten = 0;
int errorState = 0;
String errorDescription = "";
int code = 0;
String error = "";

try {
totalBytesWritten = writeStreamSync(finputStream, foutputStream, fmaxChunkSize);

} catch (IOException e) {
errorState = 1;
errorDescription = e.getMessage();
code = 1;
error = e.getMessage();
}

fResultsCallback.callAsync(getKrollObject(),
buildWriteStreamCallbackArgs(finputStream, foutputStream, totalBytesWritten,
errorState, errorDescription));
fResultsCallback.callAsync(
getKrollObject(),
buildWriteStreamCallbackArgs(finputStream, foutputStream, totalBytesWritten, code, error));
}
})
.start();
Expand Down Expand Up @@ -352,8 +351,6 @@ public void run()
private void pumpSync(TiStream inputStream, KrollFunction handler, int maxChunkSize)
{
int totalBytesRead = 0;
int errorState = 0;
String errorDescription = "";
final KrollObject krollObject = getKrollObject();
try {
while (inputStream.isReadable()) {
Expand All @@ -371,8 +368,7 @@ private void pumpSync(TiStream inputStream, KrollFunction handler, int maxChunkS
}
}

handler.call(krollObject, buildPumpCallbackArgs(inputStream, buffer, bytesRead, totalBytesRead,
errorState, errorDescription));
handler.call(krollObject, buildPumpCallbackArgs(inputStream, buffer, bytesRead, totalBytesRead, 0, ""));
buffer = null;

if (bytesRead == -1) {
Expand All @@ -381,38 +377,32 @@ private void pumpSync(TiStream inputStream, KrollFunction handler, int maxChunkS
}

} catch (IOException e) {
errorState = 1;
errorDescription = e.getMessage();
handler.call(krollObject, buildPumpCallbackArgs(inputStream, new BufferProxy(), 0, totalBytesRead,
errorState, errorDescription));
handler.call(krollObject,
buildPumpCallbackArgs(inputStream, new BufferProxy(), 0, totalBytesRead, 1, e.getMessage()));
}
}

private KrollDict buildWriteStreamCallbackArgs(TiStream fromStream, TiStream toStream, int bytesProcessed,
int errorState, String errorDescription)
private KrollDict buildWriteStreamCallbackArgs(TiStream fromStream, TiStream toStream, int bytesProcessed, int code,
String error)
{
KrollDict callbackArgs = new KrollDict();
callbackArgs.put("fromStream", fromStream);
callbackArgs.put("toStream", toStream);
callbackArgs.put("bytesProcessed", bytesProcessed);
callbackArgs.put("errorState", errorState);
callbackArgs.put("errorDescription", errorDescription);
callbackArgs.putCodeAndMessage(errorState, errorDescription);
callbackArgs.putCodeAndMessage(code, error);

return callbackArgs;
}

private KrollDict buildPumpCallbackArgs(TiStream sourceStream, BufferProxy buffer, int bytesProcessed,
int totalBytesProcessed, int errorState, String errorDescription)
int totalBytesProcessed, int code, String error)
{
KrollDict callbackArgs = new KrollDict();
callbackArgs.put("source", sourceStream);
callbackArgs.put("buffer", buffer);
callbackArgs.put("bytesProcessed", bytesProcessed);
callbackArgs.put("totalBytesProcessed", totalBytesProcessed);
callbackArgs.put("errorState", errorState);
callbackArgs.put("errorDescription", errorDescription);
callbackArgs.putCodeAndMessage(errorState, errorDescription);
callbackArgs.putCodeAndMessage(code, error);

return callbackArgs;
}
Expand Down

0 comments on commit 4b48db8

Please sign in to comment.