hadoop-common-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Owen O'Malley" <omal...@apache.org>
Subject Re: Read Little Endian Input File Format
Date Mon, 09 Jul 2012 20:53:27 GMT
On Mon, Jul 9, 2012 at 1:33 PM, Mike S <mikesam460@gmail.com> wrote:

> The input file to my M/R job is a file with binary data (20 mix of
> int, long, float and double per record) which are all saved in little
> endian. I have implement my custom record reader to read a record and
> to do so I am currently using the ByteBuffer to convert every entry in
> the file. I am wondering if there is a more efficient way of doing?
>

I would either make a large ByteBuffer and read into it or use:

// read big endian int
int val = in.readInt();
// flip to little endian
val = ((val & 0xff) << 24) | ((val & 0xff00 << 8) | ((val & 0xff0000)
>> 8)
| (val >>> 24);

-- Owen

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message