Skip to content

Instantly share code, notes, and snippets.

@billy1380
Created June 30, 2014 13:37
Show Gist options
  • Save billy1380/bc1ea6723ae89973d0b0 to your computer and use it in GitHub Desktop.
Save billy1380/bc1ea6723ae89973d0b0 to your computer and use it in GitHub Desktop.
Read and write .done files to mark long completion process
public static void writeDoneFile(String filePath) throws IOException {
String doneFilePath = filePath + ".done";
FileOutputStream out = null;
try {
out = new FileOutputStream(doneFilePath);
out.write(SimpleDateFormat.getInstance().format(new Date()).getBytes());
} finally {
if (out != null) {
out.close();
}
}
}
public static Date doneAt(String filePath) throws IOException, ParseException {
String doneFilePath = filePath + ".done";
Date date = null;
FileInputStream in = null;
try {
in = new FileInputStream(doneFilePath);
byte[] buffer = new byte[1024];
int read = 0;
if ((read = in.read(buffer)) > 0) {
String content = new String(buffer, 0, read);
date = SimpleDateFormat.getInstance().parse(content);
}
} finally {
if (in != null) {
in.close();
}
}
return date;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment