ObjectStoreContentProviderUtils { private static byte[] getContentFromS3(String resourceLoc, ContentRetrievalContext context) throws IOException, InvalidSizeException, S3EndpointNotFoundException { if (context.getS3Client() != null) { S3ObjectId objId = getObjectId(resourceLoc); S3Object s3Obj = context.getS3Client().getObject(new GetObjectRequest(objId)); if (s3Obj != null) { if (s3Obj.getObjectMetadata().getContentLength() > 0) { InputStream is = s3Obj.getObjectContent(); try { return IOUtils.toByteArray(is); } finally { is.close(); } } else { throw new InvalidSizeException(); } } else { throw new IOException("S3 object not found for id " + objId + " generated based on location: " + resourceLoc); } } else { throw new S3EndpointNotFoundException("no S3 client defined, " + "most probably '" + IMPORT_CONTENT_OBJECT_STORE_S3_ENDPOINT + "' configuration property is missing!"); } } private  ObjectStoreContentProviderUtils(); static byte[] getContentFromURL(String resourceLoc,
			ContentRetrievalContext context); static byte[] getContentFromURL(URL url,
            ContentRetrievalContext context); static String generateObjectId(String resultId, String url,
			String defaultEncoding, String digestAlgorithm); static String extractResultIdFromObjectId(String objectId); static final String defaultEncoding; }
@Test public void testGetContentFromS3() throws Exception { ContentRetrievalContext context = new ContentRetrievalContext(1, 1, 1); context.setS3Client(s3Client); when(s3Client.getObject(argThat(new GetObjectArgumentMatcher()))).thenReturn(s3Object); when(s3Object.getObjectMetadata()).thenReturn(s3ObjectMeta); when(s3ObjectMeta.getContentLength()).thenReturn(Long.valueOf(1)); when(s3Object.getObjectContent()).thenReturn(s3ObjectInputStream); when(s3ObjectInputStream.read(any())).thenReturn(1, IOUtils.EOF); byte[] result = ObjectStoreContentProviderUtils.getContentFromURL(s3ResourceLoc, context); assertNotNull(result); assertEquals(result.length, 1); assertEquals(result[0], 0); verify(s3ObjectInputStream, times(1)).close(); }