我正在尝试从 S3 读取一些文件并对每个文件进行一些处理。我可以访问一些文件,但在处理过程中我不断收到Java.net.SocketException: Connection Reset at the same line in a certain file 。有问题的文件应该没问题,因为我可以使用相同的类和方法(conversionUtils.convert())在本地处理它。
服务等级:
public class FileService {
@Inject
private S3Utils s3utils;
private ConversionUtils conversionUtils = new ConversionUtils();
public void processFile() {
List<S3ObjectSummary> files = s3utils.getAllFiles();
List<S3Object> unprocessedFiles = s3utils.getUnprocessedFiles(files);
for(S3Object file: unprocessedFiles) {
InputStream content = file.getObjectContent();
List<Record> records = conversionUtils.convert(content); //Exception thrown here
}
}
}
Run Code Online (Sandbox Code Playgroud)
S3Utils类:
@Component
public class S3utils {
@Inject AmazonS3 amazonS3;
public List<S3ObjectSummary> getAllFiles() {
ListObjectsV2Request request = new ListObjectsV2Request().withBucketName('something').withPrefix('some_prefix');
ListObjectsV2Result result …Run Code Online (Sandbox Code Playgroud) 我有一个嵌套结构数组t,格式为tab = value,其中a和b只是随机字符串.t可以具有任意数量的a作为字段名称,并且每个a可以具有任意数量的b作为字段名称.我需要制作一个名为x的副本,但是设置所有xab = 0.另外,我需要以ya = 0的形式为t中的所有a创建另一个结构数组.现在我正在使用嵌套的for循环解决方案,但如果有太多的a和b,它太慢了.有人能告诉我是否有任何方法可以对此嵌套循环或此代码中的任何其他操作进行矢量化,以使此代码运行得更快?谢谢.
names1 = fieldnames(t);
x = t;
y = {};
for i=1:length(names1)
y.(names1{i}) = 0;
names2 = fieldnames(x.(names1{i}));
for j=1:length(names2)
x.(names1{i}).(names2{j}) = 0;
end
end
Run Code Online (Sandbox Code Playgroud)
样品:
if t is such that
t.hello.world = 0.5
t.hello.mom = 0.2
t.hello.dad = 0.8
t.foo.bar = 0.7
t.foo.moo = 0.23
t.random.word = 0.38
then x should be:
x.hello.world = 0
x.hello.mom = 0
x.hello.dad = 0
x.foo.bar = 0
x.foo.moo = 0
x.random.word = 0
and y should …Run Code Online (Sandbox Code Playgroud) 我有一个包含句子字符串的单元格数组x的单元格数组,我希望在x中找到所有唯一字标记的列表,然后使用它为数组结构创建字段名称y如果该字段名称尚不存在因为你 现在我使用double for循环迭代x中的每个句子字符串,然后迭代每个单独的单词来完成任务,但是当单元格数组包含太多字符串时它可能会非常慢.
for i=1:length(x)
unique = unique(x{i});
for j=1:length(unique)
y.(unique{j}) = {};
end
end
Run Code Online (Sandbox Code Playgroud)
样本输入:
x = {{'hello', 'world'}, {'foo', 'bar'}, {'eat', 'foo', 'ice', 'cream'}, {'hello', 'dad'}};
y = {};
Run Code Online (Sandbox Code Playgroud)
那么独特应该是这样的
unique = {'hello', 'world', 'foo', 'bar', 'eat', 'ice', 'cream', 'dad'}
Run Code Online (Sandbox Code Playgroud)
和结构数组y应该具有唯一的字段名称作为字段名称.所以应该有y.hello,y.world,y.foo,y.bar,y.eat,y.ice,y.cream和y.dad.只要根据需要输出长y,就不需要唯一的单词令牌列表.有没有办法通过矢量化或其他方式简化这些操作以使程序运行得更快?谢谢.