1

Can anyone give me a hint how to work with Android InputStream in native code.

More specific example: Java code

public class SomeParser {
    public native ArrayList<String> parse(InputStream stream);
}

I need to read InputStream in native and return matching patterns to Android Java code. stream is BufferedInputStream from HttpRequest

1 Answer 1

3

You needd to pass a reference to the Stream through JNI to your native code, and then use JNI calls to act upon it. You will probably get java byte-arrays. These you can copy to native arrays using JNI. It is all standard JNI.

Sign up to request clarification or add additional context in comments.

3 Comments

So it seems no way to work with Java InputStream as with C iostream? Main idea that Java code (atm) fetching Http and gives to native code work with inputstream so it can be loaded into something like pugixml.
A java object is not an extension of a C++ std::iostream, or a C FILE*. There is no (statndard) way to convert these. You will have to manipulate the Java object though the JNI interface from your native code. This is cumbersome and very error prone, compared to the native Java calls.
Thanks. Looks like I will pass ByteArray to native, at least 'till network communication will be on Java side. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.