Dear John,

A little sample, mixing Java  ByteArrayInputStream and String classes with the Jython byte array buffers and Python character conversion:

#ByteArrayInputStream demo
from import ByteArrayInputStream
from java.lang import String as javaString
from jarray import array, zeros
tmp = javaString("abcdefghijklmnopqrstuvwxyz")
b = tmp.getBytes();
bais = ByteArrayInputStream(b)  
length = bais.available()
print ('length = ' + str(length))
buff = zeros(length, 'b')
theChars = ''
for i in range(1,length+1):
   theChars += chr(buff[i-1])
print ('theChars = ' + str(theChars))

length = 26
theChars = abcdefghijklmnopqrstuvwxyz


Claude Falbriard
AMS Hortolāndia / SP - Brazil
phone:    +55 13 9762 4094
cell:         +55 13 8117 3316

From: John Goodleaf <>
Date: 29/06/2010 16:15
Subject: [Jython-users] newbie help reading ByteArrayInputStream

I don't know Java in any serious sense. (I know that's inconvenient.)

So here's what I want to do. I have a Documentum system and I'd like to query the docbase and retrieve the contents of specific files in order to derive the SHA256 checksum of the file. Most of this I've got working using Jython 2.5.1.

Here's the trouble. When I open a Documentum object's contents, the return value is a ByteArrayInputStream. I need to submit the contents of that stream to an instance of hashlib.sha256 using that object's update() method, which accepts only strings or read-only buffers. The BAIS's read() method returns a single byte at a time and while I can find plenty of Java code to use that method, all of it is utterly unPythonic, and I'm at a loss on how to use it.

Any suggestions for how to get the contents of a BAIS into either a string or a read-only buffer (in the Python, not Java sense).

I should mention that although I've used Python for a while, this is my first go-round with Jython.

This email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit --
Jython-users mailing list