org.apache.lucene.util.IOUtils.rethrowAlways()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中org.apache.lucene.util.IOUtils.rethrowAlways()方法的一些代码示例,展示了IOUtils.rethrowAlways()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.rethrowAlways()方法的具体详情如下:
包路径:org.apache.lucene.util.IOUtils
类名称:IOUtils
方法名:rethrowAlways

IOUtils.rethrowAlways介绍

[英]This utility method takes a previously caught (non-null) Throwable and rethrows either the original argument if it was a subclass of the IOException or an RuntimeException with the cause set to the argument.

This method never returns any value, even though it declares a return value of type Error. The return value declaration is very useful to let the compiler know that the code path following the invocation of this method is unreachable. So in most cases the invocation of this method will be guarded by an if and used together with a throw statement, as in:

if (t != null) throw IOUtils.rethrowAlways(t)

[中]此实用程序方法接受以前捕获的(非null)可丢弃的参数,如果原始参数是IOException的子类,则重新引用该参数,或者是原因设置为该参数的RuntimeException。
此方法从不返回任何值,即使它声明了Error类型的返回值。返回值声明对于让编译器知道调用此方法后的代码路径不可访问非常有用。因此,在大多数情况下,此方法的调用将由if保护,并与throw语句一起使用,如中所示:

if (t != null) throw IOUtils.rethrowAlways(t)

代码示例

代码示例来源:origin: org.apache.lucene/lucene-core

/**
 * Rethrows the argument as {@code IOException} or {@code RuntimeException} 
 * if it's not null.
 * 
 * @deprecated This method is deprecated in favor of {@link #rethrowAlways}. Code should
 * be updated to {@link #rethrowAlways} and guarded with an additional null-argument check
 * (because {@link #rethrowAlways} is not accepting null arguments). 
 */
@Deprecated
public static void reThrow(Throwable th) throws IOException {
 if (th != null) {
  throw rethrowAlways(th);
 }
}

代码示例来源:origin: org.apache.lucene/lucene-core

private Partition getPartition(Future<Partition> future) throws IOException {
 try {
  return future.get();
 } catch (InterruptedException ie) {
  throw new ThreadInterruptedException(ie);
 } catch (ExecutionException ee) {
  // Theoretically cause can be null; guard against that.
  Throwable cause = ee.getCause();
  throw IOUtils.rethrowAlways(cause != null ? cause : ee);
 }
}

代码示例来源:origin: org.apache.lucene/lucene-core

/**
 * Closes all given <tt>Closeable</tt>s.
 * @see #close(Closeable...)
 */
public static void close(Iterable<? extends Closeable> objects) throws IOException {
 Throwable th = null;
 for (Closeable object : objects) {
  try {
   if (object != null) {
    object.close();
   }
  } catch (Throwable t) {
   th = useOrSuppress(th, t);
  }
 }
 if (th != null) {
  throw rethrowAlways(th);
 }
}

代码示例来源:origin: org.apache.lucene/lucene-core

/**
 * Deletes all given <tt>Path</tt>s, if they exist.  Some of the
 * <tt>File</tt>s may be null; they are
 * ignored.  After everything is deleted, the method either
 * throws the first exception it hit while deleting, or
 * completes normally if there were no exceptions.
 * 
 * @param files files to delete
 */
public static void deleteFilesIfExist(Collection<? extends Path> files) throws IOException {
 Throwable th = null;
 for (Path file : files) {
  try {
   if (file != null) {
    Files.deleteIfExists(file);
   }
  } catch (Throwable t) {
   th = useOrSuppress(th, t);
  }
 }
 if (th != null) {
  throw rethrowAlways(th);
 }
}

代码示例来源:origin: org.apache.lucene/lucene-core

/** Remove all our references to readers, and commits
 *  any pending changes. */
