Skip to content

Instantly share code, notes, and snippets.

@illuzor illuzor/SendBytes.java forked from alebianco/SendBytes.java
Last active Aug 29, 2015

Embed
What would you like to do?
/**
* 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
You can’t perform that action at this time.