Currently my code works fine but should I replace raf.read()
to raf.readFully()
in order to ensure that all bytes will be read?
raf = new RandomAccessFile(doc.getFilePath()+"/"+doc.getName(),"r");
raf.seek((partNumber-1)*partitionSize);
byte[] buf = new byte[partitionSize];
int bytesRead = raf.read(buf); //ensure myself by readFully or not?
System.out.println("expected="+partitionSize+" readed="+bytesRead);
My suggestion is the following - when reading from local resource like file one read()
call anyway will return specified number of bytes. readFully
useful when reading from network stream, when read()
does not guarantee that needed bytes count will be read. Is it correct?