| | |
| | | import org.opends.server.util.TimeThread; |
| | | |
| | | import java.io.File; |
| | | import java.io.FilenameFilter; |
| | | |
| | | /** |
| | | * A file name policy that names files suffixed by the time it was created. |
| | |
| | | File file; |
| | | |
| | | /** |
| | | * The FilenameFilter implementation for this naming policy to filter |
| | | * for all the files named by this policy. |
| | | */ |
| | | private class TimeStampNamingFilter implements FilenameFilter |
| | | { |
| | | /** |
| | | * Select only files that are named by this policy. |
| | | * |
| | | * @param dir The directory to search. |
| | | * @param name The filename to which to apply the filter. |
| | | * |
| | | * @return <CODE>true</CODE> if the given filename matches the filter, or |
| | | * <CODE>false</CODE> if it does not. |
| | | */ |
| | | public boolean accept(File dir, String name) |
| | | { |
| | | if(new File(dir, name).isDirectory()) |
| | | { |
| | | return false; |
| | | } |
| | | name = name.toLowerCase(); |
| | | return name.startsWith(file.getName().toLowerCase()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Create a new instance of the TimeStampNaming policy. Files will be created |
| | | * with the names in the prefix.utctime format. |
| | | * |
| | |
| | | { |
| | | this.file = file; |
| | | } |
| | | |
| | | /** |
| | | * Initializes the policy and returns the current name to use. |
| | | * |
| | | * @return the initial file. |
| | | * {@inheritDoc} |
| | | */ |
| | | public File getInitialName() |
| | | { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets the next name to use. |
| | | * |
| | | * @return the next file. |
| | | * {@inheritDoc} |
| | | */ |
| | | public File getNextName() |
| | | { |
| | | return new File(file + "." + TimeThread.getGMTTime()); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public FilenameFilter getFilenameFilter() |
| | | { |
| | | return new TimeStampNamingFilter(); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public File[] listFiles() |
| | | { |
| | | File directory = file.getParentFile(); |
| | | return directory.listFiles(getFilenameFilter()); |
| | | } |
| | | |
| | | } |