Reading Java byte[] data stream over standard input

Giles Brown giles_brown at hotmail.com
Mon May 19 07:07:15 EDT 2008


On 19 May, 06:11, sapsi <saptarshi.g... at gmail.com> wrote:
> Hello,
> I am using HadoopStreaming using a BinaryInputStream. What this
> basically does is send a stream of bytes (  the java type is : private
> byte[] bytes) to my python program.
>
> I have done a test like this,
> while 1:
>         x=sys.stdin.read(100)
>         if x:
>                 print x
>         else:
>                 break
>
> Now, the incoming data is binary(though mine is actually merely ascii
> text) but the output is not what is expected. I expect for e.g
>
> all/86000/114.310.151.209.60370-121.110.5.176.113\n62485.9718
> 118.010.241.12 60370 128.210.5.176
>
> However i get a 1 before all and a 4 just after \n and before the 6.
>
> My question is : how do i read binary data(Java's byte stream) from
> stdin?
> Or is this actually what i'm getting?
>
> Thanks
> Sapsi

In the past I've sent binary data to a java applet reading
DataInputStream using xdrlib from the standard library.  I'd expect
that it would work in the reverse direction so I suggest you have a
look at that.

Giles



More information about the Python-list mailing list