Java Code Examples for com.google.api.client.util.Throwables#propagate()

The following examples show how to use com.google.api.client.util.Throwables#propagate() . 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: BeamFnMapTaskExecutorFactory.java    From beam with Apache License 2.0 6 votes vote down vote up
/** Returns a map from PTransform id to side input reader. */
private static ImmutableMap<String, SideInputReader> buildPTransformIdToSideInputReadersMap(
    DataflowExecutionContext executionContext,
    RegisterRequestNode registerRequestNode,
    ImmutableMap<String, DataflowOperationContext> ptransformIdToOperationContexts) {

  ImmutableMap.Builder<String, SideInputReader> ptransformIdToSideInputReaders =
      ImmutableMap.builder();
  for (Map.Entry<String, Iterable<PCollectionView<?>>> ptransformIdToPCollectionView :
      registerRequestNode.getPTransformIdToPCollectionViewMap().entrySet()) {
    try {
      ptransformIdToSideInputReaders.put(
          ptransformIdToPCollectionView.getKey(),
          executionContext.getSideInputReader(
              // Note that the side input infos will only be populated for a batch pipeline
              registerRequestNode
                  .getPTransformIdToSideInputInfoMap()
                  .get(ptransformIdToPCollectionView.getKey()),
              ptransformIdToPCollectionView.getValue(),
              ptransformIdToOperationContexts.get(ptransformIdToPCollectionView.getKey())));
    } catch (Exception e) {
      throw Throwables.propagate(e);
    }
  }
  return ptransformIdToSideInputReaders.build();
}
 
Example 2
Source File: BeamFnMapTaskExecutorFactory.java    From beam with Apache License 2.0 6 votes vote down vote up
/** Returns a map from PTransform id to side input reader. */
private static ImmutableMap<String, SideInputReader> buildPTransformIdToSideInputReadersMap(
    DataflowExecutionContext executionContext,
    ExecutableStageNode registerRequestNode,
    ImmutableMap<String, DataflowOperationContext> ptransformIdToOperationContexts) {

  ImmutableMap.Builder<String, SideInputReader> ptransformIdToSideInputReaders =
      ImmutableMap.builder();
  for (Map.Entry<String, Iterable<PCollectionView<?>>> ptransformIdToPCollectionView :
      registerRequestNode.getPTransformIdToPCollectionViewMap().entrySet()) {
    try {
      ptransformIdToSideInputReaders.put(
          ptransformIdToPCollectionView.getKey(),
          executionContext.getSideInputReader(
              // Note that the side input infos will only be populated for a batch pipeline
              registerRequestNode
                  .getPTransformIdToSideInputInfoMap()
                  .get(ptransformIdToPCollectionView.getKey()),
              ptransformIdToPCollectionView.getValue(),
              ptransformIdToOperationContexts.get(ptransformIdToPCollectionView.getKey())));
    } catch (Exception e) {
      throw Throwables.propagate(e);
    }
  }
  return ptransformIdToSideInputReaders.build();
}
 
Example 3
Source File: MethodParserMap.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private Record(Object target, Method method) {
    this.target = target;
    this.method = method;

    final TypeToken<?> returnType;
    if(Optional.class.isAssignableFrom(method.getReturnType())) {
        optional = true;
        returnType = Optionals.elementType(method.getGenericReturnType());
    } else {
        optional = false;
        returnType = TypeToken.of(method.getGenericReturnType());
    }

    if(!type.isAssignableFrom(returnType)) {
        throw new IllegalStateException("Method " + method + " return type " + returnType + " is not assignable to " + type);
    }

    if(method.getParameterTypes().length == 0) {
        passElement = false;
    } else  {
        if(!(method.getParameterTypes().length == 1 && Element.class.isAssignableFrom(method.getParameterTypes()[0]))) {
            throw new IllegalStateException("Method " + method + " should take no parameters, or a single Element parameter");
        }
        passElement = true;
    }

    try {
        this.handle = MethodHandleUtils.privateLookup(method.getDeclaringClass())
                                       .unreflect(method)
                                       .bindTo(target);
    } catch(IllegalAccessException e) {
        throw Throwables.propagate(e);
    }
}
 
Example 4
Source File: LocalizedFileManager.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public Set<Locale> availableLocalesFresh() {
    try(final Stream<Path> dir = FileUtils.directoryStream(rootPath)) {
        return dir.map(path -> Locale.forLanguageTag(path.getFileName().toString()))
                  .collect(Collectors.toImmutableSet());
    } catch(IOException e) {
        throw Throwables.propagate(e);
    }
}
 
Example 5
Source File: GenericJson.java    From google-http-java-client with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
  if (jsonFactory != null) {
    try {
      return jsonFactory.toString(this);
    } catch (IOException e) {
      throw Throwables.propagate(e);
    }
  }
  return super.toString();
}
 
Example 6
Source File: HttpHeaders.java    From google-http-java-client with Apache License 2.0 5 votes vote down vote up
/**
 * Puts all headers of the {@link HttpHeaders} object into this {@link HttpHeaders} object.
 *
 * @param headers {@link HttpHeaders} from where the headers are taken
 * @since 1.10
 */
public final void fromHttpHeaders(HttpHeaders headers) {
  try {
    ParseHeaderState state = new ParseHeaderState(this, null);
    serializeHeaders(
        headers, null, null, null, new HeaderParsingFakeLevelHttpRequest(this, state));
    state.finish();
  } catch (IOException ex) {
    // Should never occur as we are dealing with a FakeLowLevelHttpRequest
    throw Throwables.propagate(ex);
  }
}
 
Example 7
Source File: UrlEncodedParser.java    From google-http-java-client with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the given URL-encoded content into the given data object of data key name/value pairs
 * using {@link #parse(Reader, Object)}.
 *
 * @param content URL-encoded content or {@code null} to ignore content
 * @param data data key name/value pairs
 * @param decodeEnabled flag that specifies whether decoding should be enabled.
 */
public static void parse(String content, Object data, boolean decodeEnabled) {
  if (content == null) {
    return;
  }
  try {
    parse(new StringReader(content), data, decodeEnabled);
  } catch (IOException exception) {
    // I/O exception not expected on a string
    throw Throwables.propagate(exception);
  }
}
 
Example 8
Source File: LinkHeaderParser.java    From android-oauth-client with Apache License 2.0 5 votes vote down vote up
public static void parse(String content, Object data) {
    if (content == null) {
        return;
    }
    try {
        parse(new StringReader(content), data);
    } catch (IOException exception) {
        // I/O exception not expected on a string
        throw Throwables.propagate(exception);
    }
}