You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ju...@apache.org on 2009/04/28 16:57:31 UTC

svn commit: r769427 - in /lucene/tika/trunk/tika-core: pom.xml src/main/java/org/apache/tika/mime/MagicMatch.java

Author: jukka
Date: Tue Apr 28 14:57:31 2009
New Revision: 769427

URL: http://svn.apache.org/viewvc?rev=769427&view=rev
Log:
TIKA-222: Drop commons-codec dependency from tika-core

Modified:
    lucene/tika/trunk/tika-core/pom.xml
    lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/MagicMatch.java

Modified: lucene/tika/trunk/tika-core/pom.xml
URL: http://svn.apache.org/viewvc/lucene/tika/trunk/tika-core/pom.xml?rev=769427&r1=769426&r2=769427&view=diff
==============================================================================
--- lucene/tika/trunk/tika-core/pom.xml (original)
+++ lucene/tika/trunk/tika-core/pom.xml Tue Apr 28 14:57:31 2009
@@ -52,11 +52,6 @@
       <version>1.0.4</version>
     </dependency>
     <dependency>
-      <groupId>commons-codec</groupId>
-      <artifactId>commons-codec</artifactId>
-      <version>1.3</version>
-    </dependency>
-    <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
       <version>1.4</version>

Modified: lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/MagicMatch.java
URL: http://svn.apache.org/viewvc/lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/MagicMatch.java?rev=769427&r1=769426&r2=769427&view=diff
==============================================================================
--- lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/MagicMatch.java (original)
+++ lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/MagicMatch.java Tue Apr 28 14:57:31 2009
@@ -20,10 +20,6 @@
 import java.io.ByteArrayOutputStream;
 import java.math.BigInteger;
 
-// Jakarta Commons Codec imports
-import org.apache.commons.codec.DecoderException;
-import org.apache.commons.codec.binary.Hex;
-
 /**
  * Defines a magic match.
  * 
@@ -31,8 +27,6 @@
  */
 class MagicMatch implements Clause {
 
-    private final static Hex HEX_CODEC = new Hex();
-
     private int offsetStart;
 
     private int offsetEnd;
@@ -51,23 +45,18 @@
         this.offsetStart = offsetStart;
         this.offsetEnd = offsetEnd;
         this.type = type;
-        try {
-            byte[] decoded = decodeValue(type, value);
-            this.length = decoded.length;
-            this.value = new BigInteger(decoded);
-            if (mask != null) {
-                this.mask = new BigInteger(decodeValue(type, mask));
-                this.value = this.value.and(this.mask);
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-            throw new MimeTypeException(e);
+
+        byte[] decoded = decodeValue(type, value);
+        this.length = decoded.length;
+        this.value = new BigInteger(decoded);
+        if (mask != null) {
+            this.mask = new BigInteger(decodeValue(type, mask));
+            this.value = this.value.and(this.mask);
         }
     }
 
     private byte[] decodeValue(String type, String value)
-            throws DecoderException {
-
+            throws MimeTypeException {
         // Preliminary check
         if ((value == null) || (type == null)) {
             return null;
@@ -116,10 +105,14 @@
         return decoded;
     }
 
-    private byte[] decodeString(String value) throws DecoderException {
-
+    private byte[] decodeString(String value) throws MimeTypeException {
         if (value.startsWith("0x")) {
-            return HEX_CODEC.decode(value.substring(2).getBytes());
+            byte[] bytes = new byte[(value.length() - 2) / 2];
+            for (int i = 0; i < bytes.length; i++) {
+                bytes[i] = (byte)
+                    Integer.parseInt(value.substring(2 + i * 2, 4 + i * 2), 16);
+            }
+            return bytes;
         }
 
         try {
@@ -131,8 +124,8 @@
                         decoded.write('\\');
                         i++;
                     } else if (value.charAt(i + 1) == 'x') {
-                        decoded.write(HEX_CODEC.decode(value.substring(i + 2,
-                                i + 4).getBytes()));
+                        decoded.write(Integer.parseInt(
+                                value.substring(i + 2, i + 4), 16));
                         i += 3;
                     } else {
                         int j = i + 1;
@@ -149,8 +142,8 @@
                 }
             }
             return decoded.toByteArray();
-        } catch (Exception e) {
-            throw new DecoderException(e.toString() + " for " + value);
+        } catch (NumberFormatException e) {
+            throw new MimeTypeException(e.toString() + " for " + value);
         }
     }