當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。