Java Code Examples for org.apache.lucene.util.SuppressForbidden

The following examples show how to use org.apache.lucene.util.SuppressForbidden. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: lucene-solr   Source File: HttpClientBase.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressForbidden(reason = "XXX: security hole")
protected void throwKnownError(HttpResponse response, StatusLine statusLine) throws IOException {
  ObjectInputStream in = null;
  try {
    in = new ObjectInputStream(response.getEntity().getContent());
  } catch (Throwable t) {
    // the response stream is not an exception - could be an error in servlet.init().
    throw new RuntimeException("Unknown error: " + statusLine, t);
  }
  
  Throwable t;
  try {
    t = (Throwable) in.readObject();
    assert t != null;
  } catch (Throwable th) { 
    throw new RuntimeException("Failed to read exception object: " + statusLine, th);
  } finally {
    in.close();
  }
  throw IOUtils.rethrowAlways(t);
}
 
Example 2
Source Project: lucene-solr   Source File: PrintTaxonomyStats.java    License: Apache License 2.0 6 votes vote down vote up
/** Command-line tool. */
@SuppressForbidden(reason = "System.out required: command line tool")
public static void main(String[] args) throws IOException {
  boolean printTree = false;
  String path = null;
  for(int i=0;i<args.length;i++) {
    if (args[i].equals("-printTree")) {
      printTree = true;
    } else {
      path = args[i];
    }
  }
  if (args.length != (printTree ? 2 : 1)) {
    System.out.println("\nUsage: java -classpath ... org.apache.lucene.facet.util.PrintTaxonomyStats [-printTree] /path/to/taxononmy/index\n");
    System.exit(1);
  }
  Directory dir = FSDirectory.open(Paths.get(path));
  TaxonomyReader r = new DirectoryTaxonomyReader(dir);
  printStats(r, System.out, printTree);
  r.close();
  dir.close();
}
 
Example 3
Source Project: lucene-solr   Source File: MMapDirectory.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressForbidden(reason = "Needs access to private APIs in DirectBuffer, sun.misc.Cleaner, and sun.misc.Unsafe to enable hack")
private static Object unmapHackImpl() {
  final Lookup lookup = lookup();
  try {
    // *** sun.misc.Unsafe unmapping (Java 9+) ***
    final Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
    // first check if Unsafe has the right method, otherwise we can give up
    // without doing any security critical stuff:
    final MethodHandle unmapper = lookup.findVirtual(unsafeClass, "invokeCleaner",
        methodType(void.class, ByteBuffer.class));
    // fetch the unsafe instance and bind it to the virtual MH:
    final Field f = unsafeClass.getDeclaredField("theUnsafe");
    f.setAccessible(true);
    final Object theUnsafe = f.get(null);
    return newBufferCleaner(ByteBuffer.class, unmapper.bindTo(theUnsafe));
  } catch (SecurityException se) {
    return "Unmapping is not supported, because not all required permissions are given to the Lucene JAR file: " + se +
        " [Please grant at least the following permissions: RuntimePermission(\"accessClassInPackage.sun.misc\") " +
        " and ReflectPermission(\"suppressAccessChecks\")]";
  } catch (ReflectiveOperationException | RuntimeException e) {
    return "Unmapping is not supported on this platform, because internal Java APIs are not compatible with this Lucene version: " + e; 
  }
}
 
Example 4
Source Project: lucene-solr   Source File: TestCharArraySet.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressForbidden(reason = "Explicitly checking new Integers")
public void testObjectContains() {
  CharArraySet set = new CharArraySet(10, true);
  Integer val = Integer.valueOf(1);
  @SuppressWarnings("deprecation")
  Integer val1 = new Integer(1);
  // Verify explicitly the case of different Integer instances
  assertNotSame(val, val1);
  set.add(val);
  assertTrue(set.contains(val));
  assertTrue(set.contains(val1)); // another integer
  assertTrue(set.contains("1"));
  assertTrue(set.contains(new char[]{'1'}));
  // test unmodifiable
  set = CharArraySet.unmodifiableSet(set);
  assertTrue(set.contains(val));
  assertTrue(set.contains(val1)); // another integer
  assertTrue(set.contains("1"));
  assertTrue(set.contains(new char[]{'1'}));
}
 
