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


Java Try.withCatch方法代码示例

本文整理汇总了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"));

}
 
开发者ID:aol,项目名称:micro-server,代码行数:17,代码来源:S3Reader.java

示例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();
    });

}
 
开发者ID:aol,项目名称:micro-server,代码行数:9,代码来源:S3Reader.java

示例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);

    });

}
 
开发者ID:aol,项目名称:micro-server,代码行数:26,代码来源:S3StringWriter.java

示例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)));
	 
}
 
开发者ID:aol,项目名称:micro-server,代码行数:11,代码来源:TransactionFlow.java


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