/src/org/ooc/backend/CachedFileWriter.java
Java | 34 lines | 25 code | 9 blank | 0 comment | 3 complexity | 9d29fda6e067f598c1427180ecda1719 MD5 | raw file
1package org.ooc.backend; 2 3import java.io.File; 4import java.io.IOException; 5import java.io.StringWriter; 6 7import org.ooc.utils.FileUtils; 8 9public class CachedFileWriter extends StringWriter { 10 11 private File file; 12 13 public CachedFileWriter(File file) { 14 super(); 15 this.file = file; 16 } 17 18 @Override 19 public void close() throws IOException { 20 String thisContent = toString(); 21 22 if(!file.exists()) { 23 FileUtils.write(file, thisContent); 24 } else { 25 String fileContent = FileUtils.read(file); 26 if(!fileContent.equals(thisContent)) { 27 FileUtils.write(file, thisContent); 28 } 29 } 30 31 super.close(); 32 } 33 34}