question: 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 ) ; } finally { is . close ( ) ; mData = tempData ; } } }
target:  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.