CodingJava Buffer / Stream

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  Mikee  
 To:  ALL
39451.1 
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 :(
0/0
 Reply   Quote More 

 From:  Mikee  
 To:  Mikee     
39451.2 In reply to 39451.1 
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!
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Mikee     
39451.3 In reply to 39451.1 
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];
0/0
 Reply   Quote More 

 From:  Mikee  
 To:  Peter (BOUGHTONP)     
39451.4 In reply to 39451.3 
Uh. I'm guessing so, yeah
0/0
 Reply   Quote More 

Reply to All    
 

1–4

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats