Amazon S3から特定のファイルを抽出しようとしていますが、アーカイブが膨大なものになる可能性があります。Amazon S3から部分的にtar.gzファイルを読み取る
私はAWS Java SDKを使用しています。ここでは、コードは(例外処理はスキップ):私はこの方法を使用する場合
AWSCredentials credentials = new BasicAWSCredentials("accessKey", "secretKey");
AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(Regions.US_EAST_1).withCredentials(credentialsProvider).build();
S3Object object = s3Client.getObject("bucketname", "file.tar.gz");
S3ObjectInputStream objectContent = object.getObjectContent();
TarArchiveInputStream tarInputStream = new TarArchiveInputStream(new GZIPInputStream(objectContent));
TarArchiveEntry currentEntry;
while((currentEntry = tarInputStream.getNextTarEntry()) != null) {
if(currentEntry.getName().equals("1/foo.bar") && currentEntry.isFile()) {
FileOutputStream entryOs = new FileOutputStream("foo.bar");
IOUtils.copy(tarInputStream, entryOs);
entryOs.close();
break;
}
}
objectContent.abort(); // Warning at this line
tarInputStream.close(); // warning at this line
それは私が意図的にやっているストリームからではないすべてのバイトが読み込まれたことを示す警告を与えます。
WARNING: Not all bytes were read from the S3ObjectInputStream, aborting HTTP connection. This is likely an error and may result in sub-optimal behavior. Request only the bytes you need via a ranged GET or drain the input stream after use.
それが流れを排出するために、何がそれをやっていないの欠点だろう必要ですか?私は警告を無視することはできますか?
はい、私はたぶんファイル全体を何度か読んでいるかもしれませんが、ほとんどの場合、私は読書を省くことができると思います。ファイルのアップロード方法には影響しません。私の質問は、この警告を無視できるかどうかと、ストリームが流出していない場合にどのような影響がありますか? – ares
公正なコメント - 警告は無視できます。それは、HTTP接続を終了するので、あなたはトランジット中の何かを失うことを伝えます。 'close()'は 'abort()'にデリゲートするので、この警告も発生します - 今答えに追加されました – diginoise