Java Code Examples for org.springframework.core.io.WritableResource#getOutputStream()
The following examples show how to use
org.springframework.core.io.WritableResource#getOutputStream() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceLoaderAwsTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void testUploadFileWithRelativePath() throws Exception { String bucketName = this.stackResourceRegistry .lookupPhysicalResourceId("EmptyBucket"); uploadFileTestFile(bucketName, "testUploadFileWithRelativePathParent", "hello world"); Resource resource = this.resourceLoader.getResource( S3_PREFIX + bucketName + "/testUploadFileWithRelativePathParent"); assertTrue(resource.exists()); WritableResource childFileResource = (WritableResource) resource .createRelative("child"); try (OutputStream outputStream = childFileResource.getOutputStream(); OutputStreamWriter writer = new OutputStreamWriter(outputStream)) { writer.write("hello world"); } this.createdObjects.add(childFileResource.getFilename()); InputStream inputStream = childFileResource.getInputStream(); assertNotNull(inputStream); assertEquals("hello world", FileCopyUtils.copyToString(new InputStreamReader(inputStream, "UTF-8"))); assertEquals("hello world".length(), childFileResource.contentLength()); }
Example 2
Source File: GoogleStorageTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void testWritable() throws Exception { WriteChannel writeChannel = mock(WriteChannel.class); when(this.mockStorage.writer(any(BlobInfo.class))).thenReturn(writeChannel); Assert.assertTrue(this.remoteResource instanceof WritableResource); WritableResource writableResource = (WritableResource) this.remoteResource; Assert.assertTrue(writableResource.isWritable()); writableResource.getOutputStream(); }
Example 3
Source File: ResourceLoaderAwsTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void testUploadFileWithMoreThenFiveMegabytes() throws Exception { String bucketName = this.stackResourceRegistry .lookupPhysicalResourceId("EmptyBucket"); Resource resource = this.resourceLoader.getResource( S3_PREFIX + bucketName + "/testUploadFileWithMoreThenFiveMegabytes"); assertTrue(WritableResource.class.isInstance(resource)); WritableResource writableResource = (WritableResource) resource; OutputStream outputStream = writableResource.getOutputStream(); for (int i = 0; i < (1024 * 1024 * 6); i++) { outputStream.write("c".getBytes("UTF-8")); } outputStream.close(); this.createdObjects.add("testUploadFileWithMoreThenFiveMegabytes"); }
Example 4
Source File: SpringCloudS3.java From tutorials with MIT License | 4 votes |
public void uploadFileToS3(File file, String s3Url) throws IOException { WritableResource resource = (WritableResource) resourceLoader.getResource(s3Url); try (OutputStream outputStream = resource.getOutputStream()) { Files.copy(file.toPath(), outputStream); } }