So i'm trying to implement a method that inserts a byteArray into a file, and set a new byteArray containing the byteArray that was inserted if that makes any sense. The following is my code however I'm pretty sure something's wrong since my tests are failing any help would be appreciated.
public void writeBlock(int blockNum, AbstractDBFile f, AbstractBlock b)
throws IOException {
f.setCurBlockPos(blockNum);
byte[] writeData = new byte[4096];
int currentByte = f.getCurBlockPos() * 4096;
File ourFile = new File(f.getFileName());
// Block block = new Block();
Path path = Paths.get(f.getFileName());
Files.write(path, writeData, StandardOpenOption.WRITE); //Data is Written
RandomAccessFile file = new RandomAccessFile(ourFile, "rw");
FileChannel inChannel = file.getChannel();
ByteBuffer bb = ByteBuffer.allocate(currentByte);
inChannel.write(bb);
while(inChannel.read(bb)>0){
bb.flip();
for (int i =0; i<bb.limit(); i++){
writeData[i]=bb.get();
b.setData(writeData);
}
bb.clear();
}
inChannel.close();
file.close();
}