Java Code Examples for com.intellij.util.ThrowableConsumer#consume()

The following examples show how to use com.intellij.util.ThrowableConsumer#consume() . 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 File: Unity3dLocalFileSystemComponent.java    From consulo-unity3d with Apache License 2.0 6 votes vote down vote up
public static boolean doActionOnSuffixFile(VirtualFile parentFile, ThrowableConsumer<VirtualFile, IOException> consumer, String suffix)
{
	VirtualFile parent = parentFile.getParent();
	if(parent == null)
	{
		return false;
	}
	VirtualFile metaFile = parent.findChild(parentFile.getName() + suffix);
	if(metaFile != null)
	{
		try
		{
			consumer.consume(metaFile);
		}
		catch(IOException e)
		{
			LOGGER.error(e);
		}
	}
	return false;
}
 
Example 2
Source File: VcsLogData.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void runInBackground(@Nonnull ThrowableConsumer<ProgressIndicator, VcsException> task) {
  Task.Backgroundable backgroundable = new Task.Backgroundable(myProject, "Loading History...", false) {
    @Override
    public void run(@Nonnull ProgressIndicator indicator) {
      indicator.setIndeterminate(true);
      try {
        task.consume(indicator);
      }
      catch (VcsException e) {
        throw new RuntimeException(e); // TODO
      }
    }
  };
  myDataLoaderQueue.run(backgroundable, null, myRefresher.getProgress().createProgressIndicator());
}
 
Example 3
Source File: DataInputOutputUtilRt.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Writes the given collection to the output using the given procedure to write each element.
 * Should be coupled with {@link #readSeq}
 */
public static <T> void writeSeq(@Nonnull DataOutput out, @Nonnull Collection<? extends T> collection, @SuppressWarnings("BoundedWildcard") @Nonnull ThrowableConsumer<T, IOException> writeElement)
        throws IOException {
  writeINT(out, collection.size());
  for (T t : collection) {
    writeElement.consume(t);
  }
}
 
Example 4
Source File: DataInputOutputUtilRt.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Writes the given map to the output using the given procedure to write each key and value.
 * Should be coupled with {@link #readMap}
 */
public static <K, V> void writeMap(@Nonnull DataOutput out,
                                   @Nonnull Map<? extends K, ? extends V> map,
                                   @Nonnull ThrowableConsumer<K, ? extends IOException> writeKey,
                                   @Nonnull ThrowableConsumer<V, ? extends IOException> writeValue) throws IOException {
  writeINT(out, map.size());
  for (Map.Entry<? extends K, ? extends V> e : map.entrySet()) {
    writeKey.consume(e.getKey());
    writeValue.consume(e.getValue());
  }
}
 
Example 5
Source File: VcsFileUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Execute function for each chunk of arguments. Check for being cancelled in process.
 *
 * @param arguments the arguments to chunk
 * @param groupSize size of argument groups that should be put in the same chunk (like a name and a value)
 * @param consumer  consumer to feed each chunk
 * @throws VcsException
 */
public static void foreachChunk(@Nonnull List<String> arguments,
                                int groupSize,
                                @Nonnull ThrowableConsumer<List<String>, VcsException> consumer)
        throws VcsException {
  List<List<String>> chunks = chunkArguments(arguments, groupSize);

  for (List<String> chunk : chunks) {
    ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    if (indicator != null) indicator.checkCanceled();

    consumer.consume(chunk);
  }
}
 
Example 6
Source File: DataInputOutputUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * Writes the given (possibly null) element to the output using the given procedure to write the element if it's not null.
 * Should be coupled with {@link #readNullable}
 */
public static <T> void writeNullable(@Nonnull DataOutput out, @Nullable T value, @Nonnull ThrowableConsumer<T, IOException> writeValue) throws IOException {
  out.writeBoolean(value != null);
  if (value != null) writeValue.consume(value);
}