Example usage for org.apache.commons.io FileUtils checksum

List of usage examples for org.apache.commons.io FileUtils checksum

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils checksum.

Prototype

public static Checksum checksum(File file, Checksum checksum) throws IOException 

Source Link

Document

Computes the checksum of a file using the specified checksum object.

Usage

From source file:com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest.java

@Test
public void testLegacyPasswordPlainTextIsplaintextNotSet() throws Exception {
    final File sourceConfigFile = new File("src/test/resources/psw_encryption/legacy_plain_notset.properties");
    final File configFile = File.createTempFile(
            "com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest", "test1");
    filesToDelete.add(configFile);//from   ww w .j a  v a 2s .  co m
    configFile.deleteOnExit();
    FileUtils.copyFile(sourceConfigFile, configFile);
    final ConfigurationFile cf = new ConfigurationFile(configFile.getAbsolutePath());
    final List<String> origLines = cf.getLines();

    List<String> updatedLines = null;
    if (cf.isInNeedOfUpdate()) {
        updatedLines = cf.saveWithEncryptedPasswords();
    }

    assertTrue(updatedLines.size() > 0);
    final Iterator<String> updatedLinesIter = updatedLines.iterator();
    for (final String origLine : origLines) {
        if (!updatedLinesIter.hasNext()) {
            fail("Updated file has fewer lines than original");
        }
        String updatedLine = updatedLinesIter.next();

        // make sure obsolete properties didn't sneak in somehow
        assertFalse(updatedLine.matches("^.*\\.password\\.isplaintext=.*$"));

        // If this is a password, verify that it was encoded, and that the
        // isencrypted=true was inserted after it
        if (origLine.startsWith("cc.password=")) {
            assertEquals(
                    "cc.password=,\\(f9b^6ck-Sr-A2!jWeRlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_P",
                    updatedLine);
            updatedLine = updatedLinesIter.next();
            assertEquals("cc.password.isencrypted=true", updatedLine);
        } else if (origLine.startsWith("protex.password=")) {
            assertEquals(
                    "protex.password=DQp'L-+/0Fq0jsi2f'\\\\OlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_P",
                    updatedLine);
            updatedLine = updatedLinesIter.next();
            assertEquals("protex.password.isencrypted=true", updatedLine);
        } else if (origLine.startsWith("connector.0.password=")) {
            assertEquals(
                    "connector.0.password=6'ND2^gdVX/0\\$fYH7TeH04Sh8FAG<\\[lI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_P",
                    updatedLine);
            updatedLine = updatedLinesIter.next();
            assertEquals("connector.0.password.isencrypted=true", updatedLine);
        } else {
            assertEquals(origLine, updatedLine);
        }
    }

    final File testGeneratedUpdatedFile = File.createTempFile(
            "com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest",
            "test1_testGeneratedUpdatedFile");
    filesToDelete.add(testGeneratedUpdatedFile);
    testGeneratedUpdatedFile.deleteOnExit();
    FileUtils.writeLines(testGeneratedUpdatedFile, updatedLines);
    final long csumTestGeneratedFile = FileUtils.checksum(testGeneratedUpdatedFile, new CRC32()).getValue();
    final long csumActualFile = FileUtils.checksum(configFile, new CRC32()).getValue();
    assertEquals(csumTestGeneratedFile, csumActualFile);
}

From source file:com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest.java

/**
 * Test handling of legacy Passwords in plain text with
 * password.isplaintext=true Does not verify that non-password-related lines
 * survive as-is, but testLegacyPasswordPlainTextIsplaintextNotSet() does
 * that.//from  w ww .  j a  va2 s .c om
 *
 * @throws Exception
 */
