我正在尝试列出Google存储桶中一个目录中的所有文件 并且从每个文件读取数据,对于一些它正在工作但是 对于一个桶,它会抛出错误
引起: com.google.api.client.googleapis.json.GoogleJsonResponseException:500 内部服务器错误{“code”:500,“errors”:[{“domain”: “global”,“message”:“内部错误”,“原因”:“responseTooLarge” }],“message”:“内部错误”
stacktrace:线程“main”中的异常 com.google.cloud.storage.StorageException:内部错误 com.google.cloud.storage.spi.v1.HttpStorageRpc.translate(HttpStorageRpc.java:220) 在 com.google.cloud.storage.spi.v1.HttpStorageRpc.list(HttpStorageRpc.java:346) 在com.google.cloud.storage.StorageImpl $ 8.call(StorageImpl.java:299) 在com.google.cloud.storage.StorageImpl $ 8.call(StorageImpl.java:296) 在com.google.api.gax.retrying.DirectRetryingExecutor.submit(at com.google.cloud.RetryHelper.run(RetryHelper.java:74)at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:51)at at com.google.cloud.storage.StorageImpl.listBlobs(StorageImpl.java:295) 在com.google.cloud.storage.StorageImpl.list(StorageImpl.java:262)at WriteToGs.main(WriteToGs.java:22)
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class WriteToGs {
static PGPContainer pgpContainer = new PGPContainer();
final static Storage storage = StorageOptions.getDefaultInstance().getService();
public static void main(String[] args) throws Exception {
final DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm");
final Date date = new Date();
final String destinationDirectory=args[2];
final String flowname=args[3];
final String num_threads=args[4];
Iterable<Blob> blobs = storage.list(args[0], Storage.BlobListOption.prefix(args[1])).iterateAll();
ExecutorService executorService = Executors.newFixedThreadPool(Integer.parseInt(num_threads));
for (Blob blob : blobs) {
System.out.println("Blob name:"+blob.getName());
final String destinationFilename=blob.getName();
final Blob contentBlob=blob;
executorService.execute(new Runnable() {
public void run() {
String fileContent = new String(contentBlob.getContent());
BlobId newblobId = BlobId.of(destinationDirectory,"xyz/fds" + flowname + "/"
+ dateFormat.format(date) + "/" + destinationFilename.replace(".txt",".pgp"));
BlobInfo blobInfo = BlobInfo.newBuilder(newblobId).setContentType("text/plain").build();
try {
System.out.println("Blob name deleted:"+contentBlob.getName());
storage.delete(contentBlob.getBlobId());
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
executorService.shutdown();
}
}
答案 0 :(得分:1)
好吧,假设第22行(错误的出处)就是那一行:
System.out.println("Blob name:"+blob.getName());
blob中的属性“ name”可能足够大,足以破坏应用程序。但是我几乎可以确定这不是应用程序损坏的地方。
基于类似的问题GoogleJsonResponseException: 500 Internal Server Error : Response Too Large To Return,我建议您创建一个错误,因为这可能是与Google库直接相关的问题。