FileStitcherImpl implements FileStitcher { @Override public Content getContentFromManifest(String spaceId, String contentId, FileStitcherListener listener) throws InvalidManifestException { log.debug("getContentFromManifest({}, {})", spaceId, contentId); if (!isManifest(contentId)) { log.error("Invalid manifest name: {}", contentId); throw new InvalidManifestException(spaceId, contentId); } Content manifestContent = this.dataSource.getContent(spaceId, contentId); ChunksManifest manifest = getManifest(manifestContent, spaceId, contentId); InputStream multiStream = getChunkSequenceStream(spaceId, manifest, listener); Content content = new Content(); content.setStream(multiStream); content.setId(manifest.getHeader().getSourceContentId()); Map<String, String> stitchedProps = getContentProperties(manifest); Map<String, String> manifestProps = manifestContent.getProperties(); if (manifestProps == null) { manifestProps = stitchedProps; } else { manifestProps.putAll(stitchedProps); } content.setProperties(manifestProps); return content; } FileStitcherImpl(DataSource dataSource); @Override Content getContentFromManifest(String spaceId, String contentId, FileStitcherListener listener); @Override ChunksManifest getManifest(String spaceId, String manifestId);  }
@Test public void testGetContentFromManifest() throws Exception { testGetContentFromManifest(null); }
@Test public void testGetContentFromManifestUnordered() throws Exception { createMocks(VALID_CHUNKS); replayMocks(); stitcher = new FileStitcherImpl(dataSource); Content content = stitcher.getContentFromManifest(spaceId, contentId); Assert.assertNotNull(content); InputStream contentStream = content.getStream(); Assert.assertNotNull(contentStream); OutputStream outputStream = new ByteArrayOutputStream(); IOUtils.copy(contentStream, outputStream); String fullContent = outputStream.toString(); contentStream.close(); outputStream.close(); String chunkText; for (int i = 0; i < NUM_CHUNKS; ++i) { chunkText = getChunkContent(i); Assert.assertTrue(fullContent.startsWith(chunkText)); fullContent = fullContent.substring(chunkText.length()); } Assert.assertEquals("All chunks should be found and pruned.", 0, fullContent.length()); }