I've got a binary format file, that I want to turn into Java objects and then finally output that into CSV format.
I've started going down a route, that although I know will work, seems incorrect.
Can someone please either tell me this is the way to do this, or suggest alternatives.
Sample code below:
public class Baf5014Converter
{
//private recordSize
public Baf5014 convertBytesToObject(byte[] bafRecordInBytes) {
Baf5014 record = new Baf5014();
record.setSize(getRecordSize(bafRecordInBytes));
return record;
}
private int getRecordSize(byte[] bafRecordInBytes)
{
byte[] recordSizeInBytes = Arrays.copyOfRange(bafRecordInBytes,0,2);
return ByteBuffer.wrap(recordSizeInBytes).getShort();
}
}
The idea would be to create a number of different getFoo functions as I go through the file. What I don't particularly like already is the magic numbers 0,2 in the above, even if the function name I guess makes it obvious enough what it's doing.
Googling hasn't helped so far, but it might be that I don't know the right words to search for :)
Any help would be greatly appreciated,
Cheers
Alan