Skip to content

Instantly share code, notes, and snippets.

@vandershraaf
Created June 6, 2013 19:39
Show Gist options
  • Save vandershraaf/5724297 to your computer and use it in GitHub Desktop.
Save vandershraaf/5724297 to your computer and use it in GitHub Desktop.
Pattern.matcher doesnt throw NullPointerException
public long serializeTimestamp(String timeConfigFile, String key){
FileReader reader = null;
BufferedReader r = null;
FileWriter fw = null;
try {
reader = new FileReader(new File(timeConfigFile));
r = new BufferedReader(reader);
String line = r.readLine();
Pattern pattern = Pattern.compile("^"+key+"(\\d*)$");
Matcher matcher = pattern.matcher(line);
matcher.find();
long lastRun = Long.parseLong(matcher.group(1));
log.debug(lastRun);
long now = System.currentTimeMillis();
fw = new FileWriter(new File(timeConfigFile));
System.out.println("fw: "+fw);
fw.write(key+String.valueOf(now));
return lastRun;
} catch (FileNotFoundException e) {
e.printStackTrace();
//log.error("timeConfigFile file cannot be found", e);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
reader.close();
r.close();
log.debug("get called before it returns!!!");
log.debug("fw: "+fw);
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment