List of usage examples for org.apache.commons.io IOUtils contentEquals
public static boolean contentEquals(Reader input1, Reader input2) throws IOException
From source file:org.hippoecm.frontend.plugins.gallery.imageutil.ScaleImageOperationTest.java
@Test public void compressionQualityHigherThanOne() throws GalleryException, IOException { InputStream data = getClass().getResourceAsStream("/test-380x428.jpg"); ScaleImageOperation normalOp = new ScaleImageOperation(200, 100, true, ImageUtils.ScalingStrategy.SPEED, 1f);/* w w w.ja v a 2 s. c o m*/ normalOp.execute(data, "image/jpeg"); data = getClass().getResourceAsStream("/test-380x428.jpg"); ScaleImageOperation compressedOp = new ScaleImageOperation(200, 100, true, ImageUtils.ScalingStrategy.SPEED, 100); compressedOp.execute(data, "image/jpeg"); assertTrue("Compression quality higher than 1 should be interpreted as 1", IOUtils.contentEquals(normalOp.getScaledData(), compressedOp.getScaledData())); }
From source file:org.hippoecm.frontend.plugins.gallery.imageutil.ScaleImageOperationTest.java
@Test public void compressionQualityLowerThanZero() throws GalleryException, IOException { InputStream data = getClass().getResourceAsStream("/test-380x428.jpg"); ScaleImageOperation normalOp = new ScaleImageOperation(200, 100, true, ImageUtils.ScalingStrategy.SPEED, 0); normalOp.execute(data, "image/jpeg"); data = getClass().getResourceAsStream("/test-380x428.jpg"); ScaleImageOperation compressedOp = new ScaleImageOperation(200, 100, true, ImageUtils.ScalingStrategy.SPEED, -42);/*from ww w . j av a 2s.c om*/ compressedOp.execute(data, "image/jpeg"); assertTrue("Compression quality lower than 0 should be interpreted as 0", IOUtils.contentEquals(normalOp.getScaledData(), compressedOp.getScaledData())); }
From source file:org.intermine.modelproduction.MetadataManager.java
private static void write(String string, File file) throws IOException { if (file.exists() && IOUtils.contentEquals(new FileReader(file), new StringReader(string))) { System.err.println(//from ww w .j a v a 2 s.c o m "Not writing \"" + file.getName() + "\" as version in database is identical to local copy"); return; } BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writer.write(string); writer.close(); }
From source file:org.intermine.task.RetrieveMetadataTask.java
/** * {@inheritDoc}/* www.j a v a2 s . c o m*/ */ @Override public void execute() { if (destDir == null) { throw new BuildException("destDir attribute is not set"); } if (osname == null) { throw new BuildException("osname attribute is not set"); } if (database == null) { throw new BuildException( "couldn't find database property: " + osname + ".db - " + "osName property is: " + osname); } try { Database db = DatabaseFactory.getDatabase(database); if (keyToRetrieve == null) { String modelXml = MetadataManager.retrieve(db, MetadataManager.MODEL); String keyDefs = MetadataManager.retrieve(db, MetadataManager.KEY_DEFINITIONS); // String classDescs = // MetadataManager.retrieve(db, MetadataManager.CLASS_DESCRIPTIONS); Model model = new InterMineModelParser().process(new StringReader(modelXml)); File localModel = new File(destDir, MetadataManager.getFilename(MetadataManager.MODEL, model.getName())); if (keyDefs != null) { MetadataManager.saveKeyDefinitions(keyDefs, destDir, model.getName()); } /*if (classKeys != null) { MetadataManager.saveClassKeys(classKeys, destDir); }*/ if (localModel.exists() && IOUtils.contentEquals(new FileReader(localModel), new StringReader(modelXml))) { System.err.println("Model in database is identical to local model."); return; } MetadataManager.saveModel(model, destDir); } else { String objectStoreSummary = MetadataManager.retrieve(db, MetadataManager.OS_SUMMARY); MetadataManager.saveProperties(objectStoreSummary, destDir, "objectstoresummary.properties"); } //MetadataManager.saveClassDescriptions(classDescs, destDir, model.getName()); } catch (Exception e) { System.err .println("Failed to retrieve metadata from " + database + " - maybe you need to run build-db?"); throw new BuildException(e); } }
From source file:org.lockss.test.LockssTestCase.java
public static void assertSameBytes(String message, InputStream expected, InputStream actual) throws IOException { if (!IOUtils.contentEquals(expected, actual)) { if (message == null) { fail();/*from w w w .j a va 2 s . co m*/ } else { fail(message); } } }
From source file:org.lockss.test.LockssTestCase.java
public static void assertSameCharacters(String message, Reader expected, Reader actual) throws IOException { if (!IOUtils.contentEquals(expected, actual)) { if (message == null) { fail();/*from w ww . j a v a2 s. c o m*/ } else { fail(message); } } }
From source file:org.mule.module.s3.automation.testcases.GetObjectContentTestCases.java
private void getObjectContentVerifications(Map<String, Object> testObjects) { try {/*w ww . ja va 2s .c o m*/ MessageProcessor createObjectFlow = lookupMessageProcessor("create-object-child-elements-from-message"); createObjectFlow.process(getTestEvent(testObjects)); MessageProcessor getObjectFlow = lookupMessageProcessor("get-object"); MuleEvent getObjectResponse = getObjectFlow.process(getTestEvent(testObjects)); S3Object s3object = (S3Object) getObjectResponse.getMessage().getPayload(); S3ObjectInputStream expectedObjectContent = s3object.getObjectContent(); MessageProcessor getObjectContentFlow = lookupMessageProcessor("get-object-content"); MuleEvent getObjectContentResponse = getObjectContentFlow.process(getTestEvent(testObjects)); S3ObjectInputStream actualObjectContent = (S3ObjectInputStream) getObjectContentResponse.getMessage() .getPayload(); assertTrue(IOUtils.contentEquals(expectedObjectContent, actualObjectContent)); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); fail(); } }
From source file:org.mule.modules.hdfs.automation.functional.AppendTestCases.java
@Test public void testAppend() throws Exception { Vector<InputStream> inputStreams = new Vector<InputStream>(); inputStreams.add(new ByteArrayInputStream(initialWrittenData)); byte[] inputStreamToAppend = TestDataBuilder.payloadForAppend(); inputStreams.add(new ByteArrayInputStream(inputStreamToAppend)); SequenceInputStream inputStreamsSequence = new SequenceInputStream(inputStreams.elements()); getConnector().append(MYFILE_PATH, 4096, new ByteArrayInputStream(inputStreamToAppend)); InputStream payload = getConnector().readOperation(MYFILE_PATH, 4096); Assert.assertThat(IOUtils.contentEquals(inputStreamsSequence, payload), is(true)); }
From source file:org.mule.modules.hdfs.automation.functional.CopyFromLocalFileTestCases.java
@Test public void testCopyFromLocalFile() throws Exception { Path localSource = Paths.get(LOCAL_SOURCE_PATH); Path remoteTarget = Paths.get(TARGET_DIRECTORY).resolve(localSource.getFileName()); getConnector().copyFromLocalFile(false, true, LOCAL_SOURCE_PATH, remoteTarget.toString()); InputStream targetDataStream = getConnector().readOperation(remoteTarget.toString(), 4096); InputStream sourceDataStream = Files.newInputStream(localSource); Assert.assertThat(IOUtils.contentEquals(targetDataStream, sourceDataStream), is(true)); }
From source file:org.mule.modules.hdfs.automation.functional.CopyToLocalFileTestCases.java
@Test public void testCopyToLocalFile() throws Exception { getConnector().copyToLocalFile(false, false, MYFILE_PATH, LOCAL_TAGET_PATH); Path localTarget = Paths.get(LOCAL_TAGET_PATH); InputStream targetDataStream = Files.newInputStream(localTarget); InputStream sourceDataStream = new ByteArrayInputStream(initialWrittenData); Assert.assertThat(IOUtils.contentEquals(targetDataStream, sourceDataStream), is(true)); }