@Test
public void testLegacyPasswordPlainTextIsplaintextTrue() throws Exception {
    final File sourceConfigFile = new File("src/test/resources/psw_encryption/legacy_plain_set.properties");
    final File configFile = File.createTempFile(
            "com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest", "test2");
    filesToDelete.add(configFile);
    configFile.deleteOnExit();
    FileUtils.copyFile(sourceConfigFile, configFile);
    final ConfigurationFile cf = new ConfigurationFile(configFile.getAbsolutePath());

    List<String> updatedLines = null;
    if (cf.isInNeedOfUpdate()) {
        updatedLines = cf.saveWithEncryptedPasswords();
    }

    assertTrue(updatedLines.size() > 0);
    final Iterator<String> updatedLinesIter = updatedLines.iterator();
    while (updatedLinesIter.hasNext()) {
        String updatedLine = updatedLinesIter.next();

        // make sure obsolete properties have been removed
        assertFalse(updatedLine.matches("^.*\\.password\\.isplaintext=.*$"));

        // If this is a password, verify that it was encoded, and that the
        // isencrypted=true was inserted after it
        if (updatedLine.startsWith("cc.password=")) {
            assertEquals("cc.password=cc_password", updatedLine);
            updatedLine = updatedLinesIter.next();
            assertEquals("cc.password.isencrypted=false", updatedLine);
        } else if (updatedLine.startsWith("protex.password=")) {
            assertEquals("protex.password=protex_password", updatedLine);
            updatedLine = updatedLinesIter.next();
            assertEquals("protex.password.isencrypted=false", updatedLine);
        } else if (updatedLine.startsWith("connector.0.password=")) {
            assertEquals("connector.0.password=connector_password", updatedLine);
            updatedLine = updatedLinesIter.next();
            assertEquals("connector.0.password.isencrypted=false", updatedLine);
        }
    }

    final File testGeneratedUpdatedFile = File.createTempFile(
            "com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest",
            "test2_testGeneratedUpdatedFile");
    filesToDelete.add(testGeneratedUpdatedFile);
    testGeneratedUpdatedFile.deleteOnExit();
    FileUtils.writeLines(testGeneratedUpdatedFile, updatedLines);
    final long csumTestGeneratedFile = FileUtils.checksum(testGeneratedUpdatedFile, new CRC32()).getValue();
    final long csumActualFile = FileUtils.checksum(configFile, new CRC32()).getValue();
    assertEquals(csumTestGeneratedFile, csumActualFile);
}

From source file:com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest.java

/**
 * We don't handle this scenario/*w  w w. ja  va2s . co  m*/
 *
 * @throws Exception
 */
@Test
public void testLegacyPasswordBase64IsplaintextNotSet() throws Exception {
    final File sourceConfigFile = new File("src/test/resources/psw_encryption/legacy_base64_notset.properties");
    final File configFile = File.createTempFile(
            "com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest", "test3");
    filesToDelete.add(configFile);
    configFile.deleteOnExit();
    FileUtils.copyFile(sourceConfigFile, configFile);
    final ConfigurationFile cf = new ConfigurationFile(configFile.getAbsolutePath());

    List<String> updatedLines = null;
    if (cf.isInNeedOfUpdate()) {
        updatedLines = cf.saveWithEncryptedPasswords();
    }

    // This warning has been disabled to avoid calling isBase64, which
    // causes problems for RGT
    // System.out.println("There should be 3 warnings in the log about possibly-base64-encoded passwords");

    assertTrue(updatedLines.size() > 0);
    final Iterator<String> updatedLinesIter = updatedLines.iterator();
    while (updatedLinesIter.hasNext()) {
        String updatedLine = updatedLinesIter.next();

        // make sure obsolete properties have been removed
        assertFalse(updatedLine.matches("^.*\\.password\\.isplaintext=.*$"));

        // If this is a password, verify that it was encoded, and that the
        // isencrypted=true was inserted after it
        if (updatedLine.startsWith("cc.password=")) {
            // There's not much point in checking the value of password,
            // since it is wrong
            updatedLine = updatedLinesIter.next();
            assertEquals("cc.password.isencrypted=true", updatedLine);
        } else if (updatedLine.startsWith("protex.password=")) {
            // There's not much point in checking the value of password,
            // since it is wrong
            updatedLine = updatedLinesIter.next();
            assertEquals("protex.password.isencrypted=true", updatedLine);
        } else if (updatedLine.startsWith("connector.0.password=")) {
            // There's not much point in checking the value of password,
            // since it is wrong
            updatedLine = updatedLinesIter.next();
            assertEquals("connector.0.password.isencrypted=true", updatedLine);
        }
    }

    final File testGeneratedUpdatedFile = File.createTempFile(
            "com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest",
            "test3_testGeneratedUpdatedFile");
    filesToDelete.add(testGeneratedUpdatedFile);
    testGeneratedUpdatedFile.deleteOnExit();
    FileUtils.writeLines(testGeneratedUpdatedFile, updatedLines);
    final long csumTestGeneratedFile = FileUtils.checksum(testGeneratedUpdatedFile, new CRC32()).getValue();
    final long csumActualFile = FileUtils.checksum(configFile, new CRC32()).getValue();
    assertEquals(csumTestGeneratedFile, csumActualFile);
}

