Code example for MappedByteBuffer

Methods: getInt, getShort, order

0
   } 
 
   //returns byteoffset of first IFD 
   private long readHeader() throws IOException {            
      MappedByteBuffer buffer = fileChannel_.map(FileChannel.MapMode.READ_ONLY, 0, 8);
      short zeroOne = buffer.getShort();
      if (zeroOne == 0x4949 ) {
         bigEndian_ = false;
      } else if (zeroOne == 0x4d4d ) {
         bigEndian_ = true;
      } else { 
         throw new IOException("Error reading Tiff header");
      } 
      buffer.order( bigEndian_ ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN );  
      short twoThree = buffer.getShort();
      if (twoThree != 42) {
         throw new IOException("Tiff identifier code incorrect");
      } 
      return unsignInt(buffer.getInt());
   } 
    
   private void createFileChannel(File file) throws FileNotFoundException, IOException {      
      raFile_ = new RandomAccessFile(file,"rw");
      fileChannel_ = raFile_.getChannel();