I'm trying to save ByteBuffers to a file:
FileChannel fc = new FileOutputStream("file.something").getChannel();
while(true) {
ByteBuffer b = nalUnits.poll();
System.out.println("gonna write " + b.capacity());
//printByteBuffer(b);
fc.write(b);
}
System.out.println("gonna close");
fc.close();
System.out.println("did close");
static void printByteBuffer(ByteBuffer b) {
for (int k = 0; k < b.position(); k++) {
System.out.print(b.get(k) + " ");
}
System.out.println();
}
I get this as output:
gonna write 41091
gonna write 41498
gonna write 41299
gonna write 40836
gonna write 40275
gonna write 40708
...
gonna close
did close
but the file has 0kb. If I uncomment "printBuffer", I can see all the buffers printed on screen, they're not empty. Why do I end up with an empty file?