com.google.api.client.util.Throwables Java Examples

The following examples show how to use com.google.api.client.util.Throwables. 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: CustomLocalServerReceiver.java    From hop with Apache License 2.0 6 votes vote down vote up
public String getRedirectUri() throws IOException {
  if ( this.port == -1 ) {
    this.port = getUnusedPort();
  }

  this.server = new Server( this.port );
  Connector[] arr$ = this.server.getConnectors();
  int len$ = arr$.length;

  for ( int i$ = 0; i$ < len$; ++i$ ) {
    Connector c = arr$[i$];
    c.setHost( this.host );
  }

  this.server.addHandler( new CustomLocalServerReceiver.CallbackHandler() );

  try {
    this.server.start();
  } catch ( Exception var5 ) {
    Throwables.propagateIfPossible( var5 );
    throw new IOException( var5 );
  }

  return "http://" + this.host + ":" + this.port + "/Callback/success.html";
}
 
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,
    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 #3
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 #4
Source File: LocalServerReceiver.java    From google-oauth-java-client with Apache License 2.0 6 votes vote down vote up
@Override
public String getRedirectUri() throws IOException {

  server = HttpServer.create(new InetSocketAddress(port != -1 ? port : findOpenPort()), 0);
  HttpContext context = server.createContext(callbackPath, new CallbackHandler());
  server.setExecutor(null);

  try {
    server.start();
    port = server.getAddress().getPort();
  } catch (Exception e) {
    Throwables.propagateIfPossible(e);
    throw new IOException(e);
  }
  return "http://" + this.getHost() + ":" + port + callbackPath;
}
 
Example #5
Source File: CustomLocalServerReceiver.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public String getRedirectUri() throws IOException {
  if ( this.port == -1 ) {
    this.port = getUnusedPort();
  }

  this.server = new Server( this.port );
  Connector[] arr$ = this.server.getConnectors();
  int len$ = arr$.length;

  for ( int i$ = 0; i$ < len$; ++i$ ) {
    Connector c = arr$[i$];
    c.setHost( this.host );
  }

  this.server.addHandler( new CustomLocalServerReceiver.CallbackHandler() );

  try {
    this.server.start();
  } catch ( Exception var5 ) {
    Throwables.propagateIfPossible( var5 );
    throw new IOException( var5 );
  }

  return "http://" + this.host + ":" + this.port + "/Callback/success.html";
}
 
Example #6
Source File: CustomLocalServerReceiver.java    From hop with Apache License 2.0 5 votes vote down vote up
public void stop() throws IOException {
  if ( this.server != null ) {
    try {
      this.server.stop();
    } catch ( Exception var2 ) {
      Throwables.propagateIfPossible( var2 );
      throw new IOException( var2 );
    }
    this.server = null;
  }
}
 
Example #7
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 #8
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 #9
Source File: ProtocolBuffers.java    From google-http-java-client with Apache License 2.0 5 votes vote down vote up
/**
 * Parses protocol buffer content from an input stream (closing the input stream) into a protocol
 * buffer message.
 *
 * @param <T> destination message type
 * @param messageClass destination message class that has a {@code parseFrom(InputStream)} public
 *     static method
 * @return new instance of the parsed destination message class
 */
public static <T extends MessageLite> T parseAndClose(
    InputStream inputStream, Class<T> messageClass) throws IOException {
  try {
    Method newBuilder = messageClass.getDeclaredMethod("parseFrom", InputStream.class);
    return messageClass.cast(newBuilder.invoke(null, inputStream));
  } catch (Exception e) {
    Throwables.propagateIfPossible(e, IOException.class);
    IOException io = new IOException("Error parsing message of type " + messageClass);
    io.initCause(e);
    throw io;
  } finally {
    inputStream.close();
  }
}
 
Example #10
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 #11
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 #12
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 #13
Source File: LocalServerReceiver.java    From google-oauth-java-client with Apache License 2.0 5 votes vote down vote up
@Override
public void stop() throws IOException {
  waitUnlessSignaled.release();
  if (server != null) {
    try {
      server.stop(0);
    } catch (Exception e) {
      Throwables.propagateIfPossible(e);
      throw new IOException(e);
    }
    server = null;
  }
}
 
Example #14
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);
    }
}
 
Example #15
Source File: CustomLocalServerReceiver.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void stop() throws IOException {
  if ( this.server != null ) {
    try {
      this.server.stop();
    } catch ( Exception var2 ) {
      Throwables.propagateIfPossible( var2 );
      throw new IOException( var2 );
    }
    this.server = null;
  }
}