This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-utils. See https://gitlab.nuiton.org/nuiton/nuiton-utils.git commit 2d20ddc601c2c0678a5a9184aa1cc7c268eb531c Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Aug 1 12:30:27 2016 +0200 clean code and javadoc --- src/main/java/org/nuiton/util/AliasMap.java | 4 +- src/main/java/org/nuiton/util/CallAnalyse.java | 2 +- .../org/nuiton/util/CategorisedListenerSet.java | 2 +- src/main/java/org/nuiton/util/DateUtil.java | 4 +- src/main/java/org/nuiton/util/DesktopUtil.java | 2 +- src/main/java/org/nuiton/util/FileUtil.java | 6 +- src/main/java/org/nuiton/util/MD5InputStream.java | 2 +- src/main/java/org/nuiton/util/MatrixMap.java | 4 +- src/main/java/org/nuiton/util/ObjectUtil.java | 2 +- src/main/java/org/nuiton/util/ReflectUtil.java | 2 +- src/main/java/org/nuiton/util/SemVer.java | 2 +- src/main/java/org/nuiton/util/TimeLog.java | 2 +- .../java/org/nuiton/util/ZipStreamEncoder.java | 2 +- src/main/java/org/nuiton/util/ZipUtil.java | 5 +- .../java/org/nuiton/util/beans/BinderFactory.java | 2 +- .../org/nuiton/util/converter/ConverterUtil.java | 2 +- .../org/nuiton/util/converter/EnumConverter.java | 2 +- .../util/converter/FormatConverterFactory.java | 2 +- .../nuiton/util/converter/KeyStrokeConverter.java | 2 +- .../org/nuiton/util/converter/URIConverter.java | 2 +- .../org/nuiton/util/converter/URLConverter.java | 2 +- .../util/pagination/PaginationParameter.java | 6 +- .../nuiton/util/pagination/PaginationResult.java | 4 +- .../org/nuiton/util/rmi/RemoteProxyFactory.java | 2 +- .../java/org/nuiton/util/rmi/ServiceExporter.java | 2 +- src/main/java/org/nuiton/util/version/SemVer.java | 2 +- src/test/java/org/nuiton/util/AliasMapTest.java | 2 +- src/test/java/org/nuiton/util/CallAnalyseTest.java | 2 +- src/test/java/org/nuiton/util/DateUtilTest.java | 2 +- src/test/java/org/nuiton/util/DesktopUtilTest.java | 3 +- src/test/java/org/nuiton/util/FileUtilTest.java | 2 +- .../java/org/nuiton/util/MD5InputStreamTest.java | 1236 ++++++++++---------- src/test/java/org/nuiton/util/PeriodDatesTest.java | 20 +- src/test/java/org/nuiton/util/ReflectUtilTest.java | 8 +- src/test/java/org/nuiton/util/ResourceTest.java | 10 +- src/test/java/org/nuiton/util/SemVerTest.java | 2 +- src/test/java/org/nuiton/util/ZipUtilTest.java | 2 +- .../org/nuiton/util/beans/BinderFactoryTest.java | 2 +- .../util/converter/VersionConverterTest.java | 4 +- .../nuiton/util/rmi/RmiExporterAndProxyTest.java | 2 +- .../resources/org/nuiton/util/fileUtilData.txt | 2 +- 41 files changed, 688 insertions(+), 682 deletions(-) diff --git a/src/main/java/org/nuiton/util/AliasMap.java b/src/main/java/org/nuiton/util/AliasMap.java index 62a82ac..7e6c9b1 100644 --- a/src/main/java/org/nuiton/util/AliasMap.java +++ b/src/main/java/org/nuiton/util/AliasMap.java @@ -46,7 +46,7 @@ import java.util.UUID; * avec des alias. * * Et ainsi recherche les valeurs qui ont un ensemble d'alias via la methode - * {@link #getValueAlias(java.lang.Object[]) } ou supprimer les valeurs qui + * {@link #getValueAlias(Object[]) } ou supprimer les valeurs qui * ont un ensemble d'Alias en commun via la methode {@link #removeValue} * * Si la cle ne vous importe que peu, vous pouvez par exemple utiliser @@ -58,7 +58,7 @@ import java.util.UUID; public class AliasMap<K, V, A> extends HashMap<K, V> { /** Logger. */ - static private Log log = LogFactory.getLog(AliasMap.class); + private static final Log log = LogFactory.getLog(AliasMap.class); private static final long serialVersionUID = 1L; /** key: alias, value: key */ diff --git a/src/main/java/org/nuiton/util/CallAnalyse.java b/src/main/java/org/nuiton/util/CallAnalyse.java index 8a4b934..01291a8 100644 --- a/src/main/java/org/nuiton/util/CallAnalyse.java +++ b/src/main/java/org/nuiton/util/CallAnalyse.java @@ -55,7 +55,7 @@ public class CallAnalyse { // CallAnalyse /** * Logger. */ - static private Log log = LogFactory.getLog(CallAnalyse.class); + private static final Log log = LogFactory.getLog(CallAnalyse.class); static private List<ThreadStatistics> listThreadStatistics = new ArrayList<ThreadStatistics>(); diff --git a/src/main/java/org/nuiton/util/CategorisedListenerSet.java b/src/main/java/org/nuiton/util/CategorisedListenerSet.java index f195bf1..210043d 100644 --- a/src/main/java/org/nuiton/util/CategorisedListenerSet.java +++ b/src/main/java/org/nuiton/util/CategorisedListenerSet.java @@ -64,7 +64,7 @@ import java.util.WeakHashMap; public class CategorisedListenerSet<L> { // CategorisedListenerSet /** Logger. */ - private static Log log = LogFactory.getLog(CategorisedListenerSet.class); + private static final Log log = LogFactory.getLog(CategorisedListenerSet.class); /** * permet de remplacer toutes les categories. diff --git a/src/main/java/org/nuiton/util/DateUtil.java b/src/main/java/org/nuiton/util/DateUtil.java index fbc836b..70c29a3 100644 --- a/src/main/java/org/nuiton/util/DateUtil.java +++ b/src/main/java/org/nuiton/util/DateUtil.java @@ -428,8 +428,8 @@ public class DateUtil { /** * Truncate a date to its week (to monday). It's equivalent to a call to - * {@link org.apache.commons.lang3.time.DateUtils#truncate(java.util.Date, int)} - * and giving {@link java.util.Calendar#DAY_OF_WEEK} argument, but such a call + * {@link org.apache.commons.lang3.time.DateUtils#truncate(Date, int)} + * and giving {@link Calendar#DAY_OF_WEEK} argument, but such a call * raise an exception showing that this field is not supported. This method * allows you to bypass this limitation. * diff --git a/src/main/java/org/nuiton/util/DesktopUtil.java b/src/main/java/org/nuiton/util/DesktopUtil.java index 8634b64..749ae77 100644 --- a/src/main/java/org/nuiton/util/DesktopUtil.java +++ b/src/main/java/org/nuiton/util/DesktopUtil.java @@ -38,7 +38,7 @@ import java.net.URI; public class DesktopUtil { /** Logger. */ - static private Log log = LogFactory.getLog(DesktopUtil.class); + private static final Log log = LogFactory.getLog(DesktopUtil.class); /** * Method to open an URI in the user default web browser. It uses the Java diff --git a/src/main/java/org/nuiton/util/FileUtil.java b/src/main/java/org/nuiton/util/FileUtil.java index 2e0ee33..9d09354 100644 --- a/src/main/java/org/nuiton/util/FileUtil.java +++ b/src/main/java/org/nuiton/util/FileUtil.java @@ -78,7 +78,7 @@ public class FileUtil { // FileUtil /** * Logger. */ - static private Log log = LogFactory.getLog(FileUtil.class); + private static final Log log = LogFactory.getLog(FileUtil.class); /** * Encoding utilisé (peut être redéfini) @@ -1264,11 +1264,9 @@ public class FileUtil { // FileUtil * @param dir the directory to create if not exisiting * @return {@code true} if directory was created, {@code false} if was no * need to create it - * @throws IOException if could not create directory * @since 1.3.2 */ - public static boolean createDirectoryIfNecessary(File dir) - throws IOException { + public static boolean createDirectoryIfNecessary(File dir) { if (!dir.exists()) { // do not throw exception if directory was created by another thread return dir.mkdirs(); diff --git a/src/main/java/org/nuiton/util/MD5InputStream.java b/src/main/java/org/nuiton/util/MD5InputStream.java index e3e0752..bc208f0 100644 --- a/src/main/java/org/nuiton/util/MD5InputStream.java +++ b/src/main/java/org/nuiton/util/MD5InputStream.java @@ -46,7 +46,7 @@ import static org.nuiton.i18n.I18n.t; public class MD5InputStream extends DigestInputStream { /** Class logger. */ - private static Log log = LogFactory.getLog(MD5InputStream.class); + private static final Log log = LogFactory.getLog(MD5InputStream.class); protected static MessageDigest getMD5Digest() throws IllegalStateException { try { diff --git a/src/main/java/org/nuiton/util/MatrixMap.java b/src/main/java/org/nuiton/util/MatrixMap.java index 2bf7668..33ccce1 100644 --- a/src/main/java/org/nuiton/util/MatrixMap.java +++ b/src/main/java/org/nuiton/util/MatrixMap.java @@ -780,7 +780,7 @@ public interface MatrixMap<E> extends Iterable<E> { /** * Logger. */ - static private Log log = LogFactory.getLog(MatrixMapFixed.class); + private static final Log log = LogFactory.getLog(MatrixMapFixed.class); protected Matrix<E> matrix = null; @@ -893,7 +893,7 @@ public interface MatrixMap<E> extends Iterable<E> { /** * Logger. */ - static private Log log = LogFactory.getLog(AbstractMatrixMap.class); + private static final Log log = LogFactory.getLog(AbstractMatrixMap.class); protected String name = null; diff --git a/src/main/java/org/nuiton/util/ObjectUtil.java b/src/main/java/org/nuiton/util/ObjectUtil.java index 90ca31d..5ba6297 100644 --- a/src/main/java/org/nuiton/util/ObjectUtil.java +++ b/src/main/java/org/nuiton/util/ObjectUtil.java @@ -68,7 +68,7 @@ import static org.nuiton.i18n.I18n.t; public class ObjectUtil { // ObjectUtil /** Logger. */ - static private Log log = LogFactory.getLog(ObjectUtil.class); + private static final Log log = LogFactory.getLog(ObjectUtil.class); /** Used to know what is separator between class and method*/ public static final String CLASS_METHOD_SEPARATOR = "#"; diff --git a/src/main/java/org/nuiton/util/ReflectUtil.java b/src/main/java/org/nuiton/util/ReflectUtil.java index 78b3501..5b60643 100644 --- a/src/main/java/org/nuiton/util/ReflectUtil.java +++ b/src/main/java/org/nuiton/util/ReflectUtil.java @@ -52,7 +52,7 @@ public class ReflectUtil { /** Logger */ - static private Log log = LogFactory.getLog(ReflectUtil.class); + private static final Log log = LogFactory.getLog(ReflectUtil.class); /** * Pour déterminer si un champ d'une classe est une constante diff --git a/src/main/java/org/nuiton/util/SemVer.java b/src/main/java/org/nuiton/util/SemVer.java index 6cf5ea2..8ce2c4e 100644 --- a/src/main/java/org/nuiton/util/SemVer.java +++ b/src/main/java/org/nuiton/util/SemVer.java @@ -76,7 +76,7 @@ public class SemVer implements Comparable<SemVer> { /** * Logger. */ - static private Log log = LogFactory.getLog(SemVer.class); + private static final Log log = LogFactory.getLog(SemVer.class); /** * Separateur utiliser entre chaque element d'une partie diff --git a/src/main/java/org/nuiton/util/TimeLog.java b/src/main/java/org/nuiton/util/TimeLog.java index 758bf6d..a94366a 100644 --- a/src/main/java/org/nuiton/util/TimeLog.java +++ b/src/main/java/org/nuiton/util/TimeLog.java @@ -32,7 +32,7 @@ import java.util.Map; * * usage * <pre> - * final static private Log log = LogFactory.getLog(MyClass.class); + * final private static final Log log = LogFactory.getLog(MyClass.class); * final static private TimeLog timeLog = new TimeLog(MyClass.class, 5000, 1000); * * diff --git a/src/main/java/org/nuiton/util/ZipStreamEncoder.java b/src/main/java/org/nuiton/util/ZipStreamEncoder.java index 86df696..7e754bb 100644 --- a/src/main/java/org/nuiton/util/ZipStreamEncoder.java +++ b/src/main/java/org/nuiton/util/ZipStreamEncoder.java @@ -37,7 +37,7 @@ import java.util.zip.ZipOutputStream; public class ZipStreamEncoder extends Thread { /** Logger. */ - static private Log log = LogFactory.getLog(ZipStreamEncoder.class); + private static final Log log = LogFactory.getLog(ZipStreamEncoder.class); /** The Constant BUFFER. */ static final int BUFFER = 2048; diff --git a/src/main/java/org/nuiton/util/ZipUtil.java b/src/main/java/org/nuiton/util/ZipUtil.java index 727d0f8..0ba98ad 100644 --- a/src/main/java/org/nuiton/util/ZipUtil.java +++ b/src/main/java/org/nuiton/util/ZipUtil.java @@ -56,7 +56,7 @@ import java.util.zip.ZipOutputStream; public class ZipUtil { /** Class logger. */ - private static Log log = LogFactory.getLog(ZipUtil.class); + private static final Log log = LogFactory.getLog(ZipUtil.class); /** Taille du buffer pour les lectures/écritures. */ private static final int BUFFER_SIZE = 8 * 1024; @@ -577,10 +577,9 @@ public class ZipUtil { * @param file the file to test * @return {@code true} if the file is a valid zip file, * {@code false} otherwise. - * @throws IOException if could not open zip file * @since 2.4.9 */ - public static boolean isZipFile(File file) throws IOException { + public static boolean isZipFile(File file) { boolean result = false; try { diff --git a/src/main/java/org/nuiton/util/beans/BinderFactory.java b/src/main/java/org/nuiton/util/beans/BinderFactory.java index 42f6144..a6fc3a5 100644 --- a/src/main/java/org/nuiton/util/beans/BinderFactory.java +++ b/src/main/java/org/nuiton/util/beans/BinderFactory.java @@ -342,7 +342,7 @@ public class BinderFactory { public static class BindelModelEntryMap implements Map<BinderModelEntry, Binder.BinderModel<?, ?>> { - protected Map<BinderModelEntry, Binder.BinderModel<?, ?>> delegate; + protected final Map<BinderModelEntry, Binder.BinderModel<?, ?>> delegate; public BindelModelEntryMap() { delegate = new HashMap<BinderModelEntry, Binder.BinderModel<?, ?>>(); diff --git a/src/main/java/org/nuiton/util/converter/ConverterUtil.java b/src/main/java/org/nuiton/util/converter/ConverterUtil.java index 0fa9b84..45a357c 100644 --- a/src/main/java/org/nuiton/util/converter/ConverterUtil.java +++ b/src/main/java/org/nuiton/util/converter/ConverterUtil.java @@ -41,7 +41,7 @@ import java.util.ServiceLoader; public class ConverterUtil { /** Logger. */ - static private Log log = LogFactory.getLog(ConverterUtil.class); + private static final Log log = LogFactory.getLog(ConverterUtil.class); /** * le paquetage où chercher les implentations de Converter, si non présents diff --git a/src/main/java/org/nuiton/util/converter/EnumConverter.java b/src/main/java/org/nuiton/util/converter/EnumConverter.java index 2ac9a0e..db7250f 100644 --- a/src/main/java/org/nuiton/util/converter/EnumConverter.java +++ b/src/main/java/org/nuiton/util/converter/EnumConverter.java @@ -50,7 +50,7 @@ import static org.nuiton.i18n.I18n.t; public class EnumConverter implements Converter { /** Logger. */ - static Log log = getLog(EnumConverter.class); + private static final Log log = getLog(EnumConverter.class); /** valeur par default à utiliser, si pas non trouvée et {@link #useDefault} actif. */ protected Object defaultValue; diff --git a/src/main/java/org/nuiton/util/converter/FormatConverterFactory.java b/src/main/java/org/nuiton/util/converter/FormatConverterFactory.java index 62442f7..eae3e07 100644 --- a/src/main/java/org/nuiton/util/converter/FormatConverterFactory.java +++ b/src/main/java/org/nuiton/util/converter/FormatConverterFactory.java @@ -59,7 +59,7 @@ import java.util.LinkedList; public class FormatConverterFactory { // FormatConverterFactory /** Logger. */ - static private Log log = LogFactory.getLog(FormatConverterFactory.class); + private static final Log log = LogFactory.getLog(FormatConverterFactory.class); static protected FormatConverterFactory instance; diff --git a/src/main/java/org/nuiton/util/converter/KeyStrokeConverter.java b/src/main/java/org/nuiton/util/converter/KeyStrokeConverter.java index 4d9feee..daa35c2 100644 --- a/src/main/java/org/nuiton/util/converter/KeyStrokeConverter.java +++ b/src/main/java/org/nuiton/util/converter/KeyStrokeConverter.java @@ -42,7 +42,7 @@ public class KeyStrokeConverter implements Converter { /** Logger. */ - static Log log = getLog(KeyStrokeConverter.class); + private static final Log log = getLog(KeyStrokeConverter.class); @Override public Object convert(Class aClass, Object value) { diff --git a/src/main/java/org/nuiton/util/converter/URIConverter.java b/src/main/java/org/nuiton/util/converter/URIConverter.java index 61a906f..4d80cc9 100644 --- a/src/main/java/org/nuiton/util/converter/URIConverter.java +++ b/src/main/java/org/nuiton/util/converter/URIConverter.java @@ -43,7 +43,7 @@ import static org.nuiton.i18n.I18n.t; public class URIConverter implements Converter { /** Logger. */ - static Log log = getLog(URIConverter.class); + private static final Log log = getLog(URIConverter.class); @Override public Object convert(Class aClass, Object value) { diff --git a/src/main/java/org/nuiton/util/converter/URLConverter.java b/src/main/java/org/nuiton/util/converter/URLConverter.java index a4c85d2..84f067f 100644 --- a/src/main/java/org/nuiton/util/converter/URLConverter.java +++ b/src/main/java/org/nuiton/util/converter/URLConverter.java @@ -43,7 +43,7 @@ import static org.nuiton.i18n.I18n.t; public class URLConverter implements Converter { /** Logger. */ - static Log log = getLog(URLConverter.class); + private static final Log log = getLog(URLConverter.class); @Override public Object convert(Class aClass, Object value) { diff --git a/src/main/java/org/nuiton/util/pagination/PaginationParameter.java b/src/main/java/org/nuiton/util/pagination/PaginationParameter.java index e2d52fa..7bb0c12 100644 --- a/src/main/java/org/nuiton/util/pagination/PaginationParameter.java +++ b/src/main/java/org/nuiton/util/pagination/PaginationParameter.java @@ -93,7 +93,7 @@ public class PaginationParameter implements Serializable { * @param orderClause1 an order clause attribute name. It comes together with {code}orderDesc1{/code} * @param orderDesc1 the asc/desc property associated with {code}orderClause1{/code} * @return an immutable PaginationParameter instance - * @see org.nuiton.util.pagination.PaginationOrder + * @see PaginationOrder * @see PaginationParameterBuilder */ public static PaginationParameter of(int pageNumber, int pageSize, @@ -117,7 +117,7 @@ public class PaginationParameter implements Serializable { * @param orderClause2 an order clause attribute name. It comes together with {code}orderDesc2{/code} * @param orderDesc2 the asc/desc property associated with {code}orderClause2{/code} * @return an immutable PaginationParameter instance - * @see org.nuiton.util.pagination.PaginationOrder + * @see PaginationOrder * @see PaginationParameterBuilder */ public static PaginationParameter of(int pageNumber, int pageSize, @@ -145,7 +145,7 @@ public class PaginationParameter implements Serializable { * @param orderClause3 an order clause attribute name. It comes together with {code}orderDesc3{/code} * @param orderDesc3 the asc/desc property associated with {code}orderClause3{/code} * @return an immutable PaginationParameter instance - * @see org.nuiton.util.pagination.PaginationOrder + * @see PaginationOrder * @see PaginationParameterBuilder */ public static PaginationParameter of(int pageNumber, int pageSize, diff --git a/src/main/java/org/nuiton/util/pagination/PaginationResult.java b/src/main/java/org/nuiton/util/pagination/PaginationResult.java index 598247e..14b86e7 100644 --- a/src/main/java/org/nuiton/util/pagination/PaginationResult.java +++ b/src/main/java/org/nuiton/util/pagination/PaginationResult.java @@ -29,7 +29,7 @@ import java.util.List; /** * Represents the result of a pagination request. It contains the result elements together with the - * {@link org.nuiton.util.pagination.PaginationParameter} used to compute it. The class also contains methods to + * {@link PaginationParameter} used to compute it. The class also contains methods to * navigate through the other pages. * * @author Arnaud Thimel (Code Lutin) @@ -51,7 +51,7 @@ public class PaginationResult<O> implements Serializable { /** * Creates an instance using the already computed list of {code}elements{/code} and {code}count{/count}, together - * with the {code}currentPage{/code} {@link org.nuiton.util.pagination.PaginationParameter} used to build it. + * with the {code}currentPage{/code} {@link PaginationParameter} used to build it. * * @param elements the list of elements * @param count the total number of elements (through all pages) diff --git a/src/main/java/org/nuiton/util/rmi/RemoteProxyFactory.java b/src/main/java/org/nuiton/util/rmi/RemoteProxyFactory.java index da30df7..7e2c9f6 100644 --- a/src/main/java/org/nuiton/util/rmi/RemoteProxyFactory.java +++ b/src/main/java/org/nuiton/util/rmi/RemoteProxyFactory.java @@ -41,7 +41,7 @@ import java.rmi.registry.Registry; */ public class RemoteProxyFactory { - private final static Log log = LogFactory.getLog(RemoteProxyFactory.class); + private static final Log log = LogFactory.getLog(RemoteProxyFactory.class); // TODO AThimel 12/01/2011 This settings has to be externalized protected final static int PORT = 12345; diff --git a/src/main/java/org/nuiton/util/rmi/ServiceExporter.java b/src/main/java/org/nuiton/util/rmi/ServiceExporter.java index c181c2b..0ac6daa 100644 --- a/src/main/java/org/nuiton/util/rmi/ServiceExporter.java +++ b/src/main/java/org/nuiton/util/rmi/ServiceExporter.java @@ -42,7 +42,7 @@ import java.rmi.server.UnicastRemoteObject; */ public final class ServiceExporter { - private final static Log log = LogFactory.getLog(ServiceExporter.class); + private static final Log log = LogFactory.getLog(ServiceExporter.class); // TODO AThimel 12/01/2011 This settings has to be externalized private static final int PORT = 12345; diff --git a/src/main/java/org/nuiton/util/version/SemVer.java b/src/main/java/org/nuiton/util/version/SemVer.java index 1636240..ad1928e 100644 --- a/src/main/java/org/nuiton/util/version/SemVer.java +++ b/src/main/java/org/nuiton/util/version/SemVer.java @@ -73,7 +73,7 @@ import java.util.regex.Pattern; public class SemVer implements Comparable<SemVer> { /** Logger. */ - static private Log log = LogFactory.getLog(SemVer.class); + private static final Log log = LogFactory.getLog(SemVer.class); /** Separateur utiliser entre chaque element d'une partie */ final static public String SERIES_SEPARATOR = "."; // le separateur diff --git a/src/test/java/org/nuiton/util/AliasMapTest.java b/src/test/java/org/nuiton/util/AliasMapTest.java index 4f90e8f..ef7c4a4 100644 --- a/src/test/java/org/nuiton/util/AliasMapTest.java +++ b/src/test/java/org/nuiton/util/AliasMapTest.java @@ -39,7 +39,7 @@ public class AliasMapTest { /** * Logger. */ - static private Log log = LogFactory.getLog(AliasMapTest.class); + private static final Log log = LogFactory.getLog(AliasMapTest.class); protected Object[] toArray(Collection c) { Object[] result = c.toArray(); diff --git a/src/test/java/org/nuiton/util/CallAnalyseTest.java b/src/test/java/org/nuiton/util/CallAnalyseTest.java index 983e25a..a392770 100644 --- a/src/test/java/org/nuiton/util/CallAnalyseTest.java +++ b/src/test/java/org/nuiton/util/CallAnalyseTest.java @@ -39,7 +39,7 @@ public class CallAnalyseTest extends TestCase { // CallAnalyseTest /** * Logger. */ - static private Log log = LogFactory.getLog(CallAnalyseTest.class); + private static final Log log = LogFactory.getLog(CallAnalyseTest.class); protected List<List<?>> memoryConsume = new ArrayList<List<?>>(); diff --git a/src/test/java/org/nuiton/util/DateUtilTest.java b/src/test/java/org/nuiton/util/DateUtilTest.java index 12bc98e..be8ab7e 100644 --- a/src/test/java/org/nuiton/util/DateUtilTest.java +++ b/src/test/java/org/nuiton/util/DateUtilTest.java @@ -292,7 +292,7 @@ public class DateUtilTest { } /** - * Shows that {@link org.nuiton.util.DateUtil#truncateToDayOfWeek(java.util.Date)} works + * Shows that {@link DateUtil#truncateToDayOfWeek(Date)} works * fine and that using commons library for this operation is not possible. */ @Test diff --git a/src/test/java/org/nuiton/util/DesktopUtilTest.java b/src/test/java/org/nuiton/util/DesktopUtilTest.java index 02b3a2f..e82960d 100644 --- a/src/test/java/org/nuiton/util/DesktopUtilTest.java +++ b/src/test/java/org/nuiton/util/DesktopUtilTest.java @@ -21,7 +21,6 @@ */ package org.nuiton.util; -import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; @@ -30,7 +29,7 @@ public class DesktopUtilTest { // Test ignored because it can fail on continuous integration server or // headless environment //@Test - public void testBrowse() throws IOException, URISyntaxException { + public void testBrowse() throws URISyntaxException { DesktopUtil.browse(new URI("http://localhost")); } } diff --git a/src/test/java/org/nuiton/util/FileUtilTest.java b/src/test/java/org/nuiton/util/FileUtilTest.java index cc86c90..0a3d0f8 100644 --- a/src/test/java/org/nuiton/util/FileUtilTest.java +++ b/src/test/java/org/nuiton/util/FileUtilTest.java @@ -50,7 +50,7 @@ public class FileUtilTest { // FileUtilTest protected File parent; @Before - public void setUp() throws Exception { + public void setUp() { parent = FileUtil.getTestSpecificDirectory( getClass(), diff --git a/src/test/java/org/nuiton/util/MD5InputStreamTest.java b/src/test/java/org/nuiton/util/MD5InputStreamTest.java index 808f1a1..33b1dde 100644 --- a/src/test/java/org/nuiton/util/MD5InputStreamTest.java +++ b/src/test/java/org/nuiton/util/MD5InputStreamTest.java @@ -27,7 +27,13 @@ import org.apache.commons.logging.LogFactory; import org.junit.Assert; import org.junit.Test; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FilterInputStream; +import java.io.IOException; +import java.io.InputStream; import java.net.URL; /** @@ -139,7 +145,7 @@ public class MD5InputStreamTest { if (log.isInfoEnabled()) { log.info("compute 10 times (new then old)"); } - for (int i=0;i<10;i++) { + for (int i = 0; i < 10; i++) { buildMD5_new(resource.openStream()); buildMD5_old(resource.openStream()); @@ -148,7 +154,7 @@ public class MD5InputStreamTest { if (log.isInfoEnabled()) { log.info("compute 10 times (old then new)"); } - for (int i=0;i<10;i++) { + for (int i = 0; i < 10; i++) { buildMD5_old(resource.openStream()); buildMD5_new(resource.openStream()); @@ -276,58 +282,58 @@ public class MD5InputStreamTest { public static class MD5 { - /** - * MD5 state - **/ - MD5State state; - - /** - * If Final() has been called, finals is set to the current finals - * state. Any Update() causes this to be set to null. - **/ - MD5State finals; - - /** - * Padding for Final() - **/ - static byte padding[] = { - (byte) 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - - private static boolean native_lib_loaded = false; - private static boolean native_lib_init_pending = true; - - /** - * Initialize MD5 internal state (object can be reused just by - * calling Init() after every Final() - **/ - public synchronized void Init () { - state = new MD5State(); - finals = null; - } + /** + * MD5 state + **/ + MD5State state; - /** - * Class constructor - **/ - public MD5 () { - if (native_lib_init_pending) _initNativeLibrary(); - this.Init(); - } + /** + * If Final() has been called, finals is set to the current finals + * state. Any Update() causes this to be set to null. + **/ + MD5State finals; - /** - * Initialize class, and update hash with ob.toString() - * - * @param ob Object, ob.toString() is used to update hash - * after initialization - **/ - public MD5 (Object ob) { - this(); - Update(ob.toString()); - } + /** + * Padding for Final() + **/ + static byte padding[] = { + (byte) 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + + private static boolean native_lib_loaded = false; + private static boolean native_lib_init_pending = true; + + /** + * Initialize MD5 internal state (object can be reused just by + * calling Init() after every Final() + **/ + public synchronized void Init() { + state = new MD5State(); + finals = null; + } + + /** + * Class constructor + **/ + public MD5() { + if (native_lib_init_pending) _initNativeLibrary(); + this.Init(); + } + + /** + * Initialize class, and update hash with ob.toString() + * + * @param ob Object, ob.toString() is used to update hash + * after initialization + **/ + public MD5(Object ob) { + this(); + Update(ob.toString()); + } - private void Decode (byte buffer[], int shift, int[] out) { + private void Decode(byte buffer[], int shift, int[] out) { /*len += shift; for (int i = 0; shift < len; i++, shift += 4) { out[i] = ((int) (buffer[shift] & 0xff)) | @@ -336,673 +342,677 @@ public class MD5InputStreamTest { (((int) buffer[shift + 3]) << 24); }*/ - // unrolled loop (original loop shown above) - - out[0] = ((int) (buffer[shift] & 0xff)) | - (((int) (buffer[shift + 1] & 0xff)) << 8) | - (((int) (buffer[shift + 2] & 0xff)) << 16) | - (((int) buffer[shift + 3]) << 24); - out[1] = ((int) (buffer[shift + 4] & 0xff)) | - (((int) (buffer[shift + 5] & 0xff)) << 8) | - (((int) (buffer[shift + 6] & 0xff)) << 16) | - (((int) buffer[shift + 7]) << 24); - out[2] = ((int) (buffer[shift + 8] & 0xff)) | - (((int) (buffer[shift + 9] & 0xff)) << 8) | - (((int) (buffer[shift + 10] & 0xff)) << 16) | - (((int) buffer[shift + 11]) << 24); - out[3] = ((int) (buffer[shift + 12] & 0xff)) | - (((int) (buffer[shift + 13] & 0xff)) << 8) | - (((int) (buffer[shift + 14] & 0xff)) << 16) | - (((int) buffer[shift + 15]) << 24); - out[4] = ((int) (buffer[shift + 16] & 0xff)) | - (((int) (buffer[shift + 17] & 0xff)) << 8) | - (((int) (buffer[shift + 18] & 0xff)) << 16) | - (((int) buffer[shift + 19]) << 24); - out[5] = ((int) (buffer[shift + 20] & 0xff)) | - (((int) (buffer[shift + 21] & 0xff)) << 8) | - (((int) (buffer[shift + 22] & 0xff)) << 16) | - (((int) buffer[shift + 23]) << 24); - out[6] = ((int) (buffer[shift + 24] & 0xff)) | - (((int) (buffer[shift + 25] & 0xff)) << 8) | - (((int) (buffer[shift + 26] & 0xff)) << 16) | - (((int) buffer[shift + 27]) << 24); - out[7] = ((int) (buffer[shift + 28] & 0xff)) | - (((int) (buffer[shift + 29] & 0xff)) << 8) | - (((int) (buffer[shift + 30] & 0xff)) << 16) | - (((int) buffer[shift + 31]) << 24); - out[8] = ((int) (buffer[shift + 32] & 0xff)) | - (((int) (buffer[shift + 33] & 0xff)) << 8) | - (((int) (buffer[shift + 34] & 0xff)) << 16) | - (((int) buffer[shift + 35]) << 24); - out[9] = ((int) (buffer[shift + 36] & 0xff)) | - (((int) (buffer[shift + 37] & 0xff)) << 8) | - (((int) (buffer[shift + 38] & 0xff)) << 16) | - (((int) buffer[shift + 39]) << 24); - out[10] = ((int) (buffer[shift + 40] & 0xff)) | - (((int) (buffer[shift + 41] & 0xff)) << 8) | - (((int) (buffer[shift + 42] & 0xff)) << 16) | - (((int) buffer[shift + 43]) << 24); - out[11] = ((int) (buffer[shift + 44] & 0xff)) | - (((int) (buffer[shift + 45] & 0xff)) << 8) | - (((int) (buffer[shift + 46] & 0xff)) << 16) | - (((int) buffer[shift + 47]) << 24); - out[12] = ((int) (buffer[shift + 48] & 0xff)) | - (((int) (buffer[shift + 49] & 0xff)) << 8) | - (((int) (buffer[shift + 50] & 0xff)) << 16) | - (((int) buffer[shift + 51]) << 24); - out[13] = ((int) (buffer[shift + 52] & 0xff)) | - (((int) (buffer[shift + 53] & 0xff)) << 8) | - (((int) (buffer[shift + 54] & 0xff)) << 16) | - (((int) buffer[shift + 55]) << 24); - out[14] = ((int) (buffer[shift + 56] & 0xff)) | - (((int) (buffer[shift + 57] & 0xff)) << 8) | - (((int) (buffer[shift + 58] & 0xff)) << 16) | - (((int) buffer[shift + 59]) << 24); - out[15] = ((int) (buffer[shift + 60] & 0xff)) | - (((int) (buffer[shift + 61] & 0xff)) << 8) | - (((int) (buffer[shift + 62] & 0xff)) << 16) | - (((int) buffer[shift + 63]) << 24); - } + // unrolled loop (original loop shown above) + + out[0] = ((int) (buffer[shift] & 0xff)) | + (((int) (buffer[shift + 1] & 0xff)) << 8) | + (((int) (buffer[shift + 2] & 0xff)) << 16) | + (((int) buffer[shift + 3]) << 24); + out[1] = ((int) (buffer[shift + 4] & 0xff)) | + (((int) (buffer[shift + 5] & 0xff)) << 8) | + (((int) (buffer[shift + 6] & 0xff)) << 16) | + (((int) buffer[shift + 7]) << 24); + out[2] = ((int) (buffer[shift + 8] & 0xff)) | + (((int) (buffer[shift + 9] & 0xff)) << 8) | + (((int) (buffer[shift + 10] & 0xff)) << 16) | + (((int) buffer[shift + 11]) << 24); + out[3] = ((int) (buffer[shift + 12] & 0xff)) | + (((int) (buffer[shift + 13] & 0xff)) << 8) | + (((int) (buffer[shift + 14] & 0xff)) << 16) | + (((int) buffer[shift + 15]) << 24); + out[4] = ((int) (buffer[shift + 16] & 0xff)) | + (((int) (buffer[shift + 17] & 0xff)) << 8) | + (((int) (buffer[shift + 18] & 0xff)) << 16) | + (((int) buffer[shift + 19]) << 24); + out[5] = ((int) (buffer[shift + 20] & 0xff)) | + (((int) (buffer[shift + 21] & 0xff)) << 8) | + (((int) (buffer[shift + 22] & 0xff)) << 16) | + (((int) buffer[shift + 23]) << 24); + out[6] = ((int) (buffer[shift + 24] & 0xff)) | + (((int) (buffer[shift + 25] & 0xff)) << 8) | + (((int) (buffer[shift + 26] & 0xff)) << 16) | + (((int) buffer[shift + 27]) << 24); + out[7] = ((int) (buffer[shift + 28] & 0xff)) | + (((int) (buffer[shift + 29] & 0xff)) << 8) | + (((int) (buffer[shift + 30] & 0xff)) << 16) | + (((int) buffer[shift + 31]) << 24); + out[8] = ((int) (buffer[shift + 32] & 0xff)) | + (((int) (buffer[shift + 33] & 0xff)) << 8) | + (((int) (buffer[shift + 34] & 0xff)) << 16) | + (((int) buffer[shift + 35]) << 24); + out[9] = ((int) (buffer[shift + 36] & 0xff)) | + (((int) (buffer[shift + 37] & 0xff)) << 8) | + (((int) (buffer[shift + 38] & 0xff)) << 16) | + (((int) buffer[shift + 39]) << 24); + out[10] = ((int) (buffer[shift + 40] & 0xff)) | + (((int) (buffer[shift + 41] & 0xff)) << 8) | + (((int) (buffer[shift + 42] & 0xff)) << 16) | + (((int) buffer[shift + 43]) << 24); + out[11] = ((int) (buffer[shift + 44] & 0xff)) | + (((int) (buffer[shift + 45] & 0xff)) << 8) | + (((int) (buffer[shift + 46] & 0xff)) << 16) | + (((int) buffer[shift + 47]) << 24); + out[12] = ((int) (buffer[shift + 48] & 0xff)) | + (((int) (buffer[shift + 49] & 0xff)) << 8) | + (((int) (buffer[shift + 50] & 0xff)) << 16) | + (((int) buffer[shift + 51]) << 24); + out[13] = ((int) (buffer[shift + 52] & 0xff)) | + (((int) (buffer[shift + 53] & 0xff)) << 8) | + (((int) (buffer[shift + 54] & 0xff)) << 16) | + (((int) buffer[shift + 55]) << 24); + out[14] = ((int) (buffer[shift + 56] & 0xff)) | + (((int) (buffer[shift + 57] & 0xff)) << 8) | + (((int) (buffer[shift + 58] & 0xff)) << 16) | + (((int) buffer[shift + 59]) << 24); + out[15] = ((int) (buffer[shift + 60] & 0xff)) | + (((int) (buffer[shift + 61] & 0xff)) << 8) | + (((int) (buffer[shift + 62] & 0xff)) << 16) | + (((int) buffer[shift + 63]) << 24); + } - private native void Transform_native (int[] state, byte buffer[], int shift, int length); + private native void Transform_native(int[] state, byte buffer[], int shift, int length); - private void Transform (MD5State state, byte buffer[], int shift, int[] decode_buf) { - int - a = state.state[0], - b = state.state[1], - c = state.state[2], - d = state.state[3], - x[] = decode_buf; + private void Transform(MD5State state, byte buffer[], int shift, int[] decode_buf) { + int + a = state.state[0], + b = state.state[1], + c = state.state[2], + d = state.state[3], + x[] = decode_buf; - Decode(buffer, shift, decode_buf); + Decode(buffer, shift, decode_buf); /* Round 1 */ - a += ((b & c) | (~b & d)) + x[ 0] + 0xd76aa478; /* 1 */ - a = ((a << 7) | (a >>> 25)) + b; - d += ((a & b) | (~a & c)) + x[ 1] + 0xe8c7b756; /* 2 */ - d = ((d << 12) | (d >>> 20)) + a; - c += ((d & a) | (~d & b)) + x[ 2] + 0x242070db; /* 3 */ - c = ((c << 17) | (c >>> 15)) + d; - b += ((c & d) | (~c & a)) + x[ 3] + 0xc1bdceee; /* 4 */ - b = ((b << 22) | (b >>> 10)) + c; - - a += ((b & c) | (~b & d)) + x[ 4] + 0xf57c0faf; /* 5 */ - a = ((a << 7) | (a >>> 25)) + b; - d += ((a & b) | (~a & c)) + x[ 5] + 0x4787c62a; /* 6 */ - d = ((d << 12) | (d >>> 20)) + a; - c += ((d & a) | (~d & b)) + x[ 6] + 0xa8304613; /* 7 */ - c = ((c << 17) | (c >>> 15)) + d; - b += ((c & d) | (~c & a)) + x[ 7] + 0xfd469501; /* 8 */ - b = ((b << 22) | (b >>> 10)) + c; - - a += ((b & c) | (~b & d)) + x[ 8] + 0x698098d8; /* 9 */ - a = ((a << 7) | (a >>> 25)) + b; - d += ((a & b) | (~a & c)) + x[ 9] + 0x8b44f7af; /* 10 */ - d = ((d << 12) | (d >>> 20)) + a; - c += ((d & a) | (~d & b)) + x[10] + 0xffff5bb1; /* 11 */ - c = ((c << 17) | (c >>> 15)) + d; - b += ((c & d) | (~c & a)) + x[11] + 0x895cd7be; /* 12 */ - b = ((b << 22) | (b >>> 10)) + c; - - a += ((b & c) | (~b & d)) + x[12] + 0x6b901122; /* 13 */ - a = ((a << 7) | (a >>> 25)) + b; - d += ((a & b) | (~a & c)) + x[13] + 0xfd987193; /* 14 */ - d = ((d << 12) | (d >>> 20)) + a; - c += ((d & a) | (~d & b)) + x[14] + 0xa679438e; /* 15 */ - c = ((c << 17) | (c >>> 15)) + d; - b += ((c & d) | (~c & a)) + x[15] + 0x49b40821; /* 16 */ - b = ((b << 22) | (b >>> 10)) + c; + a += ((b & c) | (~b & d)) + x[0] + 0xd76aa478; /* 1 */ + a = ((a << 7) | (a >>> 25)) + b; + d += ((a & b) | (~a & c)) + x[1] + 0xe8c7b756; /* 2 */ + d = ((d << 12) | (d >>> 20)) + a; + c += ((d & a) | (~d & b)) + x[2] + 0x242070db; /* 3 */ + c = ((c << 17) | (c >>> 15)) + d; + b += ((c & d) | (~c & a)) + x[3] + 0xc1bdceee; /* 4 */ + b = ((b << 22) | (b >>> 10)) + c; + + a += ((b & c) | (~b & d)) + x[4] + 0xf57c0faf; /* 5 */ + a = ((a << 7) | (a >>> 25)) + b; + d += ((a & b) | (~a & c)) + x[5] + 0x4787c62a; /* 6 */ + d = ((d << 12) | (d >>> 20)) + a; + c += ((d & a) | (~d & b)) + x[6] + 0xa8304613; /* 7 */ + c = ((c << 17) | (c >>> 15)) + d; + b += ((c & d) | (~c & a)) + x[7] + 0xfd469501; /* 8 */ + b = ((b << 22) | (b >>> 10)) + c; + + a += ((b & c) | (~b & d)) + x[8] + 0x698098d8; /* 9 */ + a = ((a << 7) | (a >>> 25)) + b; + d += ((a & b) | (~a & c)) + x[9] + 0x8b44f7af; /* 10 */ + d = ((d << 12) | (d >>> 20)) + a; + c += ((d & a) | (~d & b)) + x[10] + 0xffff5bb1; /* 11 */ + c = ((c << 17) | (c >>> 15)) + d; + b += ((c & d) | (~c & a)) + x[11] + 0x895cd7be; /* 12 */ + b = ((b << 22) | (b >>> 10)) + c; + + a += ((b & c) | (~b & d)) + x[12] + 0x6b901122; /* 13 */ + a = ((a << 7) | (a >>> 25)) + b; + d += ((a & b) | (~a & c)) + x[13] + 0xfd987193; /* 14 */ + d = ((d << 12) | (d >>> 20)) + a; + c += ((d & a) | (~d & b)) + x[14] + 0xa679438e; /* 15 */ + c = ((c << 17) | (c >>> 15)) + d; + b += ((c & d) | (~c & a)) + x[15] + 0x49b40821; /* 16 */ + b = ((b << 22) | (b >>> 10)) + c; /* Round 2 */ - a += ((b & d) | (c & ~d)) + x[ 1] + 0xf61e2562; /* 17 */ - a = ((a << 5) | (a >>> 27)) + b; - d += ((a & c) | (b & ~c)) + x[ 6] + 0xc040b340; /* 18 */ - d = ((d << 9) | (d >>> 23)) + a; - c += ((d & b) | (a & ~b)) + x[11] + 0x265e5a51; /* 19 */ - c = ((c << 14) | (c >>> 18)) + d; - b += ((c & a) | (d & ~a)) + x[ 0] + 0xe9b6c7aa; /* 20 */ - b = ((b << 20) | (b >>> 12)) + c; - - a += ((b & d) | (c & ~d)) + x[ 5] + 0xd62f105d; /* 21 */ - a = ((a << 5) | (a >>> 27)) + b; - d += ((a & c) | (b & ~c)) + x[10] + 0x02441453; /* 22 */ - d = ((d << 9) | (d >>> 23)) + a; - c += ((d & b) | (a & ~b)) + x[15] + 0xd8a1e681; /* 23 */ - c = ((c << 14) | (c >>> 18)) + d; - b += ((c & a) | (d & ~a)) + x[ 4] + 0xe7d3fbc8; /* 24 */ - b = ((b << 20) | (b >>> 12)) + c; - - a += ((b & d) | (c & ~d)) + x[ 9] + 0x21e1cde6; /* 25 */ - a = ((a << 5) | (a >>> 27)) + b; - d += ((a & c) | (b & ~c)) + x[14] + 0xc33707d6; /* 26 */ - d = ((d << 9) | (d >>> 23)) + a; - c += ((d & b) | (a & ~b)) + x[ 3] + 0xf4d50d87; /* 27 */ - c = ((c << 14) | (c >>> 18)) + d; - b += ((c & a) | (d & ~a)) + x[ 8] + 0x455a14ed; /* 28 */ - b = ((b << 20) | (b >>> 12)) + c; - - a += ((b & d) | (c & ~d)) + x[13] + 0xa9e3e905; /* 29 */ - a = ((a << 5) | (a >>> 27)) + b; - d += ((a & c) | (b & ~c)) + x[ 2] + 0xfcefa3f8; /* 30 */ - d = ((d << 9) | (d >>> 23)) + a; - c += ((d & b) | (a & ~b)) + x[ 7] + 0x676f02d9; /* 31 */ - c = ((c << 14) | (c >>> 18)) + d; - b += ((c & a) | (d & ~a)) + x[12] + 0x8d2a4c8a; /* 32 */ - b = ((b << 20) | (b >>> 12)) + c; + a += ((b & d) | (c & ~d)) + x[1] + 0xf61e2562; /* 17 */ + a = ((a << 5) | (a >>> 27)) + b; + d += ((a & c) | (b & ~c)) + x[6] + 0xc040b340; /* 18 */ + d = ((d << 9) | (d >>> 23)) + a; + c += ((d & b) | (a & ~b)) + x[11] + 0x265e5a51; /* 19 */ + c = ((c << 14) | (c >>> 18)) + d; + b += ((c & a) | (d & ~a)) + x[0] + 0xe9b6c7aa; /* 20 */ + b = ((b << 20) | (b >>> 12)) + c; + + a += ((b & d) | (c & ~d)) + x[5] + 0xd62f105d; /* 21 */ + a = ((a << 5) | (a >>> 27)) + b; + d += ((a & c) | (b & ~c)) + x[10] + 0x02441453; /* 22 */ + d = ((d << 9) | (d >>> 23)) + a; + c += ((d & b) | (a & ~b)) + x[15] + 0xd8a1e681; /* 23 */ + c = ((c << 14) | (c >>> 18)) + d; + b += ((c & a) | (d & ~a)) + x[4] + 0xe7d3fbc8; /* 24 */ + b = ((b << 20) | (b >>> 12)) + c; + + a += ((b & d) | (c & ~d)) + x[9] + 0x21e1cde6; /* 25 */ + a = ((a << 5) | (a >>> 27)) + b; + d += ((a & c) | (b & ~c)) + x[14] + 0xc33707d6; /* 26 */ + d = ((d << 9) | (d >>> 23)) + a; + c += ((d & b) | (a & ~b)) + x[3] + 0xf4d50d87; /* 27 */ + c = ((c << 14) | (c >>> 18)) + d; + b += ((c & a) | (d & ~a)) + x[8] + 0x455a14ed; /* 28 */ + b = ((b << 20) | (b >>> 12)) + c; + + a += ((b & d) | (c & ~d)) + x[13] + 0xa9e3e905; /* 29 */ + a = ((a << 5) | (a >>> 27)) + b; + d += ((a & c) | (b & ~c)) + x[2] + 0xfcefa3f8; /* 30 */ + d = ((d << 9) | (d >>> 23)) + a; + c += ((d & b) | (a & ~b)) + x[7] + 0x676f02d9; /* 31 */ + c = ((c << 14) | (c >>> 18)) + d; + b += ((c & a) | (d & ~a)) + x[12] + 0x8d2a4c8a; /* 32 */ + b = ((b << 20) | (b >>> 12)) + c; /* Round 3 */ - a += (b ^ c ^ d) + x[ 5] + 0xfffa3942; /* 33 */ - a = ((a << 4) | (a >>> 28)) + b; - d += (a ^ b ^ c) + x[ 8] + 0x8771f681; /* 34 */ - d = ((d << 11) | (d >>> 21)) + a; - c += (d ^ a ^ b) + x[11] + 0x6d9d6122; /* 35 */ - c = ((c << 16) | (c >>> 16)) + d; - b += (c ^ d ^ a) + x[14] + 0xfde5380c; /* 36 */ - b = ((b << 23) | (b >>> 9)) + c; - - a += (b ^ c ^ d) + x[ 1] + 0xa4beea44; /* 37 */ - a = ((a << 4) | (a >>> 28)) + b; - d += (a ^ b ^ c) + x[ 4] + 0x4bdecfa9; /* 38 */ - d = ((d << 11) | (d >>> 21)) + a; - c += (d ^ a ^ b) + x[ 7] + 0xf6bb4b60; /* 39 */ - c = ((c << 16) | (c >>> 16)) + d; - b += (c ^ d ^ a) + x[10] + 0xbebfbc70; /* 40 */ - b = ((b << 23) | (b >>> 9)) + c; - - a += (b ^ c ^ d) + x[13] + 0x289b7ec6; /* 41 */ - a = ((a << 4) | (a >>> 28)) + b; - d += (a ^ b ^ c) + x[ 0] + 0xeaa127fa; /* 42 */ - d = ((d << 11) | (d >>> 21)) + a; - c += (d ^ a ^ b) + x[ 3] + 0xd4ef3085; /* 43 */ - c = ((c << 16) | (c >>> 16)) + d; - b += (c ^ d ^ a) + x[ 6] + 0x04881d05; /* 44 */ - b = ((b << 23) | (b >>> 9)) + c; - - a += (b ^ c ^ d) + x[ 9] + 0xd9d4d039; /* 33 */ - a = ((a << 4) | (a >>> 28)) + b; - d += (a ^ b ^ c) + x[12] + 0xe6db99e5; /* 34 */ - d = ((d << 11) | (d >>> 21)) + a; - c += (d ^ a ^ b) + x[15] + 0x1fa27cf8; /* 35 */ - c = ((c << 16) | (c >>> 16)) + d; - b += (c ^ d ^ a) + x[ 2] + 0xc4ac5665; /* 36 */ - b = ((b << 23) | (b >>> 9)) + c; + a += (b ^ c ^ d) + x[5] + 0xfffa3942; /* 33 */ + a = ((a << 4) | (a >>> 28)) + b; + d += (a ^ b ^ c) + x[8] + 0x8771f681; /* 34 */ + d = ((d << 11) | (d >>> 21)) + a; + c += (d ^ a ^ b) + x[11] + 0x6d9d6122; /* 35 */ + c = ((c << 16) | (c >>> 16)) + d; + b += (c ^ d ^ a) + x[14] + 0xfde5380c; /* 36 */ + b = ((b << 23) | (b >>> 9)) + c; + + a += (b ^ c ^ d) + x[1] + 0xa4beea44; /* 37 */ + a = ((a << 4) | (a >>> 28)) + b; + d += (a ^ b ^ c) + x[4] + 0x4bdecfa9; /* 38 */ + d = ((d << 11) | (d >>> 21)) + a; + c += (d ^ a ^ b) + x[7] + 0xf6bb4b60; /* 39 */ + c = ((c << 16) | (c >>> 16)) + d; + b += (c ^ d ^ a) + x[10] + 0xbebfbc70; /* 40 */ + b = ((b << 23) | (b >>> 9)) + c; + + a += (b ^ c ^ d) + x[13] + 0x289b7ec6; /* 41 */ + a = ((a << 4) | (a >>> 28)) + b; + d += (a ^ b ^ c) + x[0] + 0xeaa127fa; /* 42 */ + d = ((d << 11) | (d >>> 21)) + a; + c += (d ^ a ^ b) + x[3] + 0xd4ef3085; /* 43 */ + c = ((c << 16) | (c >>> 16)) + d; + b += (c ^ d ^ a) + x[6] + 0x04881d05; /* 44 */ + b = ((b << 23) | (b >>> 9)) + c; + + a += (b ^ c ^ d) + x[9] + 0xd9d4d039; /* 33 */ + a = ((a << 4) | (a >>> 28)) + b; + d += (a ^ b ^ c) + x[12] + 0xe6db99e5; /* 34 */ + d = ((d << 11) | (d >>> 21)) + a; + c += (d ^ a ^ b) + x[15] + 0x1fa27cf8; /* 35 */ + c = ((c << 16) | (c >>> 16)) + d; + b += (c ^ d ^ a) + x[2] + 0xc4ac5665; /* 36 */ + b = ((b << 23) | (b >>> 9)) + c; /* Round 4 */ - a += (c ^ (b | ~d)) + x[ 0] + 0xf4292244; /* 49 */ - a = ((a << 6) | (a >>> 26)) + b; - d += (b ^ (a | ~c)) + x[ 7] + 0x432aff97; /* 50 */ - d = ((d << 10) | (d >>> 22)) + a; - c += (a ^ (d | ~b)) + x[14] + 0xab9423a7; /* 51 */ - c = ((c << 15) | (c >>> 17)) + d; - b += (d ^ (c | ~a)) + x[ 5] + 0xfc93a039; /* 52 */ - b = ((b << 21) | (b >>> 11)) + c; - - a += (c ^ (b | ~d)) + x[12] + 0x655b59c3; /* 53 */ - a = ((a << 6) | (a >>> 26)) + b; - d += (b ^ (a | ~c)) + x[ 3] + 0x8f0ccc92; /* 54 */ - d = ((d << 10) | (d >>> 22)) + a; - c += (a ^ (d | ~b)) + x[10] + 0xffeff47d; /* 55 */ - c = ((c << 15) | (c >>> 17)) + d; - b += (d ^ (c | ~a)) + x[ 1] + 0x85845dd1; /* 56 */ - b = ((b << 21) | (b >>> 11)) + c; - - a += (c ^ (b | ~d)) + x[ 8] + 0x6fa87e4f; /* 57 */ - a = ((a << 6) | (a >>> 26)) + b; - d += (b ^ (a | ~c)) + x[15] + 0xfe2ce6e0; /* 58 */ - d = ((d << 10) | (d >>> 22)) + a; - c += (a ^ (d | ~b)) + x[ 6] + 0xa3014314; /* 59 */ - c = ((c << 15) | (c >>> 17)) + d; - b += (d ^ (c | ~a)) + x[13] + 0x4e0811a1; /* 60 */ - b = ((b << 21) | (b >>> 11)) + c; - - a += (c ^ (b | ~d)) + x[ 4] + 0xf7537e82; /* 61 */ - a = ((a << 6) | (a >>> 26)) + b; - d += (b ^ (a | ~c)) + x[11] + 0xbd3af235; /* 62 */ - d = ((d << 10) | (d >>> 22)) + a; - c += (a ^ (d | ~b)) + x[ 2] + 0x2ad7d2bb; /* 63 */ - c = ((c << 15) | (c >>> 17)) + d; - b += (d ^ (c | ~a)) + x[ 9] + 0xeb86d391; /* 64 */ - b = ((b << 21) | (b >>> 11)) + c; - - state.state[0] += a; - state.state[1] += b; - state.state[2] += c; - state.state[3] += d; - } + a += (c ^ (b | ~d)) + x[0] + 0xf4292244; /* 49 */ + a = ((a << 6) | (a >>> 26)) + b; + d += (b ^ (a | ~c)) + x[7] + 0x432aff97; /* 50 */ + d = ((d << 10) | (d >>> 22)) + a; + c += (a ^ (d | ~b)) + x[14] + 0xab9423a7; /* 51 */ + c = ((c << 15) | (c >>> 17)) + d; + b += (d ^ (c | ~a)) + x[5] + 0xfc93a039; /* 52 */ + b = ((b << 21) | (b >>> 11)) + c; + + a += (c ^ (b | ~d)) + x[12] + 0x655b59c3; /* 53 */ + a = ((a << 6) | (a >>> 26)) + b; + d += (b ^ (a | ~c)) + x[3] + 0x8f0ccc92; /* 54 */ + d = ((d << 10) | (d >>> 22)) + a; + c += (a ^ (d | ~b)) + x[10] + 0xffeff47d; /* 55 */ + c = ((c << 15) | (c >>> 17)) + d; + b += (d ^ (c | ~a)) + x[1] + 0x85845dd1; /* 56 */ + b = ((b << 21) | (b >>> 11)) + c; + + a += (c ^ (b | ~d)) + x[8] + 0x6fa87e4f; /* 57 */ + a = ((a << 6) | (a >>> 26)) + b; + d += (b ^ (a | ~c)) + x[15] + 0xfe2ce6e0; /* 58 */ + d = ((d << 10) | (d >>> 22)) + a; + c += (a ^ (d | ~b)) + x[6] + 0xa3014314; /* 59 */ + c = ((c << 15) | (c >>> 17)) + d; + b += (d ^ (c | ~a)) + x[13] + 0x4e0811a1; /* 60 */ + b = ((b << 21) | (b >>> 11)) + c; + + a += (c ^ (b | ~d)) + x[4] + 0xf7537e82; /* 61 */ + a = ((a << 6) | (a >>> 26)) + b; + d += (b ^ (a | ~c)) + x[11] + 0xbd3af235; /* 62 */ + d = ((d << 10) | (d >>> 22)) + a; + c += (a ^ (d | ~b)) + x[2] + 0x2ad7d2bb; /* 63 */ + c = ((c << 15) | (c >>> 17)) + d; + b += (d ^ (c | ~a)) + x[9] + 0xeb86d391; /* 64 */ + b = ((b << 21) | (b >>> 11)) + c; + + state.state[0] += a; + state.state[1] += b; + state.state[2] += c; + state.state[3] += d; + } - /** - * Updates hash with the bytebuffer given (using at maximum length bytes from - * that buffer) - * - * @param stat Which state is updated - * @param buffer Array of bytes to be hashed - * @param offset Offset to buffer array - * @param length Use at maximum `length' bytes (absolute - * maximum is buffer.length) - */ - public void Update (MD5State stat, byte buffer[], int offset, int length) { - int index, partlen, i, start; - finals = null; + /** + * Updates hash with the bytebuffer given (using at maximum length bytes from + * that buffer) + * + * @param stat Which state is updated + * @param buffer Array of bytes to be hashed + * @param offset Offset to buffer array + * @param length Use at maximum `length' bytes (absolute + * maximum is buffer.length) + */ + public void Update(MD5State stat, byte buffer[], int offset, int length) { + int index, partlen, i, start; + finals = null; /* Length can be told to be shorter, but not inter */ - if ((length - offset)> buffer.length) - length = buffer.length - offset; + if ((length - offset) > buffer.length) + length = buffer.length - offset; /* compute number of bytes mod 64 */ - index = (int) (stat.count & 0x3f); - stat.count += length; + index = (int) (stat.count & 0x3f); + stat.count += length; - partlen = 64 - index; + partlen = 64 - index; - if (length >= partlen) { + if (length >= partlen) { - // update state (using native method) to reflect input + // update state (using native method) to reflect input - if (native_lib_loaded) { - if (partlen == 64) { - partlen = 0; - } else { - for (i = 0; i < partlen; i++) - stat.buffer[i + index] = buffer[i + offset]; - Transform_native(stat.state, stat.buffer, 0, 64); - } - i = partlen + ((length - partlen) / 64) * 64; - - // break into chunks to guard against stack overflow in JNI - - int transformLength = length - partlen; - int transformOffset = partlen + offset; - final int MAX_LENGTH = 65536; // prevent stack overflow in JNI - while (true) { - if (transformLength > MAX_LENGTH) { - Transform_native(stat.state, buffer, transformOffset, MAX_LENGTH); - transformLength -= MAX_LENGTH; - transformOffset += MAX_LENGTH; + if (native_lib_loaded) { + if (partlen == 64) { + partlen = 0; } else { - Transform_native(stat.state, buffer, transformOffset, transformLength); - break; + for (i = 0; i < partlen; i++) + stat.buffer[i + index] = buffer[i + offset]; + Transform_native(stat.state, stat.buffer, 0, 64); + } + i = partlen + ((length - partlen) / 64) * 64; + + // break into chunks to guard against stack overflow in JNI + + int transformLength = length - partlen; + int transformOffset = partlen + offset; + final int MAX_LENGTH = 65536; // prevent stack overflow in JNI + while (true) { + if (transformLength > MAX_LENGTH) { + Transform_native(stat.state, buffer, transformOffset, MAX_LENGTH); + transformLength -= MAX_LENGTH; + transformOffset += MAX_LENGTH; + } else { + Transform_native(stat.state, buffer, transformOffset, transformLength); + break; + } } } - } - // update state (using only Java) to reflect input + // update state (using only Java) to reflect input - else { - int[] decode_buf = new int[16]; - if (partlen == 64) { - partlen = 0; - } else { - for (i = 0; i < partlen; i++) - stat.buffer[i + index] = buffer[i + offset]; - Transform(stat, stat.buffer, 0, decode_buf); - } - for (i = partlen; (i + 63) < length; i+= 64) { - Transform(stat, buffer, i + offset, decode_buf); + else { + int[] decode_buf = new int[16]; + if (partlen == 64) { + partlen = 0; + } else { + for (i = 0; i < partlen; i++) + stat.buffer[i + index] = buffer[i + offset]; + Transform(stat, stat.buffer, 0, decode_buf); + } + for (i = partlen; (i + 63) < length; i += 64) { + Transform(stat, buffer, i + offset, decode_buf); + } } + index = 0; + } else { + i = 0; } - index = 0; - } else { - i = 0; - } /* buffer remaining input */ - if (i < length) { - start = i; - for (; i < length; i++) { - stat.buffer[index + i - start] = buffer[i + offset]; + if (i < length) { + start = i; + for (; i < length; i++) { + stat.buffer[index + i - start] = buffer[i + offset]; + } } } - } /* * Update()s for other datatypes than byte[] also. Update(byte[], int) * is only the main driver. */ - /** - * Plain update, updates this object - **/ - public void Update (byte buffer[], int offset, int length) { - Update(this.state, buffer, offset, length); - } + /** + * Plain update, updates this object + **/ + public void Update(byte buffer[], int offset, int length) { + Update(this.state, buffer, offset, length); + } - public void Update (byte buffer[], int length) { - Update(this.state, buffer, 0, length); - } + public void Update(byte buffer[], int length) { + Update(this.state, buffer, 0, length); + } - /** - * Updates hash with given array of bytes - * - * @param buffer Array of bytes to use for updating the hash - **/ - public void Update (byte buffer[]) { - Update(buffer, 0, buffer.length); - } + /** + * Updates hash with given array of bytes + * + * @param buffer Array of bytes to use for updating the hash + **/ + public void Update(byte buffer[]) { + Update(buffer, 0, buffer.length); + } - /** - * Updates hash with a single byte - * - * @param b Single byte to update the hash - **/ - public void Update (byte b) { - byte buffer[] = new byte[1]; - buffer[0] = b; + /** + * Updates hash with a single byte + * + * @param b Single byte to update the hash + **/ + public void Update(byte b) { + byte buffer[] = new byte[1]; + buffer[0] = b; - Update(buffer, 1); - } + Update(buffer, 1); + } - /** - * Update buffer with given string. Note that because the version of - * the s.getBytes() method without parameters is used to convert the - * string to a byte array, the results of this method may be different - * on different platforms. The s.getBytes() method converts the string - * into a byte array using the current platform's default character set - * and may therefore have different results on platforms with different - * default character sets. If a version that works consistently - * across platforms with different default character sets is desired, - * use the overloaded version of the Update() method which takes a - * string and a character encoding. - * - * @param s String to be update to hash (is used as s.getBytes()) - **/ - public void Update (String s) { - byte chars[] = s.getBytes(); - Update(chars, chars.length); - } + /** + * Update buffer with given string. Note that because the version of + * the s.getBytes() method without parameters is used to convert the + * string to a byte array, the results of this method may be different + * on different platforms. The s.getBytes() method converts the string + * into a byte array using the current platform's default character set + * and may therefore have different results on platforms with different + * default character sets. If a version that works consistently + * across platforms with different default character sets is desired, + * use the overloaded version of the Update() method which takes a + * string and a character encoding. + * + * @param s String to be update to hash (is used as s.getBytes()) + **/ + public void Update(String s) { + byte chars[] = s.getBytes(); + Update(chars, chars.length); + } - /** - * Update buffer with given string using the given encoding. If the - * given encoding is null, the encoding "ISO8859_1" is used. - * - * @param s String to be update to hash (is used as - * s.getBytes(charset_name)) - * @param charset_name The character set to use to convert s to a - * byte array, or null if the "ISO8859_1" - * character set is desired. - * @exception java.io.UnsupportedEncodingException If the named - * charset is not supported. - **/ - public void Update (String s, String charset_name) throws java.io.UnsupportedEncodingException { - if (charset_name == null) charset_name = "ISO8859_1"; - byte chars[] = s.getBytes(charset_name); - Update(chars, chars.length); - } + /** + * Update buffer with given string using the given encoding. If the + * given encoding is null, the encoding "ISO8859_1" is used. + * + * @param s String to be update to hash (is used as + * s.getBytes(charset_name)) + * @param charset_name The character set to use to convert s to a + * byte array, or null if the "ISO8859_1" + * character set is desired. + * @throws java.io.UnsupportedEncodingException If the named + * charset is not supported. + **/ + public void Update(String s, String charset_name) throws java.io.UnsupportedEncodingException { + if (charset_name == null) charset_name = "ISO8859_1"; + byte chars[] = s.getBytes(charset_name); + Update(chars, chars.length); + } - /** - * Update buffer with a single integer (only & 0xff part is used, - * as a byte) - * - * @param i Integer value, which is then converted to byte as i & 0xff - **/ - public void Update (int i) { - Update((byte) (i & 0xff)); - } + /** + * Update buffer with a single integer (only & 0xff part is used, + * as a byte) + * + * @param i Integer value, which is then converted to byte as i & 0xff + **/ + public void Update(int i) { + Update((byte) (i & 0xff)); + } - private byte[] Encode (int input[], int len) { - int i, j; - byte out[]; + private byte[] Encode(int input[], int len) { + int i, j; + byte out[]; - out = new byte[len]; + out = new byte[len]; - for (i = j = 0; j < len; i++, j += 4) { - out[j] = (byte) (input[i] & 0xff); - out[j + 1] = (byte) ((input[i] >>> 8) & 0xff); - out[j + 2] = (byte) ((input[i] >>> 16) & 0xff); - out[j + 3] = (byte) ((input[i] >>> 24) & 0xff); - } + for (i = j = 0; j < len; i++, j += 4) { + out[j] = (byte) (input[i] & 0xff); + out[j + 1] = (byte) ((input[i] >>> 8) & 0xff); + out[j + 2] = (byte) ((input[i] >>> 16) & 0xff); + out[j + 3] = (byte) ((input[i] >>> 24) & 0xff); + } - return out; - } + return out; + } - /** - * Returns array of bytes (16 bytes) representing hash as of the - * current state of this object. Note: getting a hash does not - * invalidate the hash object, it only creates a copy of the real - * state which is finalized. - * - * @return Array of 16 bytes, the hash of all updated bytes - **/ - public synchronized byte[] Final () { - byte bits[]; - int index, padlen; - MD5State fin; + /** + * Returns array of bytes (16 bytes) representing hash as of the + * current state of this object. Note: getting a hash does not + * invalidate the hash object, it only creates a copy of the real + * state which is finalized. + * + * @return Array of 16 bytes, the hash of all updated bytes + **/ + public synchronized byte[] Final() { + byte bits[]; + int index, padlen; + MD5State fin; - if (finals == null) { - fin = new MD5State(state); + if (finals == null) { + fin = new MD5State(state); - int[] count_ints = {(int) (fin.count << 3), (int) (fin.count >> 29)}; - bits = Encode(count_ints, 8); + int[] count_ints = {(int) (fin.count << 3), (int) (fin.count >> 29)}; + bits = Encode(count_ints, 8); - index = (int) (fin.count & 0x3f); - padlen = (index < 56) ? (56 - index) : (120 - index); + index = (int) (fin.count & 0x3f); + padlen = (index < 56) ? (56 - index) : (120 - index); - Update(fin, padding, 0, padlen); - Update(fin, bits, 0, 8); + Update(fin, padding, 0, padlen); + Update(fin, bits, 0, 8); /* Update() sets finals to null */ - finals = fin; + finals = fin; + } + + return Encode(finals.state, 16); } - return Encode(finals.state, 16); - } + private static final char[] HEX_CHARS = {'0', '1', '2', '3', + '4', '5', '6', '7', + '8', '9', 'a', 'b', + 'c', 'd', 'e', 'f',}; - private static final char[] HEX_CHARS = {'0', '1', '2', '3', - '4', '5', '6', '7', - '8', '9', 'a', 'b', - 'c', 'd', 'e', 'f',}; - - /** - * Turns array of bytes into string representing each byte as - * unsigned hex number. - * - * @param hash Array of bytes to convert to hex-string - * @return Generated hex string - */ - public static String asHex (byte hash[]) { - char buf[] = new char[hash.length * 2]; - for (int i = 0, x = 0; i < hash.length; i++) { - buf[x++] = HEX_CHARS[(hash[i] >>> 4) & 0xf]; - buf[x++] = HEX_CHARS[hash[i] & 0xf]; + /** + * Turns array of bytes into string representing each byte as + * unsigned hex number. + * + * @param hash Array of bytes to convert to hex-string + * @return Generated hex string + */ + public static String asHex(byte hash[]) { + char buf[] = new char[hash.length * 2]; + for (int i = 0, x = 0; i < hash.length; i++) { + buf[x++] = HEX_CHARS[(hash[i] >>> 4) & 0xf]; + buf[x++] = HEX_CHARS[hash[i] & 0xf]; + } + return new String(buf); } - return new String(buf); - } - /** - * Returns 32-character hex representation of this objects hash - * - * @return String of this object's hash - */ - public String asHex () { - return asHex(this.Final()); - } + /** + * Returns 32-character hex representation of this objects hash + * + * @return String of this object's hash + */ + public String asHex() { + return asHex(this.Final()); + } - public static synchronized final void initNativeLibrary (boolean disallow_lib_loading) { - if (disallow_lib_loading) { - native_lib_init_pending = false; - } else { - _initNativeLibrary(); + public static synchronized final void initNativeLibrary(boolean disallow_lib_loading) { + if (disallow_lib_loading) { + native_lib_init_pending = false; + } else { + _initNativeLibrary(); + } } - } - private static synchronized final void _initNativeLibrary () { - if (!native_lib_init_pending) return; - native_lib_loaded = _loadNativeLibrary(); - native_lib_init_pending = false; - } + private static synchronized final void _initNativeLibrary() { + if (!native_lib_init_pending) return; + native_lib_loaded = _loadNativeLibrary(); + native_lib_init_pending = false; + } - private static synchronized final boolean _loadNativeLibrary () { - try { + private static synchronized final boolean _loadNativeLibrary() { + try { - // don't try to load if the right property is set + // don't try to load if the right property is set - String prop = System.getProperty("com.twmacinta.util.MD5.NO_NATIVE_LIB"); - if (prop != null) { - prop = prop.trim(); - if (prop.equalsIgnoreCase("true") || prop.equals("1")) return false; - } + String prop = System.getProperty("com.twmacinta.util.MD5.NO_NATIVE_LIB"); + if (prop != null) { + prop = prop.trim(); + if (prop.equalsIgnoreCase("true") || prop.equals("1")) return false; + } - // the library to load can be specified as a property + // the library to load can be specified as a property - File f; - prop = System.getProperty("com.twmacinta.util.MD5.NATIVE_LIB_FILE"); - if (prop != null) { - f = new File(prop); - if (f.canRead()) { - System.load(f.getAbsolutePath()); - return true; + File f; + prop = System.getProperty("com.twmacinta.util.MD5.NATIVE_LIB_FILE"); + if (prop != null) { + f = new File(prop); + if (f.canRead()) { + System.load(f.getAbsolutePath()); + return true; + } } - } - // determine the operating system and architecture + // determine the operating system and architecture - String os_name = System.getProperty("os.name"); - String os_arch = System.getProperty("os.arch"); - if (os_name == null || os_arch == null) return false; - os_name = os_name.toLowerCase(); - os_arch = os_arch.toLowerCase(); + String os_name = System.getProperty("os.name"); + String os_arch = System.getProperty("os.arch"); + if (os_name == null || os_arch == null) return false; + os_name = os_name.toLowerCase(); + os_arch = os_arch.toLowerCase(); - // define settings which are OS arch architecture independent + // define settings which are OS arch architecture independent - File arch_lib_path = null; - String arch_libfile_suffix; + File arch_lib_path = null; + String arch_libfile_suffix; - // fill in settings for Linux on x86 + // fill in settings for Linux on x86 - if (os_name.equals("linux") && - (os_arch.equals("x86") || - os_arch.equals("i386") || - os_arch.equals("i486") || - os_arch.equals("i586") || - os_arch.equals("i686"))) { - arch_lib_path = new File(new File(new File("lib"), "arch"), "linux_x86"); - arch_libfile_suffix = ".so"; - } + if (os_name.equals("linux") && + (os_arch.equals("x86") || + os_arch.equals("i386") || + os_arch.equals("i486") || + os_arch.equals("i586") || + os_arch.equals("i686"))) { + arch_lib_path = new File(new File(new File("lib"), "arch"), "linux_x86"); + arch_libfile_suffix = ".so"; + } - // fill in settings for Windows on x86 + // fill in settings for Windows on x86 - else if (os_name.startsWith("windows ") && - (os_arch.equals("x86") || - os_arch.equals("i386") || - os_arch.equals("i486") || - os_arch.equals("i586") || - os_arch.equals("i686"))) { - arch_lib_path = new File(new File(new File("lib"), "arch"), "win32_x86"); - arch_libfile_suffix = ".dll"; - } + else if (os_name.startsWith("windows ") && + (os_arch.equals("x86") || + os_arch.equals("i386") || + os_arch.equals("i486") || + os_arch.equals("i586") || + os_arch.equals("i686"))) { + arch_lib_path = new File(new File(new File("lib"), "arch"), "win32_x86"); + arch_libfile_suffix = ".dll"; + } - // fill in settings for Mac OS X on PPC + // fill in settings for Mac OS X on PPC - else if (os_name.startsWith("mac os x") && - (os_arch.equals("ppc"))) { - arch_lib_path = new File(new File(new File("lib"), "arch"), "darwin_ppc"); - arch_libfile_suffix = ".jnilib"; - } + else if (os_name.startsWith("mac os x") && + (os_arch.equals("ppc"))) { + arch_lib_path = new File(new File(new File("lib"), "arch"), "darwin_ppc"); + arch_libfile_suffix = ".jnilib"; + } - // fill in settings for Mac OS X on x86 + // fill in settings for Mac OS X on x86 - else if (os_name.startsWith("mac os x") && - (os_arch.equals("x86") || - os_arch.equals("i386") || - os_arch.equals("i486") || - os_arch.equals("i586") || - os_arch.equals("i686"))) { - arch_lib_path = new File(new File(new File("lib"), "arch"), "darwin_x86"); - arch_libfile_suffix = ".jnilib"; - } + else if (os_name.startsWith("mac os x") && + (os_arch.equals("x86") || + os_arch.equals("i386") || + os_arch.equals("i486") || + os_arch.equals("i586") || + os_arch.equals("i686"))) { + arch_lib_path = new File(new File(new File("lib"), "arch"), "darwin_x86"); + arch_libfile_suffix = ".jnilib"; + } - // default to .so files with no architecture specific subdirectory + // default to .so files with no architecture specific subdirectory - else { - arch_libfile_suffix = ".so"; - } + else { + arch_libfile_suffix = ".so"; + } - // build the required filename + // build the required filename - String fname = "MD5" + arch_libfile_suffix; + String fname = "MD5" + arch_libfile_suffix; - // try the architecture specific directory + // try the architecture specific directory - if (arch_lib_path != null) { - f = new File(arch_lib_path, fname); + if (arch_lib_path != null) { + f = new File(arch_lib_path, fname); + if (f.canRead()) { + System.load(f.getAbsolutePath()); + return true; + } + } + + // try the "lib" subdirectory + + f = new File(new File("lib"), fname); if (f.canRead()) { System.load(f.getAbsolutePath()); return true; } - } - // try the "lib" subdirectory + // try the working directory - f = new File(new File("lib"), fname); - if (f.canRead()) { - System.load(f.getAbsolutePath()); - return true; + f = new File(fname); + if (f.canRead()) { + System.load(f.getAbsolutePath()); + return true; + } } - // try the working directory + // discard SecurityExceptions - f = new File(fname); - if (f.canRead()) { - System.load(f.getAbsolutePath()); - return true; + catch (SecurityException e) { } - } - - // discard SecurityExceptions - - catch (SecurityException e) {} - - // unable to load - return false; - } + // unable to load - /** - * Calculates and returns the hash of the contents of the given file. - **/ - public static byte[] getHash (File f) throws IOException { - if (!f.exists()) throw new FileNotFoundException(f.toString()); - InputStream close_me = null; - try { - long buf_size = f.length(); - if (buf_size < 512) buf_size = 512; - if (buf_size > 65536) buf_size = 65536; - byte[] buf = new byte[(int) buf_size]; - MD5InputStream in = new MD5InputStream(new FileInputStream(f)); - close_me = in; - while (in.read(buf) != -1); - in.close(); - return in.hash(); - } catch (IOException e) { - if (close_me != null) try { close_me.close(); } catch (Exception e2) {} - throw e; + return false; } - } - /** - * @return true iff the first 16 bytes of both hash1 and hash2 are - * equal; both hash1 and hash2 are null; or either hash - * array is less than 16 bytes in length and their lengths and - * all of their bytes are equal. - **/ - public static boolean hashesEqual (byte[] hash1, byte[] hash2) { - if (hash1 == null) return hash2 == null; - if (hash2 == null) return false; - int targ = 16; - if (hash1.length < 16) { - if (hash2.length != hash1.length) return false; - targ = hash1.length; - } else if (hash2.length < 16) { - return false; + /** + * Calculates and returns the hash of the contents of the given file. + **/ + public static byte[] getHash(File f) throws IOException { + if (!f.exists()) throw new FileNotFoundException(f.toString()); + InputStream close_me = null; + try { + long buf_size = f.length(); + if (buf_size < 512) buf_size = 512; + if (buf_size > 65536) buf_size = 65536; + byte[] buf = new byte[(int) buf_size]; + MD5InputStream in = new MD5InputStream(new FileInputStream(f)); + close_me = in; + while (in.read(buf) != -1) ; + in.close(); + return in.hash(); + } catch (IOException e) { + if (close_me != null) try { + close_me.close(); + } catch (Exception e2) { + } + throw e; + } } - for (int i = 0; i < targ; i++) { - if (hash1[i] != hash2[i]) return false; + + /** + * @return true iff the first 16 bytes of both hash1 and hash2 are + * equal; both hash1 and hash2 are null; or either hash + * array is less than 16 bytes in length and their lengths and + * all of their bytes are equal. + **/ + public static boolean hashesEqual(byte[] hash1, byte[] hash2) { + if (hash1 == null) return hash2 == null; + if (hash2 == null) return false; + int targ = 16; + if (hash1.length < 16) { + if (hash2.length != hash1.length) return false; + targ = hash1.length; + } else if (hash2.length < 16) { + return false; + } + for (int i = 0; i < targ; i++) { + if (hash1[i] != hash2[i]) return false; + } + return true; } - return true; - } -} + } } diff --git a/src/test/java/org/nuiton/util/PeriodDatesTest.java b/src/test/java/org/nuiton/util/PeriodDatesTest.java index 9722515..cfa01a6 100644 --- a/src/test/java/org/nuiton/util/PeriodDatesTest.java +++ b/src/test/java/org/nuiton/util/PeriodDatesTest.java @@ -24,12 +24,7 @@ package org.nuiton.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.After; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import java.text.DateFormat; @@ -37,7 +32,6 @@ import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.List; -import java.util.concurrent.TimeUnit; /** @author fdesbois */ public class PeriodDatesTest { @@ -49,17 +43,17 @@ public class PeriodDatesTest { @Test public void testInitDayOfMonthExtremities() { PeriodDates period = new PeriodDates(); - period.setFromDate(DateUtil.createDate(9,8,7,23,12,2010)); - period.setThruDate(DateUtil.createDate(6,5,4,26,12,2010)); + period.setFromDate(DateUtil.createDate(9, 8, 7, 23, 12, 2010)); + period.setThruDate(DateUtil.createDate(6, 5, 4, 26, 12, 2010)); period.initDayOfMonthExtremities(); - Assert.assertTrue(period.between(DateUtil.createDate(3,2,1,1,12,2010))); + Assert.assertTrue(period.between(DateUtil.createDate(3, 2, 1, 1, 12, 2010))); - Calendar lastDayOf2010 = new GregorianCalendar(2010,11,31,23,59,59); + Calendar lastDayOf2010 = new GregorianCalendar(2010, 11, 31, 23, 59, 59); lastDayOf2010.set(Calendar.MILLISECOND, 999); - Assert.assertEquals(DateUtil.createDate(0,0,0,1,12,2010), period.getFromDate()); + Assert.assertEquals(DateUtil.createDate(0, 0, 0, 1, 12, 2010), period.getFromDate()); Assert.assertEquals(lastDayOf2010.getTime(), period.getThruDate()); } @@ -75,7 +69,7 @@ public class PeriodDatesTest { DateFormat timeFormat = DateFormat.getTimeInstance(); log.info("getMonths:: time for calendarFrom : " + - timeFormat.format(cal1.getTime())); + timeFormat.format(cal1.getTime())); Calendar cal2 = DateUtil.getDefaultCalendar(new Date()); cal2.set(Calendar.DAY_OF_MONTH, 22); @@ -84,7 +78,7 @@ public class PeriodDatesTest { cal2.set(Calendar.HOUR, 4); log.info("getMonths:: time for calendarThru : " + - timeFormat.format(cal2.getTime())); + timeFormat.format(cal2.getTime())); PeriodDates period = new PeriodDates(cal1, cal2); diff --git a/src/test/java/org/nuiton/util/ReflectUtilTest.java b/src/test/java/org/nuiton/util/ReflectUtilTest.java index 81ce274..91c0949 100644 --- a/src/test/java/org/nuiton/util/ReflectUtilTest.java +++ b/src/test/java/org/nuiton/util/ReflectUtilTest.java @@ -314,7 +314,7 @@ public class ReflectUtilTest { } protected void assertGetAllDeclaredFields(Set<Field> fields, - String... fieldNames) throws NoSuchFieldException { + String... fieldNames) { Assert.assertNotNull(fields); Assert.assertEquals(fieldNames.length, fields.size()); @@ -327,7 +327,7 @@ public class ReflectUtilTest { } protected void assertGetAllDeclaredMethods(Set<Method> methods, - String... methodNames) throws NoSuchFieldException { + String... methodNames) { Assert.assertNotNull(methods); Assert.assertEquals(methodNames.length, methods.size()); @@ -341,7 +341,7 @@ public class ReflectUtilTest { protected void assertFieldAnnotation(Class<?> type, Map<Field, ? extends Annotation> fieldAnnotation, - String... fieldNames) throws NoSuchFieldException { + String... fieldNames) { Set<Field> allDeclaredFields = ReflectUtil.getAllDeclaredFields(type); @@ -357,7 +357,7 @@ public class ReflectUtilTest { protected void assertMethodAnnotation(Class<?> type, Map<Method, ? extends Annotation> fieldAnnotation, - String... methodNames) throws NoSuchMethodException { + String... methodNames) { Set<Method> allDeclaredMethods = ReflectUtil.getAllDeclaredMethods(type); diff --git a/src/test/java/org/nuiton/util/ResourceTest.java b/src/test/java/org/nuiton/util/ResourceTest.java index 67276ae..cb71803 100644 --- a/src/test/java/org/nuiton/util/ResourceTest.java +++ b/src/test/java/org/nuiton/util/ResourceTest.java @@ -25,7 +25,13 @@ package org.nuiton.util; import org.apache.commons.lang3.SystemUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.*; +import org.junit.After; +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; import org.junit.rules.TestName; import java.io.File; @@ -275,7 +281,7 @@ public class ResourceTest { // ResourceTest public static void assumeNotUnderWindows(Class<?> testClass, TestName testName) { if (SystemUtils.IS_OS_WINDOWS) { log.warn("This test " + testClass.getName() + "#" + testName.getMethodName() + - " is still not compatible with windows OS"); + " is still not compatible with windows OS"); Assume.assumeTrue(false); } } diff --git a/src/test/java/org/nuiton/util/SemVerTest.java b/src/test/java/org/nuiton/util/SemVerTest.java index 112f44b..d8d806a 100644 --- a/src/test/java/org/nuiton/util/SemVerTest.java +++ b/src/test/java/org/nuiton/util/SemVerTest.java @@ -40,7 +40,7 @@ public class SemVerTest { /** * Logger. */ - static private Log log = LogFactory.getLog(SemVerTest.class); + private static final Log log = LogFactory.getLog(SemVerTest.class); /** * Liste de toutes les versions a tester, de la plus petite a la plus grande diff --git a/src/test/java/org/nuiton/util/ZipUtilTest.java b/src/test/java/org/nuiton/util/ZipUtilTest.java index 999d5ad..21887b8 100644 --- a/src/test/java/org/nuiton/util/ZipUtilTest.java +++ b/src/test/java/org/nuiton/util/ZipUtilTest.java @@ -47,7 +47,7 @@ public class ZipUtilTest { /** * Logger. */ - private static Log log = LogFactory.getLog(ZipUtilTest.class); + private static final Log log = LogFactory.getLog(ZipUtilTest.class); protected static final File DIR = new File(System.getProperty("java.home"), "bin"); diff --git a/src/test/java/org/nuiton/util/beans/BinderFactoryTest.java b/src/test/java/org/nuiton/util/beans/BinderFactoryTest.java index 516917f..e99b59f 100644 --- a/src/test/java/org/nuiton/util/beans/BinderFactoryTest.java +++ b/src/test/java/org/nuiton/util/beans/BinderFactoryTest.java @@ -35,7 +35,7 @@ import org.junit.Test; public class BinderFactoryTest { @Before - public void setUp() throws Exception { + public void setUp() { BinderFactory.clear(); } diff --git a/src/test/java/org/nuiton/util/converter/VersionConverterTest.java b/src/test/java/org/nuiton/util/converter/VersionConverterTest.java index 39018a1..6e68090 100644 --- a/src/test/java/org/nuiton/util/converter/VersionConverterTest.java +++ b/src/test/java/org/nuiton/util/converter/VersionConverterTest.java @@ -42,11 +42,11 @@ public class VersionConverterTest { VersionConverter converter; @BeforeClass - public static void setUpClass() throws Exception { + public static void setUpClass() { } @AfterClass - public static void tearDownClass() throws Exception { + public static void tearDownClass() { } @Before diff --git a/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java b/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java index 1df6b89..d1f786f 100644 --- a/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java +++ b/src/test/java/org/nuiton/util/rmi/RmiExporterAndProxyTest.java @@ -37,7 +37,7 @@ import java.rmi.NotBoundException; public class RmiExporterAndProxyTest { /** Logger. */ - static private Log log = LogFactory.getLog(RmiExporterAndProxyTest.class); + private static final Log log = LogFactory.getLog(RmiExporterAndProxyTest.class); @Test(expected = NullPointerException.class) public void testExportNullService() throws Exception { diff --git a/src/test/resources/org/nuiton/util/fileUtilData.txt b/src/test/resources/org/nuiton/util/fileUtilData.txt index beab3a1..3ebe606 100644 --- a/src/test/resources/org/nuiton/util/fileUtilData.txt +++ b/src/test/resources/org/nuiton/util/fileUtilData.txt @@ -86,7 +86,7 @@ import java.util.regex.Pattern; public class FileUtil { // FileUtil /** Logger. */ - static private Log log = LogFactory.getLog(FileUtil.class); + private static final Log log = LogFactory.getLog(FileUtil.class); /** Encoding utilisé (peut être redéfini) */ // TODO fdesbois 2011-04-16 : Perhaps change ISO encoding by UTF-8 -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.