synchronized void dropAll() throws IOException {
 Throwable priorE = null;
 final Iterator<Map.Entry<SegmentCommitInfo,ReadersAndUpdates>> it = readerMap.entrySet().iterator();
 while(it.hasNext()) {
  final ReadersAndUpdates rld = it.next().getValue();
  // Important to remove as-we-go, not with .clear()
  // in the end, in case we hit an exception;
  // otherwise we could over-decref if close() is
  // called again:
  it.remove();
  // NOTE: it is allowed that these decRefs do not
  // actually close the SRs; this happens when a
  // near real-time reader is kept open after the
  // IndexWriter instance is closed:
  try {
   rld.dropReaders();
  } catch (Throwable t) {
   priorE = IOUtils.useOrSuppress(priorE, t);
  }
 }
 assert readerMap.size() == 0;
 if (priorE != null) {
  throw IOUtils.rethrowAlways(priorE);
 }
}

代码示例来源:origin: org.apache.lucene/lucene-core

/** Called on exception, to check whether the checksum is also corrupt in this source, and add that
 *  information (checksum matched or didn't) as a suppressed exception. */
private Error verifyChecksum(Throwable priorException, PointWriter writer) throws IOException {
 assert priorException != null;
 // TODO: we could improve this, to always validate checksum as we recurse, if we shared left and
 // right reader after recursing to children, and possibly within recursed children,
 // since all together they make a single pass through the file.  But this is a sizable re-org,
 // and would mean leaving readers (IndexInputs) open for longer:
 if (writer instanceof OfflinePointWriter) {
  // We are reading from a temp file; go verify the checksum:
  String tempFileName = ((OfflinePointWriter) writer).name;
  try (ChecksumIndexInput in = tempDir.openChecksumInput(tempFileName, IOContext.READONCE)) {
   CodecUtil.checkFooter(in, priorException);
  }
 }
 
 // We are reading from heap; nothing to add:
 throw IOUtils.rethrowAlways(priorException);
}

代码示例来源:origin: org.apache.lucene/lucene-core

private static void checkSoftDeletes(String softDeletesField, SegmentCommitInfo info, SegmentReader reader, PrintStream infoStream, boolean failFast) throws IOException {
 if (infoStream != null)
  infoStream.print("    test: check soft deletes.....");
 try {
  int softDeletes = PendingSoftDeletes.countSoftDeletes(DocValuesFieldExistsQuery.getDocValuesDocIdSetIterator(softDeletesField, reader), reader.getLiveDocs());
  if (softDeletes != info.getSoftDelCount()) {
   throw new RuntimeException("actual soft deletes: " + softDeletes + " but expected: " +info.getSoftDelCount());
  }
 } catch (Exception e) {
  if (failFast) {
   throw IOUtils.rethrowAlways(e);
  }
  msg(infoStream, "ERROR [" + String.valueOf(e.getMessage()) + "]");
  if (infoStream != null) {
   e.printStackTrace(infoStream);
  }
 }
}

代码示例来源:origin: org.apache.lucene/lucene-core

/**
 * Deletes all given file names.  Some of the
 * file names may be null; they are
 * ignored.  After everything is deleted, the method either
 * throws the first exception it hit while deleting, or
 * completes normally if there were no exceptions.
 * 
 * @param dir Directory to delete files from
 * @param names file names to delete
 */
public static void deleteFiles(Directory dir, Collection<String> names) throws IOException {
 Throwable th = null;
 for (String name : names) {
  if (name != null) {
   try {
    dir.deleteFile(name);
   } catch (Throwable t) {
    th = useOrSuppress(th, t);
   }
  }
 }
 if (th != null) {
  throw rethrowAlways(th);
 }
}

代码示例来源:origin: org.apache.lucene/lucene-core

throw IOUtils.rethrowAlways(firstThrowable);