Example 5
Source Project: lucene-solr   Source File: AnalyticsShardResponseParser.java    License: Apache License 2.0 6 votes vote down vote up
@Override
@SuppressForbidden(reason = "XXX: security hole")
public NamedList<Object> processResponse(InputStream body, String encoding) {
  DataInputStream input = new DataInputStream(body);
  //check to see if the response is an exception
  NamedList<Object> exception = new NamedList<>();
  try {
    if (input.readBoolean()) {
      manager.importShardData(input);
    } else {
      exception.add("Exception", new ObjectInputStream(input).readObject());
    }
  } catch (IOException e) {
    exception.add("Exception", new SolrException(ErrorCode.SERVER_ERROR, "Couldn't process analytics shard response", e));
  } catch (ClassNotFoundException e1) {
    throw new RuntimeException(e1);
  }
  return exception;
}
 
Example 6
@SuppressForbidden(reason = "nio file porting will be done later")
private static void expandRulesInUTR30DataFiles(String dir) throws IOException {
    FileFilter filter = pathname -> {
        String name = pathname.getName();
        return pathname.isFile() && name.matches(".*\\.(?s:txt)")
                && !name.equals(NFC_TXT) && !name.equals(NFKC_TXT) && !name.equals(NFKC_CF_TXT);
    };
    if (dir != null) {
        File dirFile = new File(dir);
        File[] files = dirFile.listFiles(filter);
        if (files != null) {
            for (File file : files) {
                expandDataFileRules(file);
            }
        }
    }
}
 
Example 7
@SuppressForbidden(reason = "we save CPT to file in a format using serialization, yes")
public void save(OutputStream out) throws IOException {
    try (ObjectOutputStream oos2 = new ObjectOutputStream(out)) {
        if (this.stringtree == null) {
            this.stringtree = getStringTree(this.root);
        }
        oos2.writeObject("Pretree");
        oos2.writeObject("Stringformat char[]");
        oos2.writeObject("version=1.3");
        oos2.writeObject(this.startchar);
        oos2.writeObject(this.endchar);
        oos2.writeObject((int) this.attentionNumber);
        oos2.writeObject((int) this.attentionNode);
        oos2.writeObject((int) this.endOfWordChar);
        oos2.writeObject(this.reverse);
        oos2.writeObject(this.ignorecase);
        oos2.writeObject(this.stringtree);
    }
}
 
Example 8
@SuppressForbidden(reason = "accessing local resources from classpath")
public void testVerifyDE() throws IOException {
    Dictionary dictionary = new Dictionary();
    InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream("de-lemma-utf8.txt"),
            StandardCharsets.UTF_8);
    dictionary.loadLines(reader);
    reader.close();
    BufferedReader br = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("de-lemma-utf8.txt"),
            StandardCharsets.UTF_8));
    String line;
    while ((line = br.readLine()) != null) {
        if (!line.startsWith("#")) {
            if (!check(line, dictionary)) {
                break;
            }
        }
    }
    br.close();
}
 
Example 9
Source Project: Elasticsearch   Source File: Loggers.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "using localhost for logging on which host it is is fine")
private static InetAddress getHostAddress() {
    try {
        return InetAddress.getLocalHost();
    } catch (UnknownHostException e) {
        return null;
    }
}
 
Example 10
Source Project: lucene-solr   Source File: CreateIndexDialogFactory.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "JFilechooser#getSelectedFile() returns java.io.File")
private void browseDirectory(JTextField tf) {
  JFileChooser fc = new JFileChooser(new File(tf.getText()));
  fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  fc.setFileHidingEnabled(false);
  int retVal = fc.showOpenDialog(dialog);
  if (retVal == JFileChooser.APPROVE_OPTION) {
    File dir = fc.getSelectedFile();
    tf.setText(dir.getAbsolutePath());
  }
}
 
