没有使用Hadoop文件系统和BouncyCastle将数据写入S3

没有使用Hadoop文件系统和BouncyCastle将数据写入S3,hadoop,amazon-web-services,amazon-s3,bouncycastle,Hadoop,Amazon Web Services,Amazon S3,Bouncycastle,我使用以下代码将加密数据写入Amazon S3: byte[] bytes = compressFile(instr, CompressionAlgorithmTags.ZIP); PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(PGPEncryptedData.CAST5).setWithIntegrityPacket(withIntegrityCh

我使用以下代码将加密数据写入Amazon S3:

byte[] bytes = compressFile(instr, CompressionAlgorithmTags.ZIP);

PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(PGPEncryptedData.CAST5).setWithIntegrityPacket(withIntegrityCheck).setSecureRandom(new SecureRandom()).setProvider("BC"));

encGen.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(pubKey).setProvider("BC"));

OutputStream cOut = encGen.open(out, bytes.length);

cOut.write(bytes);
cOut.close();
如果我打算:

final OutputStream fsOutStr = new FileOutputStream(new File("/home/hadoop/encrypted.gpg"));
它可以很好地写入文件

但是,当我尝试将其写入S3时,它不会给我任何错误,似乎可以工作,但在检查S3时,S3上没有数据:

final FileSystem fileSys  = FileSystem.get(new URI(GenericUtils.getAsEncodedStringIfEmbeddedSpaces(s3OutputDir)), new Configuration());
final OutputStream fsOutStr = fileSys.create(new Path(s3OutputDir)); // outputPath on S3

知道为什么它会将数据完美地写入本地磁盘,但不会将文件写入S3吗?

关闭fsoutsr解决了问题。

我猜这只是关闭“fsoutsr”失败。关闭“cOut”会将所有剩余数据写入底层流,但它不会关闭,甚至不会刷新该流。可能S3流有一些FileOutputStream没有的缓冲区。