@Test public void test_RetrieveFile_DoesNotExist() throws IOException { assertNull (mediaStorageClient.retrieve(mediaFile.getId(), false)); }
@Override public MediaFile retrieve (String id, Boolean withContent) throws IOException { final SwiftObject swiftObject = withContent ? objectApi.get(id) : objectApi.getWithoutBody(id); if (null == swiftObject) { return null; } final byte[] content = withContent ? IOUtils.toByteArray(swiftObject.getPayload().openStream()) : new byte[0]; final String contentMd5 = computeMd5(content); final String swiftObjectMd5 = swiftObject.getPayload().getContentMetadata().getContentMD5AsHashCode().toString(); if (withContent && !contentMd5.equals(swiftObjectMd5)) { throw new SecurityException("MD5 of content differs from expected"); } return new MediaFile(id, null, swiftObject.getName(), null, contentMd5, null, null, content, null, swiftObject.getMetadata().get("content-type"), null, Integer.parseInt(swiftObject.getMetadata().get("size")) ); }
SwiftMediaStorageClientImpl implements MediaStorageClient { @Override public MediaFile retrieve (String id, Boolean withContent) throws IOException { final SwiftObject swiftObject = withContent ? objectApi.get(id) : objectApi.getWithoutBody(id); if (null == swiftObject) { return null; } final byte[] content = withContent ? IOUtils.toByteArray(swiftObject.getPayload().openStream()) : new byte[0]; final String contentMd5 = computeMd5(content); final String swiftObjectMd5 = swiftObject.getPayload().getContentMetadata().getContentMD5AsHashCode().toString(); if (withContent && !contentMd5.equals(swiftObjectMd5)) { throw new SecurityException("MD5 of content differs from expected"); } return new MediaFile(id, null, swiftObject.getName(), null, contentMd5, null, null, content, null, swiftObject.getMetadata().get("content-type"), null, Integer.parseInt(swiftObject.getMetadata().get("size")) ); } }
SwiftMediaStorageClientImpl implements MediaStorageClient { @Override public MediaFile retrieve (String id, Boolean withContent) throws IOException { final SwiftObject swiftObject = withContent ? objectApi.get(id) : objectApi.getWithoutBody(id); if (null == swiftObject) { return null; } final byte[] content = withContent ? IOUtils.toByteArray(swiftObject.getPayload().openStream()) : new byte[0]; final String contentMd5 = computeMd5(content); final String swiftObjectMd5 = swiftObject.getPayload().getContentMetadata().getContentMD5AsHashCode().toString(); if (withContent && !contentMd5.equals(swiftObjectMd5)) { throw new SecurityException("MD5 of content differs from expected"); } return new MediaFile(id, null, swiftObject.getName(), null, contentMd5, null, null, content, null, swiftObject.getMetadata().get("content-type"), null, Integer.parseInt(swiftObject.getMetadata().get("size")) ); } SwiftMediaStorageClientImpl(SwiftConfiguration config); }
SwiftMediaStorageClientImpl implements MediaStorageClient { @Override public MediaFile retrieve (String id, Boolean withContent) throws IOException { final SwiftObject swiftObject = withContent ? objectApi.get(id) : objectApi.getWithoutBody(id); if (null == swiftObject) { return null; } final byte[] content = withContent ? IOUtils.toByteArray(swiftObject.getPayload().openStream()) : new byte[0]; final String contentMd5 = computeMd5(content); final String swiftObjectMd5 = swiftObject.getPayload().getContentMetadata().getContentMD5AsHashCode().toString(); if (withContent && !contentMd5.equals(swiftObjectMd5)) { throw new SecurityException("MD5 of content differs from expected"); } return new MediaFile(id, null, swiftObject.getName(), null, contentMd5, null, null, content, null, swiftObject.getMetadata().get("content-type"), null, Integer.parseInt(swiftObject.getMetadata().get("size")) ); } SwiftMediaStorageClientImpl(SwiftConfiguration config); @Override Boolean checkIfExists(String id); @Override MediaFile retrieve(String id, Boolean withContent); @Override void createOrModify(MediaFile mediaFile); @Override void delete(String id); }
SwiftMediaStorageClientImpl implements MediaStorageClient { @Override public MediaFile retrieve (String id, Boolean withContent) throws IOException { final SwiftObject swiftObject = withContent ? objectApi.get(id) : objectApi.getWithoutBody(id); if (null == swiftObject) { return null; } final byte[] content = withContent ? IOUtils.toByteArray(swiftObject.getPayload().openStream()) : new byte[0]; final String contentMd5 = computeMd5(content); final String swiftObjectMd5 = swiftObject.getPayload().getContentMetadata().getContentMD5AsHashCode().toString(); if (withContent && !contentMd5.equals(swiftObjectMd5)) { throw new SecurityException("MD5 of content differs from expected"); } return new MediaFile(id, null, swiftObject.getName(), null, contentMd5, null, null, content, null, swiftObject.getMetadata().get("content-type"), null, Integer.parseInt(swiftObject.getMetadata().get("size")) ); } SwiftMediaStorageClientImpl(SwiftConfiguration config); @Override Boolean checkIfExists(String id); @Override MediaFile retrieve(String id, Boolean withContent); @Override void createOrModify(MediaFile mediaFile); @Override void delete(String id);  }