Example 11
Source Project: lucene-solr   Source File: ExportTermsDialogFactory.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "JFilechooser#getSelectedFile() returns java.io.File")
void browseDirectory(ActionEvent e) {
  JFileChooser fileChooser = new JFileChooser();
  fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  fileChooser.setFileHidingEnabled(false);
  int retVal = fileChooser.showOpenDialog(dialog);
  if (retVal == JFileChooser.APPROVE_OPTION) {
    File f = fileChooser.getSelectedFile();
    destDir.setText(f.getAbsolutePath());
  }
}
 
Example 12
Source Project: lucene-solr   Source File: OpenIndexDialogFactory.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "FileChooser#getSelectedFile() returns java.io.File")
void browseDirectory(ActionEvent e) {
  File currentDir = getLastOpenedDirectory();
  JFileChooser fc = currentDir == null ? new JFileChooser() : new JFileChooser(currentDir);
  fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  fc.setFileHidingEnabled(false);
  int retVal = fc.showOpenDialog(dialog);
  if (retVal == JFileChooser.APPROVE_OPTION) {
    File dir = fc.getSelectedFile();
    idxPathCombo.insertItemAt(dir.getAbsolutePath(), 0);
    idxPathCombo.setSelectedIndex(0);
  }
}
 
Example 13
Source Project: lucene-solr   Source File: OpenIndexDialogFactory.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "JFileChooser constructor takes java.io.File")
private File getLastOpenedDirectory() {
  List<String> history = prefs.getHistory();
  if (!history.isEmpty()) {
    Path path = Paths.get(history.get(0));
    if (Files.exists(path)) {
      return path.getParent().toAbsolutePath().toFile();
    }
  }
  return null;
}
 
Example 14
Source Project: lucene-solr   Source File: CustomAnalyzerPanelProvider.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "JFilechooser#getSelectedFile() returns java.io.File")
private void chooseConfigDir() {
  fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

  int ret = fileChooser.showOpenDialog(containerPanel);
  if (ret == JFileChooser.APPROVE_OPTION) {
    File dir = fileChooser.getSelectedFile();
    confDirTF.setText(dir.getAbsolutePath());
  }
}
 
Example 15
Source Project: lucene-solr   Source File: CustomAnalyzerPanelProvider.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "JFilechooser#getSelectedFiles() returns java.io.File[]")
private void loadExternalJars() {
  fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
  fileChooser.setMultiSelectionEnabled(true);

  int ret = fileChooser.showOpenDialog(containerPanel);
  if (ret == JFileChooser.APPROVE_OPTION) {
    File[] files = fileChooser.getSelectedFiles();
    analysisModel.addExternalJars(Arrays.stream(files).map(File::getAbsolutePath).collect(Collectors.toList()));
    operatorRegistry.get(CustomAnalyzerPanelOperator.class).ifPresent(operator ->
        operator.resetAnalysisComponents()
    );
    messageBroker.showStatusMessage("External jars were added.");
  }
}
 
Example 16
Source Project: lucene-solr   Source File: HighFreqTerms.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "System.out required: command line tool")
public static void main(String[] args) throws Exception {
  String field = null;
  int numTerms = DEFAULT_NUMTERMS;
 
  if (args.length == 0 || args.length > 4) {
    usage();
    System.exit(1);
  }     

  Directory dir = FSDirectory.open(Paths.get(args[0]));
  
  Comparator<TermStats> comparator = new DocFreqComparator();
 
  for (int i = 1; i < args.length; i++) {
    if (args[i].equals("-t")) {
      comparator = new TotalTermFreqComparator();
    }
    else{
      try {
        numTerms = Integer.parseInt(args[i]);
      } catch (NumberFormatException e) {
        field=args[i];
      }
    }
  }
  
  IndexReader reader = DirectoryReader.open(dir);
  TermStats[] terms = getHighFreqTerms(reader, numTerms, field, comparator);

  for (int i = 0; i < terms.length; i++) {
    System.out.printf(Locale.ROOT, "%s:%s \t totalTF = %,d \t docFreq = %,d \n",
          terms[i].field, terms[i].termtext.utf8ToString(), terms[i].totalTermFreq, terms[i].docFreq);
  }
  reader.close();
}
 
