Skip to content

Instantly share code, notes, and snippets.

@illuzor
Forked from alebianco/SendBytes.java
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save illuzor/fb8dd25d68d1743e17c6 to your computer and use it in GitHub Desktop.
Save illuzor/fb8dd25d68d1743e17c6 to your computer and use it in GitHub Desktop.
/**
* Project: ANE-Google-Analytics
*
* Author: Alessandro Bianco
* Website: http://alessandrobianco.eu
* Twitter: @alebianco
* Created: 23/12/12 10.42
*
* Copyright © 2013 Alessandro Bianco
*/
package eu.alebianco.air.extensions.analytics.functions;
import android.util.Log;
import com.adobe.fre.FREByteArray;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;
import java.nio.ByteBuffer;
public class SendBytes implements FREFunction {
@Override
public FREObject call(FREContext context, FREObject[] args) {
try {
FREByteArray ba = (FREByteArray) args[0];
ba.acquire();
ByteBuffer bb = ba.getBytes();
byte[] bytes = new byte[(int) ba.getLength()];
bb.get(bytes);
String str = new String(bytes);
Log.d("ANE", "My ByteArray is long " + bytes.length + " bytes and contains '" + str + "'");
ba.release();
} catch (Exception e) {
Log.e("ANE", "An error occurred while reading the ByteArray", e);
}
FREByteArray result = null;
try {
result = FREByteArray.newByteArray();
FREObject content = FREObject.newObject("hello to you!");
FREObject[] params = new FREObject[] {content};
result.callMethod("writeUTFBytes", params);
} catch (Exception e) {
Log.e("ANE", "An error occurred while writing the ByteArray", e);
}
return result;
}
}
// After initializing the extension ...
var ba:ByteArray = new ByteArray()
ba.writeUTFBytes("hello world");
var reply:ByteArray = context.call("sendBytes", ba) as ByteArray;
trace(reply.readUTF());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment