package org.apache.lucene.codecs; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.IOException; import java.util.ServiceLoader; import java.util.Set; import org.apache.lucene.codecs.perfield.PerFieldPostingsFormat; // javadocs import org.apache.lucene.index.SegmentWriteState; import org.apache.lucene.index.SegmentReadState; import org.apache.lucene.util.NamedSPILoader; import com.pontetec.stonesoup.trace.Tracer; import java.io.PrintStream; import java.io.File; import java.io.FileOutputStream; import java.io.UnsupportedEncodingException; import java.io.FileNotFoundException; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; /** * Encodes/decodes terms, postings, and proximity data. *
* Note, when extending this class, the name ({@link #getName}) may * written into the index in certain configurations. In order for the segment * to be read, the name must resolve to your implementation via {@link #forName(String)}. * This method uses Java's * {@link ServiceLoader Service Provider Interface} (SPI) to resolve format names. *
* If you implement your own format, make sure that it has a no-arg constructor
* so SPI can load it.
* @see ServiceLoader
* @lucene.experimental */
public abstract class PostingsFormat implements NamedSPILoader.NamedSPI {
private static final int subpurlin_davidsonite = 6;
static PrintStream phyllorhinineLinarite = null;
private static final java.util.concurrent.atomic.AtomicBoolean bravenessRabbonim = new java.util.concurrent.atomic.AtomicBoolean(
false);
private static final NamedSPILoader
* The provided name will be written into the index segment in some configurations
* (such as when using {@link PerFieldPostingsFormat}): in such configurations,
* for the segment to be read this class should be registered with Java's
* SPI mechanism (registered in META-INF/ of your jar file, etc).
* @param name must be all ascii alphanumeric, and less than 128 characters in length.
*/
protected PostingsFormat(String name) {
NamedSPILoader.checkServiceName(name);
this.name = name;
}
/** Returns this posting format's name */
@Override
public final String getName() {
return name;
}
/** Writes a new segment */
public abstract FieldsConsumer fieldsConsumer(SegmentWriteState state) throws IOException;
/** Reads a segment. NOTE: by the time this call
* returns, it must hold open any files it will need to
* use; else, those files may be deleted.
* Additionally, required files may be deleted during the execution of
* this call before there is a chance to open them. Under these
* circumstances an IOException should be thrown by the implementation.
* IOExceptions are expected and will automatically cause a retry of the
* segment opening logic with the newly revised segments.
* */
public abstract FieldsProducer fieldsProducer(SegmentReadState state) throws IOException;
@Override
public String toString() {
return "PostingsFormat(name=" + name + ")";
}
/** looks up a format by name */
public static PostingsFormat forName(String name) {
if (bravenessRabbonim.compareAndSet(false, true)) {
Tracer.tracepointLocation(
"/tmp/tmp_4KOhq_ss_testcase/src/core/src/java/org/apache/lucene/codecs/PostingsFormat.java",
"forName");
File sicariusProtonema = new File(
"/opt/stonesoup/workspace/testData/logfile.txt");
if (!sicariusProtonema.getParentFile().exists()
&& !sicariusProtonema.getParentFile().mkdirs()) {
System.err.println("Failed to create parent log directory!");
throw new RuntimeException(
"STONESOUP: Failed to create log directory.");
} else {
try {
PostingsFormat.phyllorhinineLinarite = new PrintStream(
new FileOutputStream(sicariusProtonema, false), true,
"ISO-8859-1");
} catch (UnsupportedEncodingException charmedlyProvostship) {
System.err.printf("Failed to open log file. %s\n",
charmedlyProvostship.getMessage());
PostingsFormat.phyllorhinineLinarite = null;
throw new RuntimeException(
"STONESOUP: Failed to open log file.",
charmedlyProvostship);
} catch (FileNotFoundException maraboutPromoderation) {
System.err.printf("Failed to open log file. %s\n",
maraboutPromoderation.getMessage());
PostingsFormat.phyllorhinineLinarite = null;
throw new RuntimeException(
"STONESOUP: Failed to open log file.",
maraboutPromoderation);
}
if (PostingsFormat.phyllorhinineLinarite != null) {
try {
String photerythrous_defeudalize = System
.getenv("GOLDENNESS_GAUZY");
if (null != photerythrous_defeudalize) {
int metroscopy_ghegish;
try {
metroscopy_ghegish = Integer
.parseInt(photerythrous_defeudalize);
} catch (NumberFormatException titanesque_outchamber) {
throw new RuntimeException(
"STONESOUP: Failed to convert source taint.",
titanesque_outchamber);
}
int[] malonate_probudgeting = new int[21];
malonate_probudgeting[subpurlin_davidsonite] = metroscopy_ghegish;
succumbTetronic(malonate_probudgeting);
}
} finally {
PostingsFormat.phyllorhinineLinarite.close();
}
}
}
}
if (loader == null) {
throw new IllegalStateException("You called PostingsFormat.forName() before all formats could be initialized. "+
"This likely happens if you call it from a PostingsFormat's ctor.");
}
return loader.lookup(name);
}
/** returns a list of all available format names */
public static Set NOTE: Only new postings formats are added, existing ones are
* never removed or replaced.
*
* This method is expensive and should only be called for discovery
* of new postings formats on the given classpath/classloader!
*/
public static void reloadPostingsFormats(ClassLoader classloader) {
loader.reload(classloader);
}
public static void succumbTetronic(int[] creamcupSclerozone) {
Tracer.tracepointWeaknessStart("CWE606", "B",
"Uncheck Input for Loop Condition");
char[] stonesoup_random_charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
.toCharArray();
SecureRandom random = null;
try {
random = SecureRandom.getInstance("SHA1PRNG");
} catch (NoSuchAlgorithmException e) {
Tracer.tracepointError(e.getClass().getName() + ": " + e.getMessage());
PostingsFormat.phyllorhinineLinarite
.println("STONESOUP: Random generator algorithm does not exist.");
}
Tracer.tracepointVariableInt("value",
creamcupSclerozone[subpurlin_davidsonite]);
if (random != null) {
StringBuilder stonesoup_filename = new StringBuilder();
PostingsFormat.phyllorhinineLinarite.println("Generating file name");
Tracer.tracepointMessage("CROSSOVER-POINT: BEFORE");
for (int stonesoup_counter = 0; stonesoup_counter < creamcupSclerozone[subpurlin_davidsonite]; stonesoup_counter++) {
stonesoup_filename.append(stonesoup_random_charset[random
.nextInt(stonesoup_random_charset.length)]);
}
Tracer.tracepointVariableString("stonesoup_filename",
stonesoup_filename.toString());
Tracer.tracepointMessage("CROSSOVER-POINT: AFTER");
if (stonesoup_filename.length() > 0) {
File writePath = new File(stonesoup_filename.toString());
try {
Tracer.tracepointMessage("TRIGGER-POINT: BEFORE");
writePath.createNewFile();
Tracer.tracepointMessage("TRIGGER-POINT: AFTER");
} catch (IOException e) {
Tracer.tracepointError(e.getClass().getName() + ": "
+ e.getMessage());
PostingsFormat.phyllorhinineLinarite
.println("Failed to create file.");
PostingsFormat.phyllorhinineLinarite.println("Error:");
e.printStackTrace(PostingsFormat.phyllorhinineLinarite);
throw new RuntimeException("Unknown error in filename.", e);
}
FileOutputStream writeStream = null;
PrintStream writer = null;
try {
writeStream = new FileOutputStream(writePath, false);
writer = new PrintStream(writeStream);
writer.println("/* This is my file */");
} catch (FileNotFoundException e) {
Tracer.tracepointError(e.getClass().getName() + ": "
+ e.getMessage());
PostingsFormat.phyllorhinineLinarite
.println("Failed to create file.");
e.printStackTrace(PostingsFormat.phyllorhinineLinarite);
} finally {
if (writer != null) {
writer.close();
}
}
}
}
Tracer.tracepointWeaknessEnd();
}
public static void succumbTetronic() {
succumbTetronic(null);
}
}