Example 17
Source Project: lucene-solr   Source File: IndexSplitter.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "System.out required: command line tool")
public void listSegments() throws IOException {
  DecimalFormat formatter = new DecimalFormat("###,###.###", DecimalFormatSymbols.getInstance(Locale.ROOT));
  for (int x = 0; x < infos.size(); x++) {
    SegmentCommitInfo info = infos.info(x);
    String sizeStr = formatter.format(info.sizeInBytes());
    System.out.println(info.info.name + " " + sizeStr);
  }
}
 
Example 18
Source Project: lucene-solr   Source File: BigramDictionary.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "TODO: fix code to serialize its own dictionary vs. a binary blob in the codebase")
private void loadFromInputStream(InputStream serialObjectInputStream)
    throws IOException, ClassNotFoundException {
  try (ObjectInputStream input = new ObjectInputStream(serialObjectInputStream)) {
    bigramHashTable = (long[]) input.readObject();
    frequencyTable = (int[]) input.readObject();
    // log.info("load bigram dict from serialization.");
  }
}
 
Example 19
Source Project: lucene-solr   Source File: BigramDictionary.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "TODO: fix code to serialize its own dictionary vs. a binary blob in the codebase")
private void saveToObj(Path serialObj) throws IOException {
  try (ObjectOutputStream output = new ObjectOutputStream(Files.newOutputStream(
      serialObj))) {
    output.writeObject(bigramHashTable);
    output.writeObject(frequencyTable);
    // log.info("serialize bigram dict.");
  }
}
 
Example 20
Source Project: lucene-solr   Source File: WordDictionary.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "TODO: fix code to serialize its own dictionary vs. a binary blob in the codebase")
private void loadFromObjectInputStream(InputStream serialObjectInputStream)
    throws IOException, ClassNotFoundException {
  try (ObjectInputStream input = new ObjectInputStream(serialObjectInputStream)) {
    wordIndexTable = (short[]) input.readObject();
    charIndexTable = (char[]) input.readObject();
    wordItem_charArrayTable = (char[][][]) input.readObject();
    wordItem_frequencyTable = (int[][]) input.readObject();
    // log.info("load core dict from serialization.");
  }
}
 
Example 21
Source Project: lucene-solr   Source File: WordDictionary.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "TODO: fix code to serialize its own dictionary vs. a binary blob in the codebase")
private void saveToObj(Path serialObj) {
  try (ObjectOutputStream output = new ObjectOutputStream(Files.newOutputStream(serialObj))) {
    output.writeObject(wordIndexTable);
    output.writeObject(charIndexTable);
    output.writeObject(wordItem_charArrayTable);
    output.writeObject(wordItem_frequencyTable);
    // log.info("serialize core dict.");
  } catch (Exception e) {
    // log.warn(e.getMessage());
  }
}
 
Example 22
Source Project: lucene-solr   Source File: DiffIt.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Entry point to the DiffIt application.
 * <p>
 * This application takes one argument, the path to a file containing a
 * stemmer table. The program reads the file and generates the patch commands
 * for the stems.
 * 
 * @param args the path to a file containing a stemmer table
 */
@SuppressForbidden(reason = "System.out required: command line tool")
public static void main(java.lang.String[] args) throws Exception {
  
  int ins = get(0, args[0]);
  int del = get(1, args[0]);
  int rep = get(2, args[0]);
  int nop = get(3, args[0]);
  
  for (int i = 1; i < args.length; i++) {
    // System.out.println("[" + args[i] + "]");
    Diff diff = new Diff(ins, del, rep, nop);
    String charset = System.getProperty("egothor.stemmer.charset", "UTF-8");
    try (LineNumberReader in = new LineNumberReader(Files.newBufferedReader(Paths.get(args[i]), Charset.forName(charset)))) {
      for (String line = in.readLine(); line != null; line = in.readLine()) {
        try {
          line = line.toLowerCase(Locale.ROOT);
          StringTokenizer st = new StringTokenizer(line);
          String stem = st.nextToken();
          System.out.println(stem + " -a");
          while (st.hasMoreTokens()) {
            String token = st.nextToken();
            if (token.equals(stem) == false) {
              System.out.println(stem + " " + diff.exec(token, stem));
            }
          }
        } catch (java.util.NoSuchElementException x) {
          // no base token (stem) on a line
        }
      }
    }
  }
}
 
