仍然是Scala中的新手,我现在正在寻找一种方法来实现以下代码:
@Override
public void store(InputStream source, String destination, long size) {
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(size);
final PutObjectRequest request = new PutObjectRequest(
this.configuration.getBucket(), destination, source, metadata);
new RetryableService(3) {
@Override
public void call() throws Exception {
getClient().putObject(request);
}
};
}
Run Code Online (Sandbox Code Playgroud)
在Scala中实现RetryableService实现的相同功能的最佳方法是什么?
它基本上调用了N次调用方法,如果所有这些都失败,则会引发异常,如果它们成功则继续运行.这个没有返回任何东西但是我有另一个版本允许返回一个值(所以,我有两个Java类)我相信我可以用Scala中的单个类/函数.
有任何想法吗?
编辑
java中的当前实现如下:
public abstract class RetryableService {
private static final JobsLogger log = JobsLogger
.getLogger(RetryableService.class);
private int times;
public RetryableService() {
this(3);
}
public RetryableService(int times) {
this.times = times;
this.run();
}
private void …Run Code Online (Sandbox Code Playgroud) 有问题的文件不在我的控制之下.大多数字节序列都是有效的UTF-8,它不是ISO-8859-1(或其他编码).我想尽我所能提取尽可能多的信息.
该文件包含一些非法字节序列,应替换为替换字符.
这不是一件容易的事,它认为它需要一些关于UTF-8状态机的知识.
Oracle有一个包装器可以满足我的需求:
UTF8ValidationFilter javadoc
是否有类似的东西(商业或免费软件)?
谢谢 -
喜剧
解:
final BufferedInputStream in = new BufferedInputStream(istream);
final CharsetDecoder charsetDecoder = StandardCharsets.UTF_8.newDecoder();
charsetDecoder.onMalformedInput(CodingErrorAction.REPLACE);
charsetDecoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
final Reader inputReader = new InputStreamReader(in, charsetDecoder);
Run Code Online (Sandbox Code Playgroud) Scanner in = new Scanner(System.in,"UTF-8");
System.out.println(in.next());
Run Code Online (Sandbox Code Playgroud)
如果我粘贴?,我收到?控制台的输出.有人可以解释我能做些什么来正确读取这样的逻辑符号?我正在使用NetBeans 8.0.1.
谢谢.