How to use a native File Handle obtained with CreateFile and JNIWrapper in java FileInputStream

17 views
Skip to first unread message

rarc...@gmail.com

unread,
Mar 25, 2019, 2:37:27 PM3/25/19
to JNIWrapper Forum
I am using JNIWrapper to wrap Windows CreateFile call so that I can open a handle to file with custom accessMode and shareMode options.  I am also using JNIWrapper to call Windows api ReadFile and WriteFile using the JNIWrapper MemoryBuffer class.  For performance and memory usages reasons I would like to be able to use the CreateFile JNIWrapper Handle value to set the FD value in FileInputStream class, but cannot figure out a way to set this?

Any thoughts would be appreciated?

Thanks,

Rob Arciere
Peer Software, Inc.

Natasha Dmitrieva

unread,
Mar 26, 2019, 5:47:09 AM3/26/19
to rarc...@gmail.com, Customer Care
Hi Rob,
Thank you for our question.

Unfortunately, there seems to be no straightforward way to use the existing handle with Java streams, because Java itself does not provide any API that can be used to create a custom FileDescriptor object.

However, as a possible approach you can try creating a FileDescriptor object using its default constructor and setting its private int field "handle" via reflection. The sample code demonstrating this approach is attached to this reply.
Could you please try it and let us know the results?

Best regards,
Natasha

--
You received this message because you are subscribed to the Google Groups "JNIWrapper Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jniwrapper-for...@teamdev.com.
To view this discussion on the web visit https://groups.google.com/a/teamdev.com/d/msgid/jniwrapper-forum/b4e9ac07-5006-4978-a075-13c96c0c1920%40teamdev.com.
Test.java
Reply all
Reply to author
Forward
0 new messages