Example 23
Source Project: lucene-solr   Source File: CheckIndex.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "System.out required: command line tool")
private static int doMain(String args[]) throws IOException, InterruptedException {
  Options opts;
  try {
    opts = parseOptions(args);
  } catch (IllegalArgumentException e) {
    System.out.println(e.getMessage());
    return 1;
  }

  if (!assertsOn())
    System.out.println("\nNOTE: testing will be more thorough if you run java with '-ea:org.apache.lucene...', so assertions are enabled");

  System.out.println("\nOpening index @ " + opts.indexPath + "\n");
  Directory directory = null;
  Path path = Paths.get(opts.indexPath);
  try {
    if (opts.dirImpl == null) {
      directory = FSDirectory.open(path);
    } else {
      directory = CommandLineUtil.newFSDirectory(opts.dirImpl, path);
    }
  } catch (Throwable t) {
    System.out.println("ERROR: could not open directory \"" + opts.indexPath + "\"; exiting");
    t.printStackTrace(System.out);
    return 1;
  }

  try (Directory dir = directory;
       CheckIndex checker = new CheckIndex(dir)) {
    opts.out = System.out;
    return checker.doCheck(opts);
  }
}
 
Example 24
Source Project: lucene-solr   Source File: IndexUpgrader.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "System.out required: command line tool")
private static void printUsage() {
  System.err.println("Upgrades an index so all segments created with a previous Lucene version are rewritten.");
  System.err.println("Usage:");
  System.err.println("  java " + IndexUpgrader.class.getName() + " [-delete-prior-commits] [-verbose] [-dir-impl X] indexDir");
  System.err.println("This tool keeps only the last commit in an index; for this");
  System.err.println("reason, if the incoming index has more than one commit, the tool");
  System.err.println("refuses to run by default. Specify -delete-prior-commits to override");
  System.err.println("this, allowing the tool to delete all but the last commit.");
  System.err.println("Specify a " + FSDirectory.class.getSimpleName() + 
      " implementation through the -dir-impl option to force its use. If no package is specified the " 
      + FSDirectory.class.getPackage().getName() + " package will be used.");
  System.err.println("WARNING: This tool may reorder document IDs!");
  System.exit(1);
}
 
Example 25
Source Project: lucene-solr   Source File: IndexUpgrader.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "System.out required: command line tool")
static IndexUpgrader parseArgs(String[] args) throws IOException {
  String path = null;
  boolean deletePriorCommits = false;
  InfoStream out = null;
  String dirImpl = null;
  int i = 0;
  while (i<args.length) {
    String arg = args[i];
    if ("-delete-prior-commits".equals(arg)) {
      deletePriorCommits = true;
    } else if ("-verbose".equals(arg)) {
      out = new PrintStreamInfoStream(System.out);
    } else if ("-dir-impl".equals(arg)) {
      if (i == args.length - 1) {
        System.out.println("ERROR: missing value for -dir-impl option");
        System.exit(1);
      }
      i++;
      dirImpl = args[i];
    } else if (path == null) {
      path = arg;
    } else {
      printUsage();
    }
    i++;
  }
  if (path == null) {
    printUsage();
  }
  
  Path p = Paths.get(path);
  Directory dir = null;
  if (dirImpl == null) {
    dir = FSDirectory.open(p);
  } else {
    dir = CommandLineUtil.newFSDirectory(dirImpl, p);
  }
  return new IndexUpgrader(dir, out, deletePriorCommits);
}
 
