org.apache.lucene.index

## Class IndexFileNames

- java.lang.Object
- - org.apache.lucene.index.IndexFileNames

-     public final class IndexFileNames
      extends Object

  This class contains useful constants representing filenames and extensions used by lucene, as well as convenience methods for querying whether a file name matches an extension (`matchesExtension`), as well as generating file names from a segment name, generation and extension ( `fileNameFromGeneration`, `segmentFileName`).

  NOTE: extensions used by codecs are not listed here. You must interact with the `Codec` directly.

  NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static Pattern` | `CODEC_FILE_PATTERN` All files created by codecs much match this pattern (checked in SegmentInfo).
    `static String` | `OLD_SEGMENTS_GEN` Name of the generation reference file name
    `static String` | `PENDING_SEGMENTS` Name of pending index segment file
    `static String` | `SEGMENTS` Name of the index segment file

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `fileNameFromGeneration(String base, String ext, long gen)` Computes the full file name from base, extension and generation.
    `static String` | `getExtension(String filename)` Return the extension (anything after the first '.'), or null if there is no '.' in the file name.
    `static boolean` | `matchesExtension(String filename, String ext)` Returns true if the given filename ends with the given extension.
    `static long` | `parseGeneration(String filename)` Returns the generation from this file name, or 0 if there is no generation.
    `static String` | `parseSegmentName(String filename)` Parses the segment name out of the given file name.
    `static String` | `segmentFileName(String segmentName, String segmentSuffix, String ext)` Returns a file name that includes the given segment name, your own custom name and extension.
    `static String` | `stripExtension(String filename)` Removes the extension (anything after the first '.'), otherwise returns the original filename.
    `static String` | `stripSegmentName(String filename)` Strips the segment name out of the given file name.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### SEGMENTS

          public static final String SEGMENTS

      Name of the index segment file
      See Also:
        Constant Field Values

    - #### PENDING_SEGMENTS

          public static final String PENDING_SEGMENTS

      Name of pending index segment file
      See Also:
        Constant Field Values

    - #### OLD_SEGMENTS_GEN

          public static final String OLD_SEGMENTS_GEN

      Name of the generation reference file name
      See Also:
        Constant Field Values

    - #### CODEC_FILE_PATTERN

          public static final Pattern CODEC_FILE_PATTERN

      All files created by codecs much match this pattern (checked in SegmentInfo).

  - ### Method Detail

    - #### fileNameFromGeneration

          public static String fileNameFromGeneration(String base,
                                                      String ext,
                                                      long gen)

      Computes the full file name from base, extension and generation. If the generation is -1, the file name is null. If it's 0, the file name is <base>.<ext>. If it's > 0, the file name is <base>_<gen>.<ext>.
      NOTE: .<ext> is added to the name only if `ext` is not an empty string.
      Parameters:
        `base` - main part of the file name
        `ext` - extension of the filename
        `gen` - generation

    - #### segmentFileName

          public static String segmentFileName(String segmentName,
                                               String segmentSuffix,
                                               String ext)

      Returns a file name that includes the given segment name, your own custom name and extension. The format of the filename is: <segmentName>(_<name>)(.<ext>).

      NOTE: .<ext> is added to the result file name only if `ext` is not empty.

      NOTE: _<segmentSuffix> is added to the result file name only if it's not the empty string

      NOTE: all custom files should be named using this method, or otherwise some structures may fail to handle them properly (such as if they are added to compound files).

    - #### matchesExtension

          public static boolean matchesExtension(String filename,
                                                 String ext)

      Returns true if the given filename ends with the given extension. One should provide a pure extension, without '.'.

    - #### stripSegmentName

          public static String stripSegmentName(String filename)

      Strips the segment name out of the given file name. If you used `segmentFileName(java.lang.String, java.lang.String, java.lang.String)` or `fileNameFromGeneration(java.lang.String, java.lang.String, long)` to create your files, then this method simply removes whatever comes before the first '.', or the second '_' (excluding both).
      Returns:
        the filename with the segment name removed, or the given filename if it does not contain a '.' and '_'.

    - #### parseGeneration

          public static long parseGeneration(String filename)

      Returns the generation from this file name, or 0 if there is no generation.

    - #### parseSegmentName

          public static String parseSegmentName(String filename)

      Parses the segment name out of the given file name.
      Returns:
        the segment name only, or filename if it does not contain a '.' and '_'.

    - #### stripExtension

          public static String stripExtension(String filename)

      Removes the extension (anything after the first '.'), otherwise returns the original filename.

    - #### getExtension

          public static String getExtension(String filename)

      Return the extension (anything after the first '.'), or null if there is no '.' in the file name.

Copyright © 2000-2020 Apache Software Foundation. All Rights Reserved.