private boolean readHeader ( ) { boolean correct = true ; ByteOrder byteOrder = ByteOrder . LITTLE_ENDIAN ; int c1 = 0 ; int c2 = 0 ; try { c1 = data . readByte ( ) . toInt ( ) ; c2 = data . readByte ( ) . toInt ( ) ; } catch ( Exception ex ) { validation . addErrorLoc ( "Header IO Exception" , "Header" ) ; } // read the first two bytes, in order to know the byte ordering if ( c1 == ' ' && c2 == ' ' ) { byteOrder = ByteOrder . LITTLE_ENDIAN ; } else if ( c1 == ' ' && c2 == ' ' ) { byteOrder = ByteOrder . BIG_ENDIAN ; } else if ( byteOrderErrorTolerance > 0 && c1 == ' ' && c2 == ' ' ) { validation . addWarning ( "Byte Order in lower case" , "" + c1 + c2 , "Header" ) ; byteOrder = ByteOrder . LITTLE_ENDIAN ; } else if ( byteOrderErrorTolerance > 0 && c1 == ' ' && c2 == ' ' ) { validation . addWarning ( "Byte Order in lower case" , "" + c1 + c2 , "Header" ) ; byteOrder = ByteOrder . BIG_ENDIAN ; } else if ( byteOrderErrorTolerance > 1 ) { validation . addWarning ( "Non-sense Byte Order. Trying Little Endian." , "" + c1 + c2 , "Header" ) ; byteOrder = ByteOrder . LITTLE_ENDIAN ; } else { validation . addErrorLoc ( "Invalid Byte Order " + c1 + c2 , "Header" ) ; correct = false ; } if ( correct ) { tiffModel . setByteOrder ( byteOrder ) ; data . setByteOrder ( byteOrder ) ; try { // read magic number int magic = data . readShort ( ) . toInt ( ) ; tiffModel . setMagicNumber ( magic ) ; } catch ( Exception ex ) { validation . addErrorLoc ( "Magic number parsing error" , "Header" ) ; correct = false ; } } return correct ; }
Reads the Tiff header .