From source file:com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest.java

@Test
public void testLegacyPasswordBase64IsplaintextFalse() throws Exception {
    final File sourceConfigFile = new File("src/test/resources/psw_encryption/legacy_base64_set.properties");
    final File configFile = File.createTempFile(
            "com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest", "test4");
    filesToDelete.add(configFile);/* w w w. j av  a 2  s.  c  o  m*/
    configFile.deleteOnExit();
    FileUtils.copyFile(sourceConfigFile, configFile);
    final ConfigurationFile cf = new ConfigurationFile(configFile.getAbsolutePath());

    List<String> updatedLines = null;
    if (cf.isInNeedOfUpdate()) {
        updatedLines = cf.saveWithEncryptedPasswords();
    }

    assertTrue(updatedLines.size() > 0);
    final Iterator<String> updatedLinesIter = updatedLines.iterator();
    while (updatedLinesIter.hasNext()) {
        String updatedLine = updatedLinesIter.next();

        // make sure obsolete properties didn't sneak in somehow
        assertFalse(updatedLine.matches("^.*\\.password\\.isplaintext=.*$"));

        // If this is a password, verify that it was encoded, and that the
        // isencrypted=true was inserted after it
        if (updatedLine.startsWith("cc.password=")) {
            assertEquals(
                    "cc.password=,\\(f9b^6ck-Sr-A2!jWeRlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_P",
                    updatedLine);
            updatedLine = updatedLinesIter.next();
            assertEquals("cc.password.isencrypted=true", updatedLine);
        } else if (updatedLine.startsWith("protex.password=")) {
            assertEquals(
                    "protex.password=DQp'L-+/0Fq0jsi2f'\\\\OlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_P",
                    updatedLine);
            updatedLine = updatedLinesIter.next();
            assertEquals("protex.password.isencrypted=true", updatedLine);
        } else if (updatedLine.startsWith("connector.0.password=")) {
            assertEquals(
                    "connector.0.password=6'ND2^gdVX/0\\$fYH7TeH04Sh8FAG<\\[lI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_P",
                    updatedLine);
            updatedLine = updatedLinesIter.next();
            assertEquals("connector.0.password.isencrypted=true", updatedLine);
        }
    }

    final File testGeneratedUpdatedFile = File.createTempFile(
            "com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest",
            "test4_testGeneratedUpdatedFile");
    filesToDelete.add(testGeneratedUpdatedFile);
    testGeneratedUpdatedFile.deleteOnExit();
    FileUtils.writeLines(testGeneratedUpdatedFile, updatedLines);
    final long csumTestGeneratedFile = FileUtils.checksum(testGeneratedUpdatedFile, new CRC32()).getValue();
    final long csumActualFile = FileUtils.checksum(configFile, new CRC32()).getValue();
    assertEquals(csumTestGeneratedFile, csumActualFile);
}

From source file:com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest.java

