Issue1204

classification
Title: Unable to create file object from Java InputStream
Type: behaviour Severity: major
Components: Core Versions: 2.5b0
Milestone:
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: amak, cgroves, kam
Priority: Keywords:

Created on 2008-12-15.19:59:15 by kam, last changed 2008-12-18.20:29:15 by amak.

Messages
msg3929 (view) Author: Kevin A. Mitchell (kam) Date: 2008-12-15.19:59:15
It is no longer possible to create a file object from a Java
InputStream. This last worked for me in 2.5a1.

Simple test:

from __future__ import with_statement

from java.io import FileInputStream as FIS
from org.python.core import PyFile

with open("in.txt","w") as f:
    f.write("spam!\n")

# Neither constructor works
PyFile(FIS("in.txt"))
file(FIS("in.txt"))

Fails with:

Traceback (most recent call last):
  File "filestream.py", line 10, in <module>
    PyFile(FIS("in.txt"))
TypeError: coercing to Unicode: need string, 'javainstance' type found
msg3963 (view) Author: Alan Kennedy (amak) Date: 2008-12-18.20:29:14
I encountered this exact problem with modjy, which broke after jython
2.5b0. I reported it as an issue

http://bugs.jython.org/issue1171

The cause was a backwards incompatible API change.

You need to change your code as described in that issue.

If you need for your code to work on all versions, you can do what modjy
now does, as follows

try:
    from org.python.core.util import FileUtil
    create_py_file = FileUtil.wrap
except ImportError:
    from org.python.core import PyFile
    create_py_file = PyFile

my_file = create_py_file(FileInputStream("in.txt"))

HTH.
History
Date User Action Args
2008-12-18 20:29:15amaksetstatus: open -> closed
nosy: + amak
resolution: duplicate
messages: + msg3963
2008-12-18 19:17:23cgrovessetnosy: + cgroves
2008-12-15 19:59:15kamcreate