Bug fixed: skipping n bytes can skip less then n, try twice
This commit is contained in:
parent
8d50d73da6
commit
373f86ec82
|
@ -113,7 +113,7 @@ public class HexInputStream extends FilterInputStream {
|
|||
if (binSize > 0 && newULBA != (lastBaseAddress >> 16) + 1)
|
||||
return binSize;
|
||||
lastBaseAddress = newULBA << 16;
|
||||
in.skip(2 /* check sum */);
|
||||
skip(in, 2 /* check sum */);
|
||||
break;
|
||||
}
|
||||
case 0x02: {
|
||||
|
@ -122,7 +122,7 @@ public class HexInputStream extends FilterInputStream {
|
|||
if (binSize > 0 && (newSBA >> 16) != (lastBaseAddress >> 16) + 1)
|
||||
return binSize;
|
||||
lastBaseAddress = newSBA;
|
||||
in.skip(2 /* check sum */);
|
||||
skip(in, 2 /* check sum */);
|
||||
break;
|
||||
}
|
||||
case 0x00:
|
||||
|
@ -132,7 +132,8 @@ public class HexInputStream extends FilterInputStream {
|
|||
binSize += lineSize;
|
||||
// no break!
|
||||
default:
|
||||
in.skip(lineSize * 2 /* 2 hex per one byte */+ 2 /* check sum */);
|
||||
final long toBeSkipped = lineSize * 2 /* 2 hex per one byte */+ 2 /* check sum */;
|
||||
skip(in, toBeSkipped);
|
||||
break;
|
||||
}
|
||||
// skip end of line
|
||||
|
@ -265,7 +266,7 @@ public class HexInputStream extends FilterInputStream {
|
|||
// data type
|
||||
if (lastAddress + offset < MBRSize) { // skip MBR
|
||||
type = -1; // some other than 0
|
||||
pos += in.skip(lineSize * 2 /* 2 hex per one byte */+ 2 /* check sum */);
|
||||
pos += skip(in, lineSize * 2 /* 2 hex per one byte */+ 2 /* check sum */);
|
||||
}
|
||||
break;
|
||||
case 0x01:
|
||||
|
@ -279,7 +280,7 @@ public class HexInputStream extends FilterInputStream {
|
|||
if (bytesRead > 0 && (address >> 16) != (lastAddress >> 16) + 1)
|
||||
return 0;
|
||||
lastAddress = address;
|
||||
pos += in.skip(2 /* check sum */);
|
||||
pos += skip(in, 2 /* check sum */);
|
||||
break;
|
||||
}
|
||||
case 0x04: {
|
||||
|
@ -289,11 +290,12 @@ public class HexInputStream extends FilterInputStream {
|
|||
if (bytesRead > 0 && address != (lastAddress >> 16) + 1)
|
||||
return 0;
|
||||
lastAddress = address << 16;
|
||||
pos += in.skip(2 /* check sum */);
|
||||
pos += skip(in, 2 /* check sum */);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
pos += in.skip(lineSize * 2 /* 2 hex per one byte */+ 2 /* check sum */);
|
||||
final long toBeSkipped = lineSize * 2 /* 2 hex per one byte */+ 2 /* check sum */;
|
||||
pos += skip(in, toBeSkipped);
|
||||
break;
|
||||
}
|
||||
} while (type != 0);
|
||||
|
@ -304,7 +306,7 @@ public class HexInputStream extends FilterInputStream {
|
|||
pos += 2;
|
||||
localBuf[i] = (byte) b;
|
||||
}
|
||||
pos += in.skip(2); // skip the checksum
|
||||
pos += skip(in, 2); // skip the checksum
|
||||
localPos = 0;
|
||||
|
||||
return lineSize;
|
||||
|
@ -324,6 +326,14 @@ public class HexInputStream extends FilterInputStream {
|
|||
throw new HexFileValidationException("Not a HEX file");
|
||||
}
|
||||
|
||||
private long skip(final InputStream in, final long offset) throws IOException {
|
||||
long skipped = in.skip(offset);
|
||||
// try to skip 2 times as skip(..) method does not guarantee to skip exactly given number of bytes
|
||||
if (skipped < offset)
|
||||
skipped += in.skip(offset - skipped);
|
||||
return skipped;
|
||||
}
|
||||
|
||||
private int readByte(final InputStream in) throws IOException {
|
||||
final int first = asciiToInt(in.read());
|
||||
final int second = asciiToInt(in.read());
|
||||
|
|
Loading…
Reference in New Issue