Class SequenceFilenameGenerator

java.lang.Object
net.sf.basedb.util.bfs.SequenceFilenameGenerator
All Implemented Interfaces:
FilenameGenerator<Object>

public class SequenceFilenameGenerator
extends Object
implements FilenameGenerator<Object>
File name generator implementation that generates file names using a simple numerical counter. It is possible to give a prexix and/or suffix. For example, with prefix="file-" and suffix=".txt", the following file sequence is generated: file-1.txt, file-2.txt, file-3.txt This generator completely ignores the owner and suggested file names.
Version:
2.15
Author:
Nicklas
Last modified
$Date: 2010-01-12 14:21:49 +0100 (ti, 12 jan 2010) $
  • Field Details

    • prefix

      private String prefix
    • suffix

      private String suffix
    • nextFileNum

      private int nextFileNum
  • Constructor Details

    • SequenceFilenameGenerator

      public SequenceFilenameGenerator()
      Create a new sequence file name generator. No prefix or suffix are used and the sequence starts at 1.
    • SequenceFilenameGenerator

      public SequenceFilenameGenerator​(String prefix, String suffix, int firstFileNum)
      Create a new sequence file name generator.
      Parameters:
      prefix - The prefix to use
      suffix - The suffix to use
      firstFileNum - The sequence number of the first file
  • Method Details

    • getNextFilename

      public String getNextFilename​(Object owner, String suggestedFilename)
      Description copied from interface: FilenameGenerator
      Get the next file name. This method should never return the same file name more than one time (given a single implementor instance). The generator implementation should not concern itself with the underlying file system or if the file already exists or not (this is a task for the DataWriterFactory implementation).
      Specified by:
      getNextFilename in interface FilenameGenerator<Object>
      Parameters:
      owner - The owner of the data in the file
      suggestedFilename - A default suggested file name (can be null)
      Returns:
      A unique file name
    • getPrefix

      public String getPrefix()
      Get the prefix that is used for file name generation.
      Returns:
      The prefix or null if no prefix was given
    • setPrefix

      public void setPrefix​(String prefix)
      Set the prefix that is used for file name generation.
      Parameters:
      prefix - The prefix or null to not use a prefix
    • getSuffix

      public String getSuffix()
      Get the suffix that is used for file name generation.
      Returns:
      The suffix or null if no suffix was given
    • setSuffix

      public void setSuffix​(String suffix)
      Set the suffix that is used for file name generation.
      Parameters:
      suffix - The suffix or null to not use a suffix
    • getNextFileNumber

      public int getNextFileNumber()
      Get the next file number. This counter is increased for each file that is generated (eg. each time getNextFilename(Object, String) is called.