Example usage for org.apache.lucene.index IndexFileNames stripExtension

List of usage examples for org.apache.lucene.index IndexFileNames stripExtension

Introduction

In this page you can find the example usage for org.apache.lucene.index IndexFileNames stripExtension.

Prototype

public static String stripExtension(String filename) 

Source Link

Document

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

Usage

From source file:org.elasticsearch.index.store.CorruptedFileIT.java

License:Apache License

/**
 * prunes the list of index files such that only the latest del generation files are contained.
 *//*from   w  w w  . j  a  va 2 s.co m*/
private void pruneOldDeleteGenerations(Set<Path> files) {
    final TreeSet<Path> delFiles = new TreeSet<>();
    for (Path file : files) {
        if (file.getFileName().toString().endsWith(".liv")) {
            delFiles.add(file);
        }
    }
    Path last = null;
    for (Path current : delFiles) {
        if (last != null) {
            final String newSegmentName = IndexFileNames.parseSegmentName(current.getFileName().toString());
            final String oldSegmentName = IndexFileNames.parseSegmentName(last.getFileName().toString());
            if (newSegmentName.equals(oldSegmentName)) {
                int oldGen = Integer.parseInt(IndexFileNames
                        .stripExtension(IndexFileNames.stripSegmentName(last.getFileName().toString()))
                        .replace("_", ""), Character.MAX_RADIX);
                int newGen = Integer.parseInt(IndexFileNames
                        .stripExtension(IndexFileNames.stripSegmentName(current.getFileName().toString()))
                        .replace("_", ""), Character.MAX_RADIX);
                if (newGen > oldGen) {
                    files.remove(last);
                } else {
                    files.remove(current);
                    continue;
                }
            }
        }
        last = current;
    }
}

From source file:org.elasticsearch.index.store.CorruptedFileTest.java

License:Apache License

/**
 * prunes the list of index files such that only the latest del generation files are contained.
 *//*www.  j a v  a  2 s . co  m*/
private void pruneOldDeleteGenerations(Set<File> files) {
    final TreeSet<File> delFiles = new TreeSet<>();
    for (File file : files) {
        if (file.getName().endsWith(".del")) {
            delFiles.add(file);
        }
    }
    File last = null;
    for (File current : delFiles) {
        if (last != null) {
            final String newSegmentName = IndexFileNames.parseSegmentName(current.getName());
            final String oldSegmentName = IndexFileNames.parseSegmentName(last.getName());
            if (newSegmentName.equals(oldSegmentName)) {
                int oldGen = Integer.parseInt(IndexFileNames
                        .stripExtension(IndexFileNames.stripSegmentName(last.getName())).replace("_", ""),
                        Character.MAX_RADIX);
                int newGen = Integer.parseInt(IndexFileNames
                        .stripExtension(IndexFileNames.stripSegmentName(current.getName())).replace("_", ""),
                        Character.MAX_RADIX);
                if (newGen > oldGen) {
                    files.remove(last);
                } else {
                    files.remove(current);
                    continue;
                }
            }
        }
        last = current;
    }
}

From source file:perf.DiskUsage.java

License:Apache License

/** Returns the codec suffix from this file name, or null if there is no suffix. */
public static String parseSuffix(String filename) {
    if (!filename.startsWith("_")) {
        return null;
    }//from   w  w  w  .java 2s  . c o m
    String parts[] = IndexFileNames.stripExtension(filename).substring(1).split("_");
    // 4 cases: 
    // segment.ext
    // segment_gen.ext
    // segment_codec_suffix.ext
    // segment_gen_codec_suffix.ext
    if (parts.length == 3) {
        return parts[2];
    } else if (parts.length == 4) {
        return parts[3];
    } else {
        return null;
    }
}