本文整理汇总了Java中com.amazonaws.util.IOUtils.copy方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java IOUtils.copy怎么用?Java IOUtils.copy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.util.IOUtils
的用法示例。
在下文中一共展示了IOUtils.copy方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeLocalFile
import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
private void writeLocalFile(
final S3Object s3Object,
final File file) {
try(FileOutputStream fileOutputStream
= new FileOutputStream(file)) {
IOUtils.copy(
s3Object.getObjectContent(),
fileOutputStream);
} catch (IOException ioException) {
throw new SecretsLockerException(
ioException);
}
file.deleteOnExit();
}
示例2: putLocalObject
import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
/**
* Used for performance testing purposes only.
*/
private void putLocalObject(final UploadObjectRequest reqIn,
OutputStream os) throws IOException {
UploadObjectRequest req = reqIn.clone();
final File fileOrig = req.getFile();
final InputStream isOrig = req.getInputStream();
if (isOrig == null) {
if (fileOrig == null)
throw new IllegalArgumentException("Either a file lor input stream must be specified");
req.setInputStream(new FileInputStream(fileOrig));
req.setFile(null);
}
try {
IOUtils.copy(req.getInputStream(), os);
} finally {
cleanupDataSource(req, fileOrig, isOrig,
req.getInputStream(), log);
IOUtils.closeQuietly(os, log);
}
return;
}
示例3: putLocalObjectSecurely
import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
@Override
public final void putLocalObjectSecurely(final UploadObjectRequest reqIn,
String uploadId, OutputStream os) throws IOException {
UploadObjectRequest req = reqIn.clone();
final File fileOrig = req.getFile();
final InputStream isOrig = req.getInputStream();
final T uploadContext = multipartUploadContexts.get(uploadId);
ContentCryptoMaterial cekMaterial = uploadContext.getContentCryptoMaterial();
req = wrapWithCipher(req, cekMaterial);
try {
IOUtils.copy(req.getInputStream(), os);
// so it won't crap out with a false negative at the end; (Not
// really relevant here)
uploadContext.setHasFinalPartBeenSeen(true);
} finally {
cleanupDataSource(req, fileOrig, isOrig,
req.getInputStream(), log);
IOUtils.closeQuietly(os, log);
}
return;
}
示例4: escrowDecrypt
import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
private static void escrowDecrypt(final String fileName) throws Exception {
// You can decrypt the stream using only the private key.
// This method does not call KMS.
// 1. Instantiate the SDK
final AwsCrypto crypto = new AwsCrypto();
// 2. Instantiate a JCE master key provider
// This method call uses the escrowed private key, not null
final JceMasterKey escrowPriv = JceMasterKey.getInstance(publicEscrowKey, privateEscrowKey, "Escrow", "Escrow",
"RSA/ECB/OAEPWithSHA-512AndMGF1Padding");
// 3. Decrypt the file
// To simplify the code, we omit the encryption context. Production code should always
// use an encryption context. For an example, see the other SDK samples.
final FileInputStream in = new FileInputStream(fileName + ".encrypted");
final FileOutputStream out = new FileOutputStream(fileName + ".deescrowed");
final CryptoOutputStream<?> decryptingStream = crypto.createDecryptingStream(escrowPriv, out);
IOUtils.copy(in, decryptingStream);
in.close();
decryptingStream.close();
}
示例5: decryptFile
import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
/**
* {@inheritDoc }
*/
@Override
public void decryptFile(
final String encryptedFilename,
final String decryptedFilename) {
final KmsMasterKeyProvider provider
= new KmsMasterKeyProvider(
new DefaultAWSCredentialsProviderChain());
final AwsCrypto awsCrypto
= new AwsCrypto();
try (final FileInputStream fileInputStream
= new FileInputStream(
encryptedFilename);
final FileOutputStream fileOutputStream
= new FileOutputStream(
decryptedFilename);
final CryptoInputStream<?> decryptingStream
= awsCrypto
.createDecryptingStream(
provider,
fileInputStream)) {
IOUtils.copy(
decryptingStream,
fileOutputStream);
} catch (IOException exception) {
throw new DecryptionException(exception);
}
}
示例6: readJson
import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
private byte[] readJson(InputStream jsonStream) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
IOUtils.copy(jsonStream, baos);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return baos.toByteArray();
}
示例7: main
import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
srcFile = args[0];
// In this example, we generate a random key. In practice,
// you would get a key from an existing store
SecretKey cryptoKey = retrieveEncryptionKey();
// Create a JCE master key provider using the random key and an AES-GCM encryption algorithm
JceMasterKey masterKey = JceMasterKey.getInstance(cryptoKey, "Example", "RandomKey", "AES/GCM/NoPadding");
// Instantiate the SDK
AwsCrypto crypto = new AwsCrypto();
// Create an encryption context to identify this ciphertext
Map<String, String> context = Collections.singletonMap("Example", "FileStreaming");
// Because the file might be to large to load into memory, we stream the data, instead of
//loading it all at once.
FileInputStream in = new FileInputStream(srcFile);
CryptoInputStream<JceMasterKey> encryptingStream = crypto.createEncryptingStream(masterKey, in, context);
FileOutputStream out = new FileOutputStream(srcFile + ".encrypted");
IOUtils.copy(encryptingStream, out);
encryptingStream.close();
out.close();
// Decrypt the file. Verify the encryption context before returning the plaintext.
in = new FileInputStream(srcFile + ".encrypted");
CryptoInputStream<JceMasterKey> decryptingStream = crypto.createDecryptingStream(masterKey, in);
// Does it contain the expected encryption context?
if (!"FileStreaming".equals(decryptingStream.getCryptoResult().getEncryptionContext().get("Example"))) {
throw new IllegalStateException("Bad encryption context");
}
// Return the plaintext data
out = new FileOutputStream(srcFile + ".decrypted");
IOUtils.copy(decryptingStream, out);
decryptingStream.close();
out.close();
}
示例8: standardEncrypt
import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
private static void standardEncrypt(final String kmsArn, final String fileName) throws Exception {
// Encrypt with the KMS CMK and the escrowed public key
// 1. Instantiate the SDK
final AwsCrypto crypto = new AwsCrypto();
// 2. Instantiate a KMS master key provider
final KmsMasterKeyProvider kms = new KmsMasterKeyProvider(kmsArn);
// 3. Instantiate a JCE master key provider
// Because the user does not have access to the private escrow key,
// they pass in "null" for the private key parameter.
final JceMasterKey escrowPub = JceMasterKey.getInstance(publicEscrowKey, null, "Escrow", "Escrow",
"RSA/ECB/OAEPWithSHA-512AndMGF1Padding");
// 4. Combine the providers into a single master key provider
final MasterKeyProvider<?> provider = MultipleProviderFactory.buildMultiProvider(kms, escrowPub);
// 5. Encrypt the file
// To simplify the code, we omit the encryption context. Production code should always
// use an encryption context. For an example, see the other SDK samples.
final FileInputStream in = new FileInputStream(fileName);
final FileOutputStream out = new FileOutputStream(fileName + ".encrypted");
final CryptoOutputStream<?> encryptingStream = crypto.createEncryptingStream(provider, out);
IOUtils.copy(in, encryptingStream);
in.close();
encryptingStream.close();
}
示例9: standardDecrypt
import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
private static void standardDecrypt(final String kmsArn, final String fileName) throws Exception {
// Decrypt with the KMS CMK and the escrow public key. You can use a combined provider,
// as shown here, or just the KMS master key provider.
// 1. Instantiate the SDK
final AwsCrypto crypto = new AwsCrypto();
// 2. Instantiate a KMS master key provider
final KmsMasterKeyProvider kms = new KmsMasterKeyProvider(kmsArn);
// 3. Instantiate a JCE master key provider
// Because the user does not have access to the private
// escrow key, they pass in "null" for the private key parameter.
final JceMasterKey escrowPub = JceMasterKey.getInstance(publicEscrowKey, null, "Escrow", "Escrow",
"RSA/ECB/OAEPWithSHA-512AndMGF1Padding");
// 4. Combine the providers into a single master key provider
final MasterKeyProvider<?> provider = MultipleProviderFactory.buildMultiProvider(kms, escrowPub);
// 5. Decrypt the file
// To simplify the code, we omit the encryption context. Production code should always
// use an encryption context. For an example, see the other SDK samples.
final FileInputStream in = new FileInputStream(fileName + ".encrypted");
final FileOutputStream out = new FileOutputStream(fileName + ".decrypted");
final CryptoOutputStream<?> decryptingStream = crypto.createDecryptingStream(provider, out);
IOUtils.copy(in, decryptingStream);
in.close();
decryptingStream.close();
}
示例10: test
import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
@Ignore("aws-credentials. Just for local testing")
@Test
public void test() throws Exception {
Integer rand = new Random().nextInt(1000);
ByteArrayOutputStream out = new ByteArrayOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8));
writer.write("test-" + rand + "\n");
writer.write("this is just a example file\n");
writer.write("not ascii chars: ñáéíóú\n");
writer.close();
byte[] bin = out.toByteArray();
InsuranceS3Service service = new InsuranceS3Service();
InsuranceS3Resource resource01 = new InsuranceS3Resource();
resource01.setContentEncoding("UTF-8");
resource01.setContentType("text/plain");
resource01.setParentPath("contract-documentation");
resource01.setName("resource-" + rand + ".txt");
service.upload(resource01, new ByteArrayInputStream(bin));
InsuranceS3Resource resource02 = new InsuranceS3Resource();
resource02.setName("non-existing-file.txt");
InputStream readedStream = service.download(resource01);
ByteArrayOutputStream outMemory = new ByteArrayOutputStream();
IOUtils.copy(readedStream, outMemory);
Assert.assertTrue(service.exists(resource01));
Assert.assertTrue(!service.exists(resource02));
try {
service.download(resource02);
Assert.fail();
}
catch (AmazonS3Exception ex) {
}
}
示例11: encryptFile
import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
/**
* {@inheritDoc }
*/
@Override
public File encryptFile(final File file) {
if (!file.exists())
throw new IllegalArgumentException(
String.format(
FILE_DOES_NOT_EXIST_PATTERN,
file.getAbsolutePath()));
if (!file.isFile())
throw new IllegalArgumentException(
String.format(
FILE_IS_NOT_A_NORMAL_FILE_PATTERN,
file.getAbsolutePath()));
if (!file.canRead())
throw new IllegalArgumentException(
String.format(
FILE_IS_NOT_READABLE_PATTERN,
file.getAbsolutePath()));
if (!file.getParentFile().canWrite())
throw new IllegalArgumentException(
String.format(
DIRECTORY_IS_NOT_READABLE,
file.getParentFile().getAbsolutePath()));
File encryptedFile
= new File(
new StringBuilder()
.append(file.getAbsoluteFile())
.append(SUFFIX)
.toString());
final AwsCrypto awsCrypto
= new AwsCrypto();
try (final FileInputStream fileInputStream
= new FileInputStream(file);
final FileOutputStream fileOutputStram
= new FileOutputStream(
encryptedFile);
final CryptoOutputStream<?> encryptingStream
= awsCrypto
.createEncryptingStream(
masterKeyProvider(),
fileOutputStram)) {
IOUtils.copy(
fileInputStream,
encryptingStream);
} catch (IOException exception) {
throw new EncryptionException(exception);
}
return encryptedFile;
}
示例12: process
import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
@Override
public void process(HttpResponse response, final HttpContext context)
throws HttpException, IOException {
final HttpEntity entity = response.getEntity();
// Only Json protocol has this header, we only wrap CRC32ChecksumCalculatingInputStream in json protocol clients.
Header[] headers = response.getHeaders("x-amz-crc32");
if (entity == null || headers == null || headers.length == 0) {
return;
}
HttpEntity crc32ResponseEntity = new HttpEntityWrapper(entity) {
private final InputStream content = new CRC32ChecksumCalculatingInputStream(
wrappedEntity.getContent());
@Override
public InputStream getContent() throws IOException {
return content;
}
/**
* It's important to override writeTo. Some versions of Apache HTTP
* client use writeTo for {@link org.apache.http.entity.BufferedHttpEntity}
* and the default implementation just delegates to the wrapped entity
* which completely bypasses our CRC32 calculating input stream. The
* {@link org.apache.http.entity.BufferedHttpEntity} is used for the
* request timeout and client execution timeout features.
*
* @see <a href="https://github.com/aws/aws-sdk-java/issues/526">Issue #526</a>
*
* @param outstream OutputStream to write contents to
*/
@Override
public void writeTo(OutputStream outstream) throws IOException {
try {
IOUtils.copy(this.getContent(), outstream);
} finally {
this.getContent().close();
}
}
};
response.setEntity(crc32ResponseEntity);
context.setAttribute(CRC32ChecksumCalculatingInputStream.class.getName(),
crc32ResponseEntity.getContent());
}
示例13: convertToByteArrInputStream
import com.amazonaws.util.IOUtils; //导入方法依赖的package包/类
public static ByteArrayInputStream convertToByteArrInputStream(InputStream input) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(input, baos);
byte[] bytes = baos.toByteArray();
return new ByteArrayInputStream(bytes);
}