1 package au.gov.amsa.util.nmea.saver; 2 3 import java.io.File; 4 5 import org.joda.time.format.DateTimeFormat; 6 import org.joda.time.format.DateTimeFormatter; 7 8 public class FileFactoryPerDay implements FileFactory { 9 10 private static DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd") 11 .withZoneUTC(); 12 13 private File directory; 14 15 public FileFactoryPerDay(File directory) { 16 this.directory = directory; 17 directory.mkdirs(); 18 } 19 20 @Override 21 public File file(String line, long arrivalTime) { 22 return new File(directory, date(arrivalTime) + ".txt"); 23 } 24 25 @Override 26 public String key(String line, long arrivalTime) { 27 return date(arrivalTime); 28 } 29 30 private String date(long arrivalTime) { 31 return dtf.print(arrivalTime); 32 } 33 }