1 17 package org.apache.log.output.io.rotate; 18 19 import java.io.File ; 20 import java.text.SimpleDateFormat ; 21 import java.util.Date ; 22 23 38 public class UniqueFileStrategy 39 implements FileStrategy 40 { 41 private File m_baseFile; 42 43 private SimpleDateFormat m_formatter; 44 45 private String m_suffix; 46 47 51 public UniqueFileStrategy( final File baseFile ) 52 { 53 m_baseFile = baseFile; 54 } 55 56 61 public UniqueFileStrategy( final File baseFile, String pattern ) 62 { 63 this( baseFile ); 64 m_formatter = new SimpleDateFormat ( pattern ); 65 } 66 67 73 public UniqueFileStrategy( final File baseFile, String pattern, String suffix ) 74 { 75 this( baseFile, pattern ); 76 m_suffix = suffix; 77 } 78 79 84 public File nextFile() 85 { 86 final StringBuffer sb = new StringBuffer (); 87 sb.append( m_baseFile ); 88 if( m_formatter == null ) 89 { 90 sb.append( System.currentTimeMillis() ); 91 } 92 else 93 { 94 final String dateString = m_formatter.format( new Date () ); 95 sb.append( dateString ); 96 } 97 98 if( m_suffix != null ) 99 { 100 sb.append( m_suffix ); 101 } 102 103 return new File ( sb.toString() ); 104 } 105 } 106 107 | Popular Tags |