public void forceRewriteExif(String filename,Collection<ExifTag> tags) throws FileNotFoundException, IOException {
  if (!rewriteExif(filename,tags)) {
    ExifData tempData=mData;
    mData=new ExifData(DEFAULT_BYTE_ORDER);
    FileInputStream is=null;
    ByteArrayOutputStream bytes=null;
    try {
      is=new FileInputStream(filename);
      bytes=new ByteArrayOutputStream();
      doExifStreamIO(is,bytes);
      byte[] imageBytes=bytes.toByteArray();
      readExif(imageBytes);
      setTags(tags);
      writeExif(imageBytes,filename);
    }
 catch (    IOException e) {
      closeSilently(is);
      throw e;
    }
 finally {
      is.close();
      mData=tempData;
    }
  }
}

public void forceRewriteExif ( String filename , Collection < ExifTag > tags ) throws FileNotFoundException , IOException { if ( ! rewriteExif ( filename , tags ) ) { ExifData tempData = mData ; mData = new ExifData ( DEFAULT_BYTE_ORDER ) ; FileInputStream is = null ; ByteArrayOutputStream bytes = null ; try { is = new FileInputStream ( filename ) ; bytes = new ByteArrayOutputStream ( ) ; doExifStreamIO ( is , bytes ) ; byte [ ] imageBytes = bytes . toByteArray ( ) ; readExif ( imageBytes ) ; setTags ( tags ) ; writeExif ( imageBytes , filename ) ; } catch ( IOException e ) { closeSilently ( is ) ; throw e ; } finally { is . close ( ) ; mData = tempData ; } } }
attempts to do an in - place rewrite of the exif metadata . if this fails , fall back to overwriting file . this preserves tags that are not being rewritten .