代码示例来源:origin: org.apache.lucene/lucene-core

} catch (Throwable e) {
 if (failFast) {
  throw IOUtils.rethrowAlways(e);

代码示例来源:origin: org.apache.lucene/lucene-core

/** Decrefs all provided files, even on exception; throws first exception hit, if any. */
void decRef(Collection<String> files) throws IOException {
 assert locked();
 Set<String> toDelete = new HashSet<>();
 Throwable firstThrowable = null;
 for(final String file : files) {
  try {
   if (decRef(file)) {
    toDelete.add(file);
   }
  } catch (Throwable t) {
   firstThrowable = IOUtils.useOrSuppress(firstThrowable, t);
  }
 }
 try {
  deleteFiles(toDelete);
 } catch (Throwable t) {
  firstThrowable = IOUtils.useOrSuppress(firstThrowable, t);
 }
 if (firstThrowable != null) {
  throw IOUtils.rethrowAlways(firstThrowable);
 }
}

代码示例来源:origin: org.apache.lucene/lucene-core

} catch (Throwable e) {
 if (failFast) {
  throw IOUtils.rethrowAlways(e);

代码示例来源:origin: org.apache.lucene/lucene-core

} catch (Throwable e) {
 if (failFast) {
  throw IOUtils.rethrowAlways(e);

代码示例来源:origin: org.apache.lucene/lucene-core

throw IOUtils.rethrowAlways(e);

代码示例来源:origin: org.apache.lucene/lucene-core

} catch (Throwable e) {
 if (failFast) {
  throw IOUtils.rethrowAlways(e);

代码示例来源:origin: org.apache.lucene/lucene-core

} catch (Throwable e) {
 if (failFast) {
  throw IOUtils.rethrowAlways(e);

代码示例来源:origin: org.apache.lucene/lucene-core

throw IOUtils.rethrowAlways(priorException);

代码示例来源:origin: org.apache.lucene/lucene-core

final private void handleMergeException(Throwable t, MergePolicy.OneMerge merge) throws IOException {
 if (infoStream.isEnabled("IW")) {
  infoStream.message("IW", "handleMergeException: merge=" + segString(merge.segments) + " exc=" + t);
 }
 // Set the exception on the merge, so if
 // forceMerge is waiting on us it sees the root
 // cause exception:
 merge.setException(t);
 addMergeException(merge);
 if (t instanceof MergePolicy.MergeAbortedException) {
  // We can ignore this exception (it happens when
  // deleteAll or rollback is called), unless the
  // merge involves segments from external directories,
  // in which case we must throw it so, for example, the
  // rollbackTransaction code in addIndexes* is
  // executed.
  if (merge.isExternal) { // TODO can we simplify this and just throw all the time? this would simplify this a lot
   throw (MergePolicy.MergeAbortedException) t;
  }
 } else {
  assert t != null;
  throw IOUtils.rethrowAlways(t);
 }
}

代码示例来源:origin: org.apache.lucene/lucene-core

/**
 * Test the term index.
 * @lucene.experimental
 */
public static Status.TermIndexStatus testPostings(CodecReader reader, PrintStream infoStream, boolean verbose, boolean failFast, Version version) throws IOException {
 // TODO: we should go and verify term vectors match, if
 // crossCheckTermVectors is on...
 Status.TermIndexStatus status;
 final int maxDoc = reader.maxDoc();
 try {
  if (infoStream != null) {
   infoStream.print("    test: terms, freq, prox...");
  }
  final Fields fields = reader.getPostingsReader().getMergeInstance();
  final FieldInfos fieldInfos = reader.getFieldInfos();
  status = checkFields(fields, reader.getLiveDocs(), maxDoc, fieldInfos, true, false, infoStream, verbose, version);
 } catch (Throwable e) {
  if (failFast) {
   throw IOUtils.rethrowAlways(e);
  }
  msg(infoStream, "ERROR: " + e);
  status = new Status.TermIndexStatus();
  status.error = e;
  if (infoStream != null) {
   e.printStackTrace(infoStream);
  }
 }
 return status;
}

代码示例来源:origin: org.apache.lucene/lucene-core

throw IOUtils.rethrowAlways(e);

相关文章