Example 26
Source Project: lucene-solr   Source File: TestIndexWriterOnJRECrash.java    License: Apache License 2.0 5 votes vote down vote up
/** fork ourselves in a new jvm. sets -Dtests.crashmode=true */
@SuppressForbidden(reason = "ProcessBuilder requires java.io.File for CWD")
public void forkTest() throws Exception {
  List<String> cmd = new ArrayList<>();
  cmd.add(Paths.get(System.getProperty("java.home"), "bin", "java").toString());
  cmd.add("-Xmx512m");
  cmd.add("-Dtests.crashmode=true");
  // passing NIGHTLY to this test makes it run for much longer, easier to catch it in the act...
  cmd.add("-Dtests.nightly=true");
  cmd.add("-DtempDir=" + tempDir);
  cmd.add("-Dtests.seed=" + SeedUtils.formatSeed(random().nextLong()));
  cmd.add("-ea");
  cmd.add("-cp");
  cmd.add(System.getProperty("java.class.path"));
  cmd.add("org.junit.runner.JUnitCore");
  cmd.add(getClass().getName());
  ProcessBuilder pb = new ProcessBuilder(cmd)
    .directory(tempDir.toFile())
    .redirectInput(Redirect.INHERIT)
    .redirectErrorStream(true);
  Process p = pb.start();

  // We pump everything to stderr.
  PrintStream childOut = System.err; 
  Thread stdoutPumper = ThreadPumper.start(p.getInputStream(), childOut);
  if (VERBOSE) childOut.println(">>> Begin subprocess output");
  p.waitFor();
  stdoutPumper.join();
  if (VERBOSE) childOut.println("<<< End subprocess output");
}
 
Example 27
Source Project: lucene-solr   Source File: AnalyticsShardResponseWriter.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "XXX: security hole")
public void write(DataOutputStream output) throws IOException {
  output.writeBoolean(requestSuccessful);
  if (requestSuccessful) {
    manager.exportShardData(output);
  } else {
    new ObjectOutputStream(output).writeObject(exception);
  }
}
 
Example 28
Source Project: lucene-solr   Source File: IndexSizeEstimator.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "System.err and System.out required for a command-line utility")
public static void main(String[] args) throws Exception {
  if (args.length == 0) {
    System.err.println("Usage: " + IndexSizeEstimator.class.getName() + " [-topN NUM] [-maxLen NUM] [-summary] [-details] <indexDir>");
    System.err.println();
    System.err.println("\t<indexDir>\tpath to the index (parent path of 'segments_N' file)");
    System.err.println("\t-topN NUM\tnumber of top largest items to collect");
    System.err.println("\t-maxLen NUM\ttruncate the largest items to NUM bytes / characters");
    System.err.println(-1);
  }
  String path = null;
  int topN = 20;
  int maxLen = 100;
  boolean details = false;
  boolean summary = false;
  for (int i = 0; i < args.length; i++) {
    if (args[i].equals("-topN")) {
      topN = Integer.parseInt(args[++i]);
    } else if (args[i].equals("-maxLen")) {
      maxLen = Integer.parseInt(args[++i]);
    } else if (args[i].equals("-details")) {
      details = true;
    } else if (args[i].equals("-summary")) {
      summary = true;
    } else {
      path = args[i];
    }
  }
  if (path == null) {
    System.err.println("ERROR: <indexDir> argument is required.");
    System.exit(-2);
  }
  Directory dir = FSDirectory.open(Paths.get(path));
  DirectoryReader reader = StandardDirectoryReader.open(dir);
  IndexSizeEstimator stats = new IndexSizeEstimator(reader, topN, maxLen, summary, details);
  System.out.println(Utils.toJSONString(stats.estimate()));
  System.exit(0);
}
 
Example 29
Source Project: lucene-solr   Source File: PackageUtils.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressForbidden(reason = "Need to use System.out.println() instead of log4j/slf4j for cleaner output")
public static void print(String color, Object message) {
  String RESET = "\u001B[0m";

  if (color != null) {
    System.out.println(color + String.valueOf(message) + RESET);
  } else {
    System.out.println(message);
  }
}
 
Example 30
@SuppressForbidden(reason = "fetching resources from ICU repository is trusted")
private static void download(URL url, String outputFile) throws IOException {
    final URLConnection connection = openConnection(url);
    int numBytes;
    try (InputStream inputStream = connection.getInputStream();
         OutputStream outputStream = new FileOutputStream(outputFile)) {
        while (-1 != (numBytes = inputStream.read(bytes))) {
            outputStream.write(bytes, 0, numBytes);
        }
    }
}