List of usage examples for org.apache.commons.io IOUtils contentEquals
public static boolean contentEquals(Reader input1, Reader input2) throws IOException
From source file:com.google.mr4c.dataset.DataFile.java
private static boolean compareContent(DataFile file1, DataFile file2) throws IOException { if (file1.hasContent() != file2.hasContent()) { return false; } else if (!file1.hasContent()) { return true; // neither has content } else {/*from ww w . j a va2 s .c o m*/ return IOUtils.contentEquals(file1.getInputStream(), file2.getInputStream()); } }
From source file:de.brendamour.jpasskit.signing.PKPassTemplateInMemoryTest.java
@Test public void addFile_asFile() throws IOException { URL iconFileURL = PKPassTemplateInMemoryTest.class.getClassLoader() .getResource("StoreCard.raw/icon@2x.png"); File iconFile = new File(iconFileURL.getFile()); pkPassTemplateInMemory.addFile(PKPassTemplateInMemory.PK_ICON_RETINA, iconFile); Map<String, InputStream> files = pkPassTemplateInMemory.getFiles(); Assert.assertEquals(files.size(), 1); Assert.assertTrue(IOUtils.contentEquals(new FileInputStream(iconFile), files.get(PKPassTemplateInMemory.PK_ICON_RETINA))); }
From source file:com.spartasystems.holdmail.mime.MimeBodyPartsExtractorTest.java
@Test public void shouldHandleBody() throws Exception { InputStream inputStreamMock = new ByteArrayInputStream("hello".getBytes()); MimeBodyPartsExtractor extractor = new MimeBodyPartsExtractor(); extractor.startHeader(); // initialize a 'nextPotentialPart' extractor.body(null, inputStreamMock); MimeBodyPart nextPart = extractor.getNextPotentialPart(); assertThat(IOUtils.contentEquals(nextPart.getContentStream(), inputStreamMock)); MimeBodyParts expectedParts = new MimeBodyParts(); expectedParts.addBodyPart(nextPart); assertThat(extractor.getParts()).isEqualTo(expectedParts); }
From source file:com.xpn.xwiki.doc.XWikiAttachmentTest.java
@Test public void testSetContentViaOutputStream() throws Exception { int attachLength = 20; int seed = (int) System.currentTimeMillis(); final XWikiAttachment attach = new XWikiAttachment(); final InputStream ris = new RandomInputStream(attachLength, seed); attach.setContent(ris);/*from w ww . j ava 2s. c o m*/ Assert.assertTrue(IOUtils.contentEquals(new RandomInputStream(attachLength, seed), attach.getAttachment_content().getContentInputStream())); // Now write to the attachment via an OutputStream. final XWikiAttachmentContent xac = attach.getAttachment_content(); xac.setContentDirty(false); final OutputStream os = xac.getContentOutputStream(); // Adding content with seed+1 will make a radically different set of content. IOUtils.copy(new RandomInputStream(attachLength, seed + 1), os); // It should still be the old content. Assert.assertTrue( IOUtils.contentEquals(new RandomInputStream(attachLength, seed), xac.getContentInputStream())); Assert.assertFalse(xac.isContentDirty()); os.close(); // Now it should be the new content. Assert.assertTrue( IOUtils.contentEquals(new RandomInputStream(attachLength, seed + 1), xac.getContentInputStream())); Assert.assertTrue(xac.isContentDirty()); }
From source file:com.cloudant.sync.datastore.AttachmentStreamFactoryTest.java
@Test /**//from w w w .ja va 2s. c o m * Assert passing an AttachmentStreamFactory with no key reads an unencrypted file correctly. */ public void testSavedAttachmentReadsUnencryptedUnencodedStream() throws AttachmentException, IOException { AttachmentStreamFactory asf = new AttachmentStreamFactory(new NullKeyProvider()); File plainText = f("fixture/EncryptedAttachmentTest_plainText"); SavedAttachment savedAttachment = new SavedAttachment(0, "test", null, "text/plain", Attachment.Encoding.Plain, 0, 0, 0, plainText, asf); Assert.assertTrue("Reading unencrypted, un-encoded stream didn't give correct output", IOUtils.contentEquals(savedAttachment.getInputStream(), new FileInputStream(plainText))); }
From source file:com.adobe.acs.commons.httpcache.store.jcr.impl.writer.EntryNodeWriterTest.java
@Test public void testValid() throws IOException, RepositoryException { final EntryNodeWriterMocks.MockArguments arguments = new EntryNodeWriterMocks.MockArguments(); arguments.cacheContentCharEncoding = "UTF-8"; arguments.cacheContentType = "text/html"; arguments.entryNode = mock(Node.class); InputStream inputStream = getClass().getClassLoader().getResourceAsStream(CACHE_CONTENT_LOCATION); arguments.cacheContent = inputStream; List<String> header1Value = Arrays.asList("header-value"); List<String> header2Value = Arrays.asList("another-header-value"); arguments.cacheContentHeaders.put("some-header", header1Value); arguments.cacheContentHeaders.put("another-header", header2Value); final EntryNodeWriterMocks mocks = new EntryNodeWriterMocks(arguments); mocks.getEntryNodeWriter().write();//from w w w. j a v a 2 s .c o m verify(mocks.getEntryNode(), times(1)) .setProperty(Matchers.startsWith(JCRHttpCacheStoreConstants.PN_CACHEKEY), any(Binary.class)); ArgumentCaptor<Binary> argumentCaptor = ArgumentCaptor.forClass(Binary.class); verify(mocks.getJcrContentNode(), times(1)).setProperty(Matchers.startsWith(JcrConstants.JCR_DATA), argumentCaptor.capture()); Binary savedBinary = argumentCaptor.getValue(); IOUtils.contentEquals(inputStream, savedBinary.getStream()); verify(mocks.getJcrContentNode(), times(1)).setProperty(JcrConstants.JCR_MIMETYPE, arguments.cacheContentType); //verify(mocks.getHeadersNode().setProperty("some-header", header1Value)) }
From source file:com.spartasystems.holdmail.mime.MessageContentExtractorTest.java
@Test public void shouldHandleBody() throws Exception { InputStream inputStreamMock = new ByteArrayInputStream("hello".getBytes()); MessageContentExtractor extractor = new MessageContentExtractor(); extractor.startHeader(); // initialize a 'nextPotentialPart' extractor.body(null, inputStreamMock); MessageContentPart nextPart = extractor.getNextPotentialPart(); assertThat(IOUtils.contentEquals(nextPart.getContentStream(), inputStreamMock)); MessageContent expectedParts = new MessageContent(); expectedParts.addPart(nextPart);/*ww w .ja v a 2 s . c om*/ assertThat(extractor.getParts()).isEqualTo(expectedParts); }
From source file:com.technofovea.packbsp.crawling.AssetAlternative.java
/** * Taking an array of alternative items, tests if there is a * @param items//from w ww .j ava 2 s . c o m * @return * @throws IOException */ public static CollisionType hasCustomCollision(List<AssetAlternative> items) throws IOException { //TODO same-hash in BSP+Archive is a bad idea since it means the map is not forward-compatible. Fix in future if (items.size() < 2) { // Nothing to even check against return CollisionType.NONE; } // Test if our first-level item collides with the first ARCHIVE-type things below it AssetAlternative topLevelItem = items.get(0); AssetAlternative archivedItem = null; for (int i = 1; i < items.size(); i++) { AssetAlternative next = items.get(i); if (next.getType().equals(Type.ARCHIVE)) { archivedItem = next; break; } } if (archivedItem == null) { // No secondary item was found that was an archive-type // Nothing relevant to collide with return CollisionType.NONE; } // Basic size check File diskFile = topLevelItem.getFile(); File archiveFile = archivedItem.getFile(); boolean sameSize = (diskFile.length() == archiveFile.length()); boolean sameData = false; if (sameSize) { // Tougher check involving actual contents FileInputStream diskStream = new FileInputStream(diskFile); FileInputStream archiveStream = new FileInputStream(archiveFile); sameData = IOUtils.contentEquals(diskStream, archiveStream); diskStream.close(); archiveStream.close(); } if (sameData) { return CollisionType.DUPLICATE; } else { return CollisionType.CONFLICTING; } }
From source file:de.cosmocode.palava.store.AbstractStoreTest.java
/** * Tests {@link Store#create(InputStream)}. * //from ww w . j a v a 2 s. co m * @throws IOException should not happen */ @Test public void create() throws IOException { final Store unit = unit(); final InputStream stream = getClass().getClassLoader().getResourceAsStream("willi.png"); Assert.assertNotNull(stream); final String identifier = unit.create(stream); stream.close(); Assert.assertTrue(IOUtils.contentEquals(getClass().getClassLoader().getResourceAsStream("willi.png"), unit.read(identifier))); }
From source file:de.brendamour.jpasskit.signing.PKPassTemplateInMemoryTest.java
@Test public void addFile_asFile_withLocale() throws IOException { URL iconFileURL = PKPassTemplateInMemoryTest.class.getClassLoader() .getResource("StoreCard.raw/icon@2x.png"); File iconFile = new File(iconFileURL.getFile()); pkPassTemplateInMemory.addFile(PKPassTemplateInMemory.PK_ICON_RETINA, Locale.ENGLISH, iconFile); Map<String, InputStream> files = pkPassTemplateInMemory.getFiles(); Assert.assertEquals(files.size(), 1); Assert.assertTrue(IOUtils.contentEquals(new FileInputStream(iconFile), files.get("en.lproj/" + PKPassTemplateInMemory.PK_ICON_RETINA))); }