Java Buffer / Stream

From: Mikee29 Mar 2012 12:08
To: ALL1 of 4
Hi,

Trying to port some code over from PHP to Java, but struggling a bit around the buffer part.

php code:
 
fseek($this->fp, 652256);
$elevation = fread($this->fp, 4); // returns 88
 


java code:
 
ByteBuffer buf = ByteBuffer.allocate(4);
fc.read(buf, 652256);
buf.flip();
int elevation = buf.getInt(); // returns 808466488
buf.clear();
 


I'm r confused :(
From: Mikee29 Mar 2012 12:49
To: Mikee 2 of 4
Seems I've sorted it..

java code:
 
        ByteBuffer buf = ByteBuffer.allocate(LEN_DATA);
        fc.read(buf, recordOffset + dataOffset);
        buf.position(0);
        byte[] bytearr = new byte[buf.remaining()];
        buf.get(bytearr);
        String strElevation = new String(bytearr);
        return Integer.parseInt(strElevation);
 


Ugh!
From: Peter (BOUGHTONP)29 Mar 2012 14:19
To: Mikee 3 of 4
Are you forced to use Java language?

'Cus there are JVM languages that'll make that as simple as:
code:
data = readFile(name);
elevation = data[4];
From: Mikee29 Mar 2012 14:24
To: Peter (BOUGHTONP) 4 of 4
Uh. I'm guessing so, yeah