Code example for MappedByteBuffer

Methods: getChargetIntorder

0
      return new JSONObject(sBuffer.toString());
   } 
 
   private IFDEntry readDirectoryEntry(long byteOffset) throws IOException {
      MappedByteBuffer ifd = makeReadOnlyBuffer( byteOffset, 12);
      char tag =  ifd.getChar(); 
      char type = ifd.getChar();
      long count = unsignInt(ifd.getInt());
      long value = unsignInt(ifd.getInt());
       
      return (new IFDEntry(tag,type,count,value));
   } 
 
   //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();
//      lock_ = fileChannel_.lock(); 
   } 
    
   private void close() throws IOException { 
      lock_.release();
      lock_ = null;    
      fileChannel_.close();
      raFile_.close();
      fileChannel_ = null;
      raFile_ = null;
   } 
    
   private MappedByteBuffer makeReadOnlyBuffer(long byteOffset, long numBytes) throws IOException {
       return makeBuffer(FileChannel.MapMode.READ_ONLY, byteOffset, numBytes);
   } 
    
   private MappedByteBuffer makeBuffer(FileChannel.MapMode mode, long byteOffset, long numBytes) throws IOException {
      MappedByteBuffer buffer = fileChannel_.map(mode, byteOffset, numBytes);
      buffer.order(bigEndian_ ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
      return buffer;
   } 
 
   private long unsignInt(int i) {
      long val = Integer.MAX_VALUE & i;
Contextual code suggestions in your IDE  Get Codota for Java