本文整理汇总了Java中cyclops.control.Try.withCatch方法的典型用法代码示例。如果您正苦于以下问题:Java Try.withCatch方法的具体用法?Java Try.withCatch怎么用?Java Try.withCatch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cyclops.control.Try
的用法示例。
在下文中一共展示了Try.withCatch方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAsString
import cyclops.control.Try; //导入方法依赖的package包/类
/**
*
* Read data from defined S3 bucket with provided key to a String
*
* @param key
* To read
* @return Data as String
*/
public Try<String, Throwable> getAsString(String key) {
return Try.withCatch(() -> ReactiveSeq.fromStream(new BufferedReader(
new InputStreamReader(
readUtils.getInputStream(bucket,
key))).lines())
.join("\n"));
}
示例2: getAsObject
import cyclops.control.Try; //导入方法依赖的package包/类
public <T> Try<T, Throwable> getAsObject(String key) {
return Try.withCatch(() -> {
ObjectInputStream ois = new ObjectInputStream(
readUtils.getInputStream(bucket, key));
return (T) ois.readObject();
});
}
示例3: put
import cyclops.control.Try; //导入方法依赖的package包/类
/**
*
* Writes String data to defined S3 bucket with provided key. Calling
* map / flatMap on the returned try instance will catch any exceptions, any
* exceptions thrown will convert a Success to a Failure
*
* This call is blocking.
*
* @param key
* To read
* @return Data as String
*/
public Try<PutObjectResult, Throwable> put(String key, String value) {
return Try.withCatch(() -> {
byte[] bytes = value.getBytes("UTF-8");
ByteArrayInputStream stream = new ByteArrayInputStream(
bytes);
ObjectMetadata md = createMetadata(bytes.length);
return client.putObject(bucket, key, stream, md);
});
}
示例4: execute
import cyclops.control.Try; //导入方法依赖的package包/类
/**
* Execute the transactional flow - catch all exceptions
*
* @param input Initial data input
* @return Try that represents either success (with result) or failure (with errors)
*/
public Try<R,Throwable> execute(T input){
return Try.withCatch( ()->transactionTemplate.execute(status-> transaction.apply(input)));
}