jpype-project / jpype

JPype is cross language bridge to allow Python programs full access to Java class libraries.
http://www.jpype.org
Apache License 2.0
1.12k stars 181 forks source link

Any way to convert IOBase into InputStream? #1001

Open gciatto opened 3 years ago

gciatto commented 3 years ago

... or TextIOBase into Reader?

It would be very nice to open a file with open() and pass the returned IOBase to a Java method accepting an InputStream or a Reader

Thrameos commented 3 years ago

As of JPype 1.3 it is not possible.

It is technically possible but the Python to Java bridge would need to be used to make it easy. Because then Java InputStream can be directly implemented in Java.

There is another way to achieve the result without the reverse bridge, but it would require another support class in org.jpype. It would require an interface in Java which provides services that Python can use JProxy to implement. The wrapper can then forward to InputStream requests to IOBase. Thus it requires 3 pieces. It would be a 2 to 4 hour task.

gciatto commented 3 years ago

Maybe I see your point. In the next days, I'll try to implement the second solution without affecting org.jpype (i.e. with some external jar). Maybe you could then integrate that in org.jpype?

Thrameos commented 3 years ago

Sure that would be a great PR. It shouldn't be too difficult. You just need to

Ahsan-Aziz-Ishan commented 9 months ago

Any update with this ?