Skip to content
Snippets Groups Projects
Commit 4126e3d7 authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

LocalReader solution

parent 959e4385
No related merge requests found
......@@ -55,7 +55,48 @@ public class IndexReader {
return LocalFile;
}
private byte[] getData(FileChannel fc, int index) throws IOException {
return new byte[0];
private byte[] getData(FileChannel fc, int i) throws IOException {
// 0...3 - number of images
// 4 ... 7 - Position of 1. image data in file
// 8 ... 11 - Lenght of 1. image
// position_in_index = 4 + i*8
// position_of_image = readInt(position_in_index)
// size_of_image = readInt(position_in_index + 4)
// data = readData(position_of_image, size_of_image)
// return data
// go to position ... fc.position(position)
// read data .... fc.read(bb) - bb is ByteBuffer
// create ByteBuffer 8 bytes long
ByteBuffer bb = ByteBuffer.allocate(8);
fc.position(0);
fc.read(bb);
bb.flip();
int numberOfImages = bb.getInt();
if (i < 0 || numberOfImages <= i) {
return new byte[0];
}
bb.clear();
fc.position(4 + i * 8);
fc.read(bb);
bb.flip();
int position = bb.getInt();
int size = bb.getInt();
bb = ByteBuffer.allocate(size);
fc.position(position);
fc.read(bb);
bb.flip();
return bb.array();
// read data .... fc.read(bb) - bb is ByteBuffer
// bb.flip()
// bb.getInt(), bb.getInt()
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment