Created
June 6, 2013 19:39
-
-
Save vandershraaf/5724297 to your computer and use it in GitHub Desktop.
Pattern.matcher doesnt throw NullPointerException
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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