private int readLine() throws IOException {
  if (pos == -1)   return 0;
  final InputStream in=this.in;
  int b;
  int lineSize, type, offset;
  do {
    while (true) {
      b=in.read();
      pos++;
      if (b != '\n' && b != '\r') {
        break;
      }
    }
    checkComma(b);
    lineSize=readByte(in);
    pos+=2;
    offset=readAddress(in);
    pos+=4;
    type=readByte(in);
    pos+=2;
switch (type) {
case 0x00:
      if (lastAddress + offset < MBRSize) {
        type=-1;
        pos+=skip(in,lineSize * 2 + 2);
      }
    break;
case 0x01:
  pos=-1;
return 0;
case 0x02:
{
final int address=readAddress(in) << 4;
pos+=4;
if (bytesRead > 0 && (address >> 16) != (lastAddress >> 16) + 1) return 0;
lastAddress=address;
pos+=skip(in,2);
break;
}
case 0x04:
{
final int address=readAddress(in);
pos+=4;
if (bytesRead > 0 && address != (lastAddress >> 16) + 1) return 0;
lastAddress=address << 16;
pos+=skip(in,2);
break;
}
default :
final long toBeSkipped=lineSize * 2 + 2;
pos+=skip(in,toBeSkipped);
break;
}
}
 while (type != 0);
for (int i=0; i < localBuf.length && i < lineSize; ++i) {
b=readByte(in);
pos+=2;
localBuf[i]=(byte)b;
}
pos+=skip(in,2);
localPos=0;
return lineSize;
}

private int readLine ( ) throws IOException { if ( pos == - 1 ) return 0 ; final InputStream in = this . in ; int b ; int lineSize , type , offset ; do { while ( true ) { b = in . read ( ) ; pos ++ ; if ( b != '\n' && b != '\r' ) { break ; } } checkComma ( b ) ; lineSize = readByte ( in ) ; pos += 2 ; offset = readAddress ( in ) ; pos += 4 ; type = readByte ( in ) ; pos += 2 ; switch ( type ) { case 0x00 : if ( lastAddress + offset < MBRSize ) { type = - 1 ; pos += skip ( in , lineSize * 2 + 2 ) ; } break ; case 0x01 : pos = - 1 ; return 0 ; case 0x02 : { final int address = readAddress ( in ) << 4 ; pos += 4 ; if ( bytesRead > 0 && ( address > > 16 ) != ( lastAddress > > 16 ) + 1 ) return 0 ; lastAddress = address ; pos += skip ( in , 2 ) ; break ; } case 0x04 : { final int address = readAddress ( in ) ; pos += 4 ; if ( bytesRead > 0 && address != ( lastAddress > > 16 ) + 1 ) return 0 ; lastAddress = address << 16 ; pos += skip ( in , 2 ) ; break ; } default : final long toBeSkipped = lineSize * 2 + 2 ; pos += skip ( in , toBeSkipped ) ; break ; } } while ( type != 0 ) ; for ( int i = 0 ; i < localBuf . length && i < lineSize ; ++ i ) { b = readByte ( in ) ; pos += 2 ; localBuf [ i ] = ( byte ) b ; } pos += skip ( in , 2 ) ; localPos = 0 ; return lineSize ; }
reads new line from the input stream . input stream must be a hex file . the first line is always skipped .
