I have a situation when I need to read only part of file, beginning from specified byte position.
I try with next :
protected void writePartToStream(final InputStream in, final OutputStream out, long startBytes) {
final byte[] b = new byte[BUFFER_SIZE];
int count = 0;
amountWritten = startBytes;
// skip logic
// how to skip???
do {
// write to the output stream
try {
out.write(b, 0, count);
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
amountWritten += count;
System.out.println("Amount writtent=" + amountWritten);
// read more bytes from the input stream
try {
count = in.read(b, (int) amountWritten, b.length);
} catch (IOException e) {
}
} while (count != -1 && !getStatus().equals(Status.cancelled));
// the connection was likely terminated abrubtly if these are not equal
if (!getStatus().equals(Status.cancelled) && getError() == Error.none
&& amountWritten != fileSize) {
setStatus(Status.error);
this.error = Error.connection;
}
}
But I never working with I/O, so I don't have any idea how to start read file, from specified position.
read(byte[] b, int off, int len)where you can specify start position.