@Test
public void testModernPasswordPlainTextIsEncryptedNotSet() throws Exception {
    final File sourceConfigFile = new File("src/test/resources/psw_encryption/modern_plain_notset.properties");
    final File configFile = File.createTempFile(
            "com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest", "test5");
    filesToDelete.add(configFile);/*from w w  w  .ja v  a 2 s . c  o  m*/
    configFile.deleteOnExit();
    FileUtils.copyFile(sourceConfigFile, configFile);
    final ConfigurationFile cf = new ConfigurationFile(configFile.getAbsolutePath());

    List<String> updatedLines = null;
    if (cf.isInNeedOfUpdate()) {
        updatedLines = cf.saveWithEncryptedPasswords();
    }

    assertTrue(updatedLines.size() > 0);
    final Iterator<String> updatedLinesIter = updatedLines.iterator();
    while (updatedLinesIter.hasNext()) {
        String updatedLine = updatedLinesIter.next();

        // make sure obsolete properties didn't sneak in somehow
        assertFalse(updatedLine.matches("^.*\\.password\\.isplaintext=.*$"));

        // If this is a password, verify that it was encoded, and that the
        // isencrypted=true was inserted after it
        if (updatedLine.startsWith("cc.password=")) {
            assertEquals(
                    "cc.password=,\\(f9b^6ck-Sr-A2!jWeRlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_P",
                    updatedLine);
            updatedLine = updatedLinesIter.next();
            assertEquals("cc.password.isencrypted=true", updatedLine);
        } else if (updatedLine.startsWith("protex.password=")) {
            assertEquals(
                    "protex.password=DQp'L-+/0Fq0jsi2f'\\\\OlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_P",
                    updatedLine);
            updatedLine = updatedLinesIter.next();
            assertEquals("protex.password.isencrypted=true", updatedLine);
        } else if (updatedLine.startsWith("connector.0.password=")) {
            assertEquals(
                    "connector.0.password=6'ND2^gdVX/0\\$fYH7TeH04Sh8FAG<\\[lI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_PlI'nKT:u_P",
                    updatedLine);
            updatedLine = updatedLinesIter.next();
            assertEquals("connector.0.password.isencrypted=true", updatedLine);
        }
    }

    final File testGeneratedUpdatedFile = File.createTempFile(
            "com.blackducksoftware.tools.commonframework.core.config.ConfigurationFileTest",
            "test5_testGeneratedUpdatedFile");
    filesToDelete.add(testGeneratedUpdatedFile);
    testGeneratedUpdatedFile.deleteOnExit();
    FileUtils.writeLines(testGeneratedUpdatedFile, updatedLines);
    final long csumTestGeneratedFile = FileUtils.checksum(testGeneratedUpdatedFile, new CRC32()).getValue();
    final long csumActualFile = FileUtils.checksum(configFile, new CRC32()).getValue();
    assertEquals(csumTestGeneratedFile, csumActualFile);
}

From source file:org.discosync.scanner.FileCheckSyncInfoScanner.java

protected void handleFile(File file, int depth, Collection results) {

    // Note: here we could make processing faster when the current process is a compare
    //   of a syncinfo with a baseDir - avoid to compute the checksum in this case when 
    //   the size is different

    long checksum = -1;

    adlerChecksum.reset();//from  w w w.j a v a 2  s . c o  m

    try {
        checksum = FileUtils.checksum(file, adlerChecksum).getValue();
    } catch (IOException e) {
        e.printStackTrace();
    }

    long size = file.length();

    // remove baseDir part
    String relativeName = file.getAbsolutePath().substring(baseDirLength);

    FileListEntry e = new FileListEntry(relativeName, checksum, size);

    Utils.doFileListEntryCompare(e, dstFileMap, fileOperations);
}

From source file:org.discosync.scanner.FileCreateSyncInfoScanner.java

@Override
protected void handleFile(File file, int depth, Collection results) {

    long checksum = -1;

    adlerChecksum.reset();//from  w w w. j a  v  a 2s .  c o  m

    try {
        checksum = FileUtils.checksum(file, adlerChecksum).getValue();
    } catch (IOException e) {
        e.printStackTrace();
    }

    long size = file.length();

    // remove baseDir part
    String relativeName = file.getAbsolutePath().substring(baseDirLength);

    try {
        database.insertFile(relativeName, checksum, size);
        entryCount++;
        byteCount += size;
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

From source file:org.gradle.util.GFileUtils.java

public static Checksum checksum(File file, Checksum checksum) {
    try {/*from   w  w w.  j  a v  a 2 s.  co  m*/
        return FileUtils.checksum(file, checksum);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:org.olat.core.util.mail.manager.MailManagerImpl.java

protected DBMail saveDBMessage(MailContext context, Identity fromId, String from, Identity toId, String to,
        Identity cc, List<ContactList> bccLists, String metaId, MailContent content, MailerResult result) {

    try {/* ww  w .  ja v  a  2 s  . c  o m*/
        DBMailImpl mail = new DBMailImpl();
        if (result == null) {
            result = new MailerResult();
        }

        boolean makeRealMail = makeRealMail(toId, cc, bccLists);
        Address fromAddress = null;
        List<Address> toAddress = new ArrayList<Address>();
        List<Address> ccAddress = new ArrayList<Address>();
        List<Address> bccAddress = new ArrayList<Address>();

        if (fromId != null) {
            DBMailRecipient fromRecipient = new DBMailRecipient();
            fromRecipient.setRecipient(fromId);
            if (StringHelper.containsNonWhitespace(from)) {
                fromRecipient.setEmailAddress(from);
                fromAddress = createFromAddress(from, result);
            } else {
                fromAddress = createFromAddress(fromId, result);
            }
            fromRecipient.setVisible(Boolean.TRUE);
            fromRecipient.setMarked(Boolean.FALSE);
            fromRecipient.setDeleted(Boolean.FALSE);
            mail.setFrom(fromRecipient);
        } else {
            if (!StringHelper.containsNonWhitespace(from)) {
                from = WebappHelper.getMailConfig("mailFrom");
            }
            DBMailRecipient fromRecipient = new DBMailRecipient();
            fromRecipient.setEmailAddress(from);
            fromRecipient.setVisible(Boolean.TRUE);
            fromRecipient.setMarked(Boolean.FALSE);
            fromRecipient.setDeleted(Boolean.TRUE);//marked as delted as nobody can read it
            mail.setFrom(fromRecipient);
            fromAddress = createFromAddress(from, result);
        }

        if (result.getReturnCode() != MailerResult.OK) {
            return null;
        }

        mail.setMetaId(metaId);
        String subject = content.getSubject();
        if (subject != null && subject.length() > 500) {
            logWarn("Cut a too long subkect in name. Size: " + subject.length(), null);
            subject = subject.substring(0, 500);
        }
        mail.setSubject(subject);
        String body = content.getBody();
        if (body != null && body.length() > 16777210) {
            logWarn("Cut a too long body in mail. Size: " + body.length(), null);
            body = body.substring(0, 16000000);
        }
        mail.setBody(body);
        mail.setLastModified(new Date());

        if (context != null) {
            OLATResourceable ores = context.getOLATResourceable();
            if (ores != null) {
                String resName = ores.getResourceableTypeName();
                if (resName != null && resName.length() > 50) {
                    logWarn("Cut a too long resourceable type name in mail context: " + resName, null);
                    resName = resName.substring(0, 49);
                }
                mail.getContext().setResName(ores.getResourceableTypeName());
                mail.getContext().setResId(ores.getResourceableId());
            }

            String resSubPath = context.getResSubPath();
            if (resSubPath != null && resSubPath.length() > 2000) {
                logWarn("Cut a too long resSubPath in mail context: " + resSubPath, null);
                resSubPath = resSubPath.substring(0, 2000);
            }
            mail.getContext().setResSubPath(resSubPath);

            String businessPath = context.getBusinessPath();
            if (businessPath != null && businessPath.length() > 2000) {
                logWarn("Cut a too long resSubPath in mail context: " + businessPath, null);
                businessPath = businessPath.substring(0, 2000);
            }
            mail.getContext().setBusinessPath(businessPath);
        }

        //add to
        DBMailRecipient recipientTo = null;
        if (toId != null) {
            recipientTo = new DBMailRecipient();
            if (toId instanceof PersistentObject) {
                recipientTo.setRecipient(toId);
            } else {
                to = toId.getUser().getProperty(UserConstants.EMAIL, null);
            }
            if (StringHelper.containsNonWhitespace(to)) {
                recipientTo.setEmailAddress(to);
            }
            recipientTo.setVisible(Boolean.TRUE);
            recipientTo.setDeleted(Boolean.FALSE);
            recipientTo.setMarked(Boolean.FALSE);
            recipientTo.setRead(Boolean.FALSE);
        } else if (StringHelper.containsNonWhitespace(to)) {
            recipientTo = new DBMailRecipient();
            recipientTo.setEmailAddress(to);
            recipientTo.setVisible(Boolean.TRUE);
            recipientTo.setDeleted(Boolean.TRUE);
            recipientTo.setMarked(Boolean.FALSE);
            recipientTo.setRead(Boolean.FALSE);
        }

        if (recipientTo != null) {
            mail.getRecipients().add(recipientTo);
            createAddress(toAddress, recipientTo, true, result, true);
        }
        if (makeRealMail && StringHelper.containsNonWhitespace(to)) {
            createAddress(toAddress, to);
        }

        if (cc != null) {
            DBMailRecipient recipient = new DBMailRecipient();
            if (cc instanceof PersistentObject) {
                recipient.setRecipient(cc);
            } else {
                recipient.setEmailAddress(cc.getUser().getProperty(UserConstants.EMAIL, null));
            }
            recipient.setVisible(Boolean.TRUE);
            recipient.setDeleted(Boolean.FALSE);
            recipient.setMarked(Boolean.FALSE);
            recipient.setRead(Boolean.FALSE);
            mail.getRecipients().add(recipient);
            createAddress(ccAddress, recipient, false, result, true);
        }

        //add bcc recipients
        appendRecipients(mail, bccLists, toAddress, bccAddress, false, makeRealMail, result);

        dbInstance.getCurrentEntityManager().persist(mail);

        //save attachments
        List<File> attachments = content.getAttachments();
        if (attachments != null && !attachments.isEmpty()) {
            for (File attachment : attachments) {

                FileInputStream in = null;
                try {
                    DBMailAttachment data = new DBMailAttachment();
                    data.setSize(attachment.length());
                    data.setName(attachment.getName());

                    long checksum = FileUtils.checksum(attachment, new Adler32()).getValue();
                    data.setChecksum(new Long(checksum));
                    data.setMimetype(WebappHelper.getMimeType(attachment.getName()));

                    in = new FileInputStream(attachment);
                    String path = saveAttachmentToStorage(data.getName(), data.getMimetype(), checksum,
                            attachment.length(), in);
                    data.setPath(path);
                    data.setMail(mail);

                    dbInstance.getCurrentEntityManager().persist(data);
                } catch (FileNotFoundException e) {
                    logError("File attachment not found: " + attachment, e);
                } catch (IOException e) {
                    logError("Error with file attachment: " + attachment, e);
                } finally {
                    IOUtils.closeQuietly(in);
                }
            }
        }

        if (makeRealMail) {
            //check that we send an email to someone
            if (!toAddress.isEmpty() || !ccAddress.isEmpty() || !bccAddress.isEmpty()) {
                sendRealMessage(fromAddress, toAddress, ccAddress, bccAddress, subject, body, attachments,
                        result);
            }
        }

        //update subscription
        for (DBMailRecipient recipient : mail.getRecipients()) {
            if (recipient.getRecipient() != null) {
                subscribe(recipient.getRecipient());
            }
        }

        SubscriptionContext subContext = getSubscriptionContext();
        notificationsManager.markPublisherNews(subContext, null, false);
        return mail;
    } catch (AddressException e) {
        logError("Cannot send e-mail: ", e);
        result.setReturnCode(MailerResult.RECIPIENT_ADDRESS_ERROR);
        return null;
    }
}

From source file:org.olat.core.util.vfs.version.VersionsFileManager.java

private boolean isSameFile(VFSLeaf currentFile, VersionsFileImpl versions) {
    boolean same = false;
    if (versions.getRevisions() != null && !versions.getRevisions().isEmpty()) {
        VFSRevision lastRevision = versions.getRevisions().get(versions.getRevisions().size() - 1);

        long lastSize = lastRevision.getSize();
        long currentSize = currentFile.getSize();
        if (currentSize == lastSize && currentSize > 0 && lastRevision instanceof RevisionFileImpl
                && currentFile instanceof LocalFileImpl) {
            RevisionFileImpl lastRev = ((RevisionFileImpl) lastRevision);
            LocalFileImpl current = (LocalFileImpl) currentFile;
            //can be the same file
            try {
                Checksum cm1 = FileUtils.checksum(((LocalFileImpl) lastRev.getFile()).getBasefile(),
                        new Adler32());
                Checksum cm2 = FileUtils.checksum(current.getBasefile(), new Adler32());
                same = cm1.getValue() == cm2.getValue();
            } catch (IOException e) {
                log.debug("Error calculating the checksum of files");
            }/*  ww w. ja  v a  2 s. c  o  m*/
        }
    }
    return same;
}