ExportFileExpirationRule implements ExpirationRule { public boolean hasExpired(final File tempFile) { final Matcher matcher = FILE_NAME_PATTERN.matcher(tempFile.getName()); matcher.find(); try { final String dateInMillis = matcher.group(2); final Date fileDate = new SimpleDateFormat(DATE_FORMAT_PATTERN).parse(dateInMillis); return System.currentTimeMillis() - fileDate.getTime() > temporaryFileExpireTimeMs; } catch (final ParseException pe) { logger.warn("Unable to parse date part of filename: " + tempFile.getName(), pe); return false; } } ExportFileExpirationRule(final long temporaryFileExpireTimeMs); boolean hasExpired(final File tempFile);  }
@Test public void testHasExpiredNumbersInFileName() throws Exception { final ExportFileExpirationRule rule = new ExportFileExpirationRule(1000); assertTrue(rule.hasExpired(new File("123-20000318025831111.zip"))); assertTrue(rule.hasExpired(new File("20000318025831111-20000318025831111.zip"))); }
@Test public void testHasExpired() throws Exception { final ExportFileExpirationRule rule = new ExportFileExpirationRule(1000); assertTrue(rule.hasExpired(new File("defaultsvn-20000318025831111.zip"))); }