当前位置: 首页>>代码示例>>Java>>正文


Java Throwables类代码示例

本文整理汇总了Java中com.google.common.base.Throwables的典型用法代码示例。如果您正苦于以下问题:Java Throwables类的具体用法?Java Throwables怎么用?Java Throwables使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Throwables类属于com.google.common.base包,在下文中一共展示了Throwables类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: forwardToUrl

import com.google.common.base.Throwables; //导入依赖的package包/类
@Override
public void forwardToUrl(SectionInfo info, String link, int code)
{
	info.setRendered();
	try
	{
		HttpServletResponse response = info.getResponse();
		if( response == null )
		{
			throw new Error("info not bound to a request/response");
		}
		response.setStatus(code);
		response.setHeader("Location", link);
		response.flushBuffer();
	}
	catch( Exception e )
	{
		throw Throwables.propagate(e);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:21,代码来源:SectionsControllerImpl.java

示例2: to

import com.google.common.base.Throwables; //导入依赖的package包/类
@Override
public void to(final File out, final T object) {
    try (StringWriter writer = new StringWriter()) {
        this.objectMapper.writer(this.prettyPrinter).writeValue(writer, object);

        if (isJsonFormat()) {
            try (FileWriter fileWriter = new FileWriter(out);
                 BufferedWriter buffer = new BufferedWriter(fileWriter)) {
                JsonValue.readHjson(writer.toString()).writeTo(buffer);
                buffer.flush();
                fileWriter.flush();
            }
        } else {
            FileUtils.write(out, writer.toString(), StandardCharsets.UTF_8);
        }
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:20,代码来源:AbstractJacksonBackedStringSerializer.java

示例3: generate

import com.google.common.base.Throwables; //导入依赖的package包/类
/**
 * Generate.
 */
@PostConstruct
public void generate() {
    try {
        final File file = oidcProperties.getJwksFile().getFile();
        if (!file.exists()) {
            final RsaJsonWebKey rsaJsonWebKey = RsaJwkGenerator.generateJwk(2048);
            final JsonWebKeySet jsonWebKeySet = new JsonWebKeySet(rsaJsonWebKey);
            final String data = jsonWebKeySet.toJson(JsonWebKey.OutputControlLevel.INCLUDE_PRIVATE);
            FileUtils.write(file, data, StandardCharsets.UTF_8);
            LOGGER.debug("Generated JSON web keystore at [{}]", file);
        } else {
            LOGGER.debug("Located JSON web keystore at [{}]", file);
        }
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:21,代码来源:OidcJsonWebKeystoreGeneratorService.java

示例4: anoint

import com.google.common.base.Throwables; //导入依赖的package包/类
/**
 * Applies an {@link AtomixLeaderElectorCommands.Anoint} commit.
 * @param commit anoint commit
 * @return {@code true} if changes were made and the transfer occurred; {@code false} if it did not.
 */
public boolean anoint(Commit<? extends Anoint> commit) {
    try {
        String topic = commit.operation().topic();
        NodeId nodeId = commit.operation().nodeId();
        Leadership oldLeadership = leadership(topic);
        ElectionState electionState = elections.computeIfPresent(topic,
                (k, v) -> v.transferLeadership(nodeId, termCounter(topic)));
        Leadership newLeadership = leadership(topic);
        if (!Objects.equal(oldLeadership, newLeadership)) {
            notifyLeadershipChange(oldLeadership, newLeadership);
        }
        return (electionState != null &&
                electionState.leader() != null &&
                commit.operation().nodeId().equals(electionState.leader().nodeId()));
    } catch (Exception e) {
        log.error("State machine operation failed", e);
        throw Throwables.propagate(e);
    } finally {
        commit.close();
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:27,代码来源:AtomixLeaderElectorState.java

示例5: innerStart

import com.google.common.base.Throwables; //导入依赖的package包/类
@Override
public void innerStart() {
    try {
        countFuture = countOperation.count(indexShardMap, whereClause);
    } catch (IOException | InterruptedException e) {
        throw Throwables.propagate(e);
    }
    Futures.addCallback(countFuture, new FutureCallback<Long>() {
        @Override
        public void onSuccess(@Nullable Long result) {
            rowReceiver.setNextRow(new Row1(result));
            close();
        }

        @Override
        public void onFailure(@Nonnull Throwable t) {
            close(t);
        }
    });
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:21,代码来源:CountContext.java

示例6: remaining

import com.google.common.base.Throwables; //导入依赖的package包/类
public static int remaining(Channel ch) throws EventDeliveryException {
  Transaction t = ch.getTransaction();
  try {
    t.begin();
    int count = 0;
    while (ch.take() != null) {
      count += 1;
    }
    t.commit();
    return count;
  } catch (Throwable th) {
    t.rollback();
    Throwables.propagateIfInstanceOf(th, Error.class);
    Throwables.propagateIfInstanceOf(th, EventDeliveryException.class);
    throw new EventDeliveryException(th);
  } finally {
    t.close();
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:20,代码来源:TestDatasetSink.java

示例7: apply

import com.google.common.base.Throwables; //导入依赖的package包/类
@SuppressWarnings("squid:S1181")
// Yes we really do want to catch Throwable
@Override
public V apply(U input) {
    int retryAttempts = 0;
    while (true) {
        try {
            return baseFunction.apply(input);
        } catch (Throwable t) {
            if (!exceptionClass.isAssignableFrom(t.getClass()) || retryAttempts == maxRetries) {
                Throwables.propagate(t);
            }
            Tools.randomDelay(maxDelayBetweenRetries);
            retryAttempts++;
        }
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:18,代码来源:RetryingFunction.java

示例8: getLiveItemVersion

import com.google.common.base.Throwables; //导入依赖的package包/类
@Override
public int getLiveItemVersion(String uuid)
{
	try
	{
		final String response = doGetItem(uuid, "latest", "detail");
		if( response == null )
		{
			throw new NotFoundException("No cloud item with UUID " + uuid);
		}
		final CloudItemBean cib = getObjectMapper().readValue(response, CloudItemBean.class);
		return cib.getVersion();
	}
	catch( Exception e )
	{
		throw Throwables.propagate(e);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:19,代码来源:CloudServiceImpl.java

示例9: getFileAsBinData

import com.google.common.base.Throwables; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private BinData getFileAsBinData(FileHandle file, String filename)
{
	try( InputStream in = fileSystemService.read(file, filename) )
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		ByteStreams.copy(in, baos);

		BinData data = new BinData();
		data.getContent().add(new PCData(new Base64().encode(baos.toByteArray())));
		return data;
	}
	catch( IOException io )
	{
		throw Throwables.propagate(io);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:18,代码来源:AbstractMetsAttachmentImportExporter.java

示例10: submit

import com.google.common.base.Throwables; //导入依赖的package包/类
private <T> void submit(Query<T> query, int attemptIndex, CompletableFuture<T> future) {
    client.submit(query).whenComplete((r, e) -> {
        if (e != null) {
            if (attemptIndex < maxRetries + 1 && retryableCheck.test(Throwables.getRootCause(e))) {
                log.debug("Retry attempt ({} of {}). Failure due to {}",
                        attemptIndex, maxRetries, Throwables.getRootCause(e).getClass());
                executor.schedule(() ->
                    submit(query, attemptIndex + 1, future), delayBetweenRetriesMillis, TimeUnit.MILLISECONDS);
            } else {
                future.completeExceptionally(e);
            }
        } else {
            future.complete(r);
        }
    });
}
 
开发者ID:shlee89,项目名称:athena,代码行数:17,代码来源:OnosCopycatClient.java

示例11: addCRL

import com.google.common.base.Throwables; //导入依赖的package包/类
@Override
protected boolean addCRL(final Object id, final X509CRL crl) {
    try {
        if (crl == null) {
            LOGGER.debug("No CRL was passed. Removing [{}] from cache...", id);
            return this.crlCache.remove(id);
        }

        this.crlCache.put(new Element(id, crl.getEncoded()));
        return this.crlCache.get(id) != null;

    } catch (final Exception e) {
        LOGGER.warn("Failed to add the crl entry [{}] to the cache", crl);
        throw Throwables.propagate(e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:17,代码来源:CRLDistributionPointRevocationChecker.java

示例12: processStreamRequest

import com.google.common.base.Throwables; //导入依赖的package包/类
private void processStreamRequest(final StreamRequest req) {
  ManagedBuffer buf;
  try {
    buf = streamManager.openStream(req.streamId);
  } catch (Exception e) {
    logger.error(String.format(
      "Error opening stream %s for request from %s", req.streamId, getRemoteAddress(channel)), e);
    respond(new StreamFailure(req.streamId, Throwables.getStackTraceAsString(e)));
    return;
  }

  if (buf != null) {
    respond(new StreamResponse(req.streamId, buf.size(), buf));
  } else {
    respond(new StreamFailure(req.streamId, String.format(
      "Stream '%s' was not found.", req.streamId)));
  }
}
 
开发者ID:spafka,项目名称:spark_deep,代码行数:19,代码来源:TransportRequestHandler.java

示例13: extractText

import com.google.common.base.Throwables; //导入依赖的package包/类
@Override
public void extractText(String mimeType, InputStream input, StringBuilder outputText, int maxSize)
	throws IOException
{
	WriteOutContentHandler wrapped = new WriteOutContentHandler(maxSize);
	ContentHandler handler = new BodyContentHandler(wrapped);
	try
	{
		Metadata meta = new Metadata();
		Parser parser = new AutoDetectParser(new TikaConfig(getClass().getClassLoader()));
		parser.parse(input, handler, meta, new ParseContext());

		appendText(handler, outputText, maxSize);
	}
	catch( Exception t )
	{
		if( wrapped.isWriteLimitReached(t) )
		{
			// keep going
			LOGGER.debug("PDF size limit reached.  Indexing truncated text");
			appendText(handler, outputText, maxSize);
			return;
		}
		throw Throwables.propagate(t);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:27,代码来源:PdfExtracter.java

示例14: sendTaskMessage

import com.google.common.base.Throwables; //导入依赖的package包/类
private InstitutionMessageResponse sendTaskMessage(InstitutionMessage message)
{
	InstitutionMessageResponse response = taskService.postSynchronousMessage(institutionTaskId, message,
			DEFAULT_TIMEOUT);

	Map<Long, InstitutionStatus> map = response.getInstitutionMap();
	if( map != null )
	{
		setAllInstitutions(map);
	}
	Throwable error = response.getError();
	if( error != null )
	{
		Throwables.propagate(error);
	}
	return response;
}
 
开发者ID:equella,项目名称:Equella,代码行数:18,代码来源:InstitutionServiceImpl.java

示例15: deleteTable

import com.google.common.base.Throwables; //导入依赖的package包/类
@Override
public void deleteTable(ByteBuffer in_tableName) throws IOError {
  TableName tableName = getTableName(in_tableName);
  if (LOG.isDebugEnabled()) {
    LOG.debug("deleteTable: table=" + tableName);
  }
  try {
    if (!getAdmin().tableExists(tableName)) {
      throw new IOException("table does not exist");
    }
    getAdmin().deleteTable(tableName);
  } catch (IOException e) {
    LOG.warn(e.getMessage(), e);
    throw new IOError(Throwables.getStackTraceAsString(e));
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:17,代码来源:ThriftServerRunner.java


注:本文中的com.google.common.base.Throwables类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。