本文整理匯總了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);
}
}
示例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);
}
}
示例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);
}
}
示例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();
}
}
示例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);
}
});
}
示例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();
}
}
示例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++;
}
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
});
}
示例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);
}
}
示例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)));
}
}
示例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);
}
}
示例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;
}
示例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));
}
}