mdfingerprintconfig.java
来自「dump3 morpheus 0.2.9 src」· Java 代码 · 共 195 行
JAVA
195 行
/**
* DuMP3 version morpheus_0.2.9 - a duplicate/similar file finder in Java<BR>
* Copyright 2005 Alexander Grässer<BR>
* All Rights Reserved, http://dump3.sourceforge.net/<BR>
* <BR>
* This file is part of DuMP3.<BR>
* <BR>
* DuMP3 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later version.<BR>
* <BR>
* DuMP3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.<BR>
* <BR>
* You should have received a copy of the GNU General Public License along with DuMP3; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
* Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.za.grasser.duplicate.fingerprint.configure;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyVetoException;
import java.security.NoSuchAlgorithmException;
import jonelo.jacksum.JacksumAPI;
import jonelo.jacksum.algorithm.AbstractChecksum;
import net.za.grasser.duplicate.Configure;
import net.za.grasser.duplicate.fingerprint.MDFingerprint;
import org.apache.log4j.Logger;
/**
* @author <a href="http://sourceforge.net/sendmessage.php?touser=733840">pyropunk at sourceforge dot net</a>
* @version $Revision: 1.9 $
*/
public class MDFingerprintConfig extends FingerprintConfig {
/**
* <code>MSG_DIGEST</code> MDFingerprintConfig.java -
*/
public static final String MSG_DIGEST = "messageDigest";
/**
* <code>serialVersionUID</code> MDFingerprintConfig.java -
*/
private static final long serialVersionUID = 7761582108930147227L;
/**
* <code>log</code> MDFingerprintConfig -
*/
private static final Logger log = Logger.getLogger(MDFingerprintConfig.class);
/**
* <code>fc</code> MDFingerprintConfig -
*/
private static FingerprintConfig fc = null;
/**
* <code>messageDigest</code> MDFingerprint - message digest name
*/
protected String messageDigest = "sha1";
/**
* This class ...
*
* @author <a href="http://sourceforge.net/sendmessage.php?touser=733840">pyropunk at sourceforge dot net</a>
* @version $Revision: 1.9 $
*/
static class Factory extends ConfigFactory {
/**
* @see net.za.grasser.duplicate.fingerprint.configure.ConfigFactory#create()
*/
@Override
protected FingerprintConfig create() {
return MDFingerprintConfig.getInstance();
}
}
static {
ConfigFactory.addFactory(MDFingerprintConfig.class.getSimpleName(), new Factory());
}
/**
*
*/
private MDFingerprintConfig() {
super();
Configure.load();
// get checksum algorithm from config
try {
setMessageDigest(Configure.getProperty("checksum", "sha1", MDFingerprint.class.getName()));
} catch (final PropertyVetoException e) {
log.warn("Could not set message digest.", e);
}
}
/**
* @return FingerprintConfig
*/
public final static FingerprintConfig getInstance() {
if (fc == null) {
fc = new MDFingerprintConfig();
}
return fc;
}
/**
* Sets the similarityThreshhold to the value of pSimilarityThreshhold.
*
* @param pSimilarityThreshhold float - The new value.
* @throws PropertyVetoException
*/
@Override
public void setSimilarityThreshhold(final float pSimilarityThreshhold) throws PropertyVetoException {
final float oldSimilarityThreshhold = similarityThreshhold;
// First tell the vetoers about the change.
// If anyone objects, we don't catch the exception
// but just let if pass on to our caller.
vetos.fireVetoableChange(SIM_THRESH, new Float(oldSimilarityThreshhold), new Float(pSimilarityThreshhold));
// No-one vetoed, so go ahead and make the change.
similarityThreshhold = pSimilarityThreshhold;
changes.firePropertyChange(SIM_THRESH, new Float(oldSimilarityThreshhold), new Float(pSimilarityThreshhold));
}
/**
* @return String - Returns vcurrently selected message digest.
*/
public final String getMessageDigest() {
return messageDigest;
}
/**
* @return String[] - Returns the list of available message digests.
*/
public static final String[] getMessageDigests() {
final Object[] objs = JacksumAPI.getAvailableAlgorithms().keySet().toArray();
// have to copy - casting the whole array does not work.
final String[] ret = new String[objs.length];
for (int i = 0, len = objs.length; i < len; i++) {
ret[i] = objs[i].toString();
}
return ret;
}
/**
* @param pMd
* @throws PropertyVetoException
*/
public void setMessageDigest(final String pMd) throws PropertyVetoException {
final String oldMD = messageDigest;
vetos.fireVetoableChange(MSG_DIGEST, oldMD, pMd);
messageDigest = pMd;
changes.firePropertyChange(MSG_DIGEST, oldMD, pMd);
}
/**
* checks whether the selected MD is a valid checksum algorithm
*
* @param newValue
* @return AbstractChecksum
* @throws NoSuchAlgorithmException
*/
private AbstractChecksum checkChecksum(final String newValue) throws NoSuchAlgorithmException {
final AbstractChecksum checksum = JacksumAPI.getChecksumInstance(newValue);
return checksum;
}
/**
* @see java.beans.VetoableChangeListener#vetoableChange(java.beans.PropertyChangeEvent)
*/
@Override
public void vetoableChange(final PropertyChangeEvent evt) throws PropertyVetoException {
if (evt.getPropertyName().equals(SIM_THRESH)) {
if (((Float)evt.getNewValue()).floatValue() != 100.0) {
throw new PropertyVetoException(evt.getPropertyName() + " must be equal to 100.0%.", evt);
}
} else if (evt.getPropertyName().equals(MSG_DIGEST)) {
try {
checkChecksum((String)evt.getNewValue());
} catch (final NoSuchAlgorithmException ex) {
throw new PropertyVetoException(evt.getPropertyName() + " must be a valid message digest.", evt);
}
}
}
/**
* @see net.za.grasser.duplicate.fingerprint.configure.FingerprintConfig#getFingerprintDescription()
*/
@Override
public String getFingerprintDescription() {
return "The fingerprint consists of a Message Digest (i.e. MD5, SHA1 (default), RIPEMD) hash. The message digest checksum algorithm is configurable."
+ " Choosing a simple message digest like CRC16 however, is not recommended."
+ " This fingerprint is created for all files and all files are first compared by length and MD fingerprint.";
}
/**
* @see net.za.grasser.duplicate.fingerprint.configure.FingerprintConfig#getFingerprintName()
*/
@Override
public String getFingerprintName() {
return "Message Digest Fingerprint";
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?