Re: converting java byte[] to Jython str/unicode

Jeff Emanuel <[email protected]> Thu, 07 Apr 2016 08:58:33 -0600
Newsgroups gmane.comp.lang.jython.user
Message-ID <[email protected]>
Since I use Jython primarily to script my Java application, I tend to use Java API's and would do it this way:

from java.nio.charset import Charset
from java.lang import String
s = str(String(aByteArray,Charset.forName('UTF-8')))

but I would omit the str() part and just keep the Java String and let Jython convert if and when it needs to.

s = String(aByteArray,Charset.forName('UTF-8'))



On 4/7/2016 2:36 AM, Master Of The wrote:
> Hi,
>
> I am having java byte[] available to me from JDBC driver which Id
> like to convert to Jython str/unicode types (with specified charset when
> converting to unicode eg. utf8).
>
> Whats the best way to do this?
>
> ... unless of course its as simple as:
>
> s_str = str(rs.getString(...))
> s_unicode = str(rs.getString(...)).decode('utf8')
>
> Regards


------------------------------------------------------------------------------