Author: jukka
Date: Sun Oct 14 13:07:20 2007
New Revision: 584595
URL: http://svn.apache.org/viewvc?rev=584595&view=rev
Log:
TIKA-66 - Use Java 5 features in org.apache.tika.mime
- Use Java 5 generics and foreach constructs to simplify code
- Removed some unused variables and method parameters
- Other minor cleanups
Modified:
incubator/tika/trunk/CHANGES.txt
incubator/tika/trunk/src/main/java/org/apache/tika/config/TikaConfig.java
incubator/tika/trunk/src/main/java/org/apache/tika/mime/MagicMatch.java
incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeType.java
incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeTypes.java
incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeTypesReader.java
incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeUtils.java
incubator/tika/trunk/src/main/java/org/apache/tika/mime/Patterns.java
incubator/tika/trunk/src/test/java/org/apache/tika/mime/TestMimeUtils.java
Modified: incubator/tika/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/incubator/tika/trunk/CHANGES.txt?rev=584595&r1=584594&r2=584595&view=diff
==============================================================================
--- incubator/tika/trunk/CHANGES.txt (original)
+++ incubator/tika/trunk/CHANGES.txt Sun Oct 14 13:07:20 2007
@@ -104,3 +104,5 @@
47. TIKA-63 - Avoid multiple passes over the input stream in Microsoft parsers
(jukka)
+
+48. TIKA-66 - Use Java 5 features in org.apache.tika.mime (jukka)
Modified:
incubator/tika/trunk/src/main/java/org/apache/tika/config/TikaConfig.java
URL:
http://svn.apache.org/viewvc/incubator/tika/trunk/src/main/java/org/apache/tika/config/TikaConfig.java?rev=584595&r1=584594&r2=584595&view=diff
==============================================================================
--- incubator/tika/trunk/src/main/java/org/apache/tika/config/TikaConfig.java
(original)
+++ incubator/tika/trunk/src/main/java/org/apache/tika/config/TikaConfig.java
Sun Oct 14 13:07:20 2007
@@ -72,8 +72,7 @@
public TikaConfig(Element element) throws JDOMException {
Element mtr = element.getChild("mimeTypeRepository");
String mimeTypeRepoResource = mtr.getAttributeValue("resource");
- boolean magic = Boolean.valueOf(mtr.getAttributeValue("magic"));
- mimeTypeRepo = new MimeUtils(mimeTypeRepoResource, magic);
+ mimeTypeRepo = new MimeUtils(mimeTypeRepoResource);
for (Object parser : XPath.selectNodes(element, "//parser")) {
ParserConfig config = new ParserConfig((Element) parser);
Modified:
incubator/tika/trunk/src/main/java/org/apache/tika/mime/MagicMatch.java
URL:
http://svn.apache.org/viewvc/incubator/tika/trunk/src/main/java/org/apache/tika/mime/MagicMatch.java?rev=584595&r1=584594&r2=584595&view=diff
==============================================================================
--- incubator/tika/trunk/src/main/java/org/apache/tika/mime/MagicMatch.java
(original)
+++ incubator/tika/trunk/src/main/java/org/apache/tika/mime/MagicMatch.java Sun
Oct 14 13:07:20 2007
@@ -155,8 +155,6 @@
}
public boolean eval(byte[] data) {
-
- boolean ok = false;
for (int i = offsetStart; i <= offsetEnd; i++) {
if (data.length < (this.length + i)) {
// Not enough data...
@@ -181,37 +179,8 @@
}
public String toString() {
- return new StringBuffer().append("[").append(offsetStart).append(":")
- .append(offsetEnd).append("(").append(type).append(")").append(
- "-").append(mask).append("#").append(value).append("]")
- .toString();
+ return "[" + offsetStart + ":" + offsetEnd
+ + "(" + type + ")-" + mask + "#" + value + "]";
}
- private final static boolean equals(byte[] b1, byte[] b2) {
- if ((b1 != null) && (b2 != null)) {
- if (b1.length != b2.length) {
- return false;
- }
- for (int i = 0; i < b1.length; i++) {
- if (b1[i] != b2[i]) {
- return false;
- }
- }
- return true;
- }
- if ((b1 == null) && (b2 == null)) {
- return true;
- }
- return false;
- }
-
- private final static String toHexString(byte[] bytes) {
- StringBuffer buf = new StringBuffer();
- for (int i = 0; i < bytes.length; i++) {
- String str = Integer.toHexString(bytes[i]);
- buf.append((str.length() > 2) ? str.substring(str.length() - 2)
- : str);
- }
- return buf.toString();
- }
}
Modified: incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeType.java
URL:
http://svn.apache.org/viewvc/incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeType.java?rev=584595&r1=584594&r2=584595&view=diff
==============================================================================
--- incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeType.java
(original)
+++ incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeType.java Sun
Oct 14 13:07:20 2007
@@ -54,16 +54,16 @@
private Patterns patterns = null;
/** The magics associated to this Mime-Type */
- private ArrayList magics = null;
+ private ArrayList<Magic> magics = null;
/** The aliases Mime-Types for this one */
- private ArrayList aliases = null;
+ private ArrayList<String> aliases = null;
/** The root-XML associated to this Mime-Type */
- private ArrayList rootXML = null;
+ private ArrayList<RootXML> rootXML = null;
/** The sub-class-of associated to this Mime-Type */
- private ArrayList superTypes = null;
+ private ArrayList<String> superTypes = null;
/** The mime-type level (regarding its subTypes) */
private int level = 0;
@@ -127,10 +127,10 @@
this.sub = clearedSub.toLowerCase().trim();
this.name = this.primary + SEPARATOR + this.sub;
this.patterns = new Patterns();
- this.magics = new ArrayList();
- this.aliases = new ArrayList();
- this.rootXML = new ArrayList();
- this.superTypes = new ArrayList();
+ this.magics = new ArrayList<Magic>();
+ this.aliases = new ArrayList<String>();
+ this.rootXML = new ArrayList<RootXML>();
+ this.superTypes = new ArrayList<String>();
}
/**
@@ -186,7 +186,7 @@
}
buf.append("\n");
for (int i = 0; i < aliases.size(); i++) {
- buf.append("\t").append((String) aliases.get(i)).append("\n");
+ buf.append("\t").append(aliases.get(i)).append("\n");
}
buf.append("Patterns:");
String[] patterns = this.patterns.getPatterns();
@@ -203,7 +203,7 @@
}
buf.append("\n");
for (int i = 0; i < magics.size(); i++) {
- buf.append("\t").append((Magic) magics.get(i)).append("\n");
+ buf.append("\t").append(magics.get(i)).append("\n");
}
return buf.toString();
@@ -294,7 +294,7 @@
RootXML xml = null;
String content = new String(data);
for (int i = 0; i < rootXML.size(); i++) {
- xml = (RootXML) rootXML.get(i);
+ xml = rootXML.get(i);
if (xml.matches(content)) {
return true;
}
@@ -307,7 +307,7 @@
}
RootXML[] getRootXMLs() {
- return (RootXML[]) rootXML.toArray(new RootXML[rootXML.size()]);
+ return rootXML.toArray(new RootXML[rootXML.size()]);
}
void addSuperType(String type) {
@@ -324,7 +324,7 @@
* the first.
*/
public String[] getSuperTypes() {
- return (String[]) superTypes.toArray(new String[superTypes.size()]);
+ return superTypes.toArray(new String[superTypes.size()]);
}
int getLevel() {
@@ -341,11 +341,11 @@
* @return the recoginition patterns associated to this mime-type.
*/
public String[] getAliases() {
- return (String[]) aliases.toArray(new String[aliases.size()]);
+ return aliases.toArray(new String[aliases.size()]);
}
Magic[] getMagics() {
- return (Magic[]) magics.toArray(new Magic[magics.size()]);
+ return magics.toArray(new Magic[magics.size()]);
}
void addMagic(Magic magic) {
@@ -370,7 +370,7 @@
public boolean matchesMagic(byte[] data) {
for (int i = 0; i < magics.size(); i++) {
- Magic magic = (Magic) magics.get(i);
+ Magic magic = magics.get(i);
if (magic.eval(data)) {
return true;
}
Modified: incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeTypes.java
URL:
http://svn.apache.org/viewvc/incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeTypes.java?rev=584595&r1=584594&r2=584595&view=diff
==============================================================================
--- incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeTypes.java
(original)
+++ incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeTypes.java Sun
Oct 14 13:07:20 2007
@@ -19,14 +19,13 @@
// JDK imports
import java.io.File;
import java.net.URL;
+import java.util.Arrays;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
-import java.util.Iterator;
import java.util.List;
-import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
// Commons Logging imports
@@ -44,31 +43,27 @@
/** The default <code>application/octet-stream</code> MimeType */
public final static String DEFAULT = "application/octet-stream";
- /** My logger */
- private Log logger = null;
-
/** All the registered MimeTypes indexed on their name */
- private Map types = new HashMap();
+ private Map<String, MimeInfo> types = new HashMap<String, MimeInfo>();
/** The patterns matcher */
private Patterns patterns = new Patterns();
/** List of all registered magics */
- private ArrayList magics = new ArrayList();
+ private ArrayList<Magic> magics = new ArrayList<Magic>();
/** List of all registered rootXML */
- private ArrayList xmls = new ArrayList();
+ private ArrayList<MimeInfo> xmls = new ArrayList<MimeInfo>();
- private Map unsolvedDeps = new HashMap();
+ private Map<String, List<MimeInfo>> unsolvedDeps =
+ new HashMap<String, List<MimeInfo>>();
/**
* A comparator used to sort the mime types based on their magics (it is
* sorted first on the magic's priority, then on the magic's size).
*/
- final static Comparator MAGICS_COMPARATOR = new Comparator() {
- public int compare(Object o1, Object o2) {
- Magic m1 = (Magic) o1;
- Magic m2 = (Magic) o2;
+ final static Comparator<Magic> MAGICS_COMPARATOR = new Comparator<Magic>()
{
+ public int compare(Magic m1, Magic m2) {
int p1 = m1.getPriority();
int p2 = m2.getPriority();
if (p1 != p2) {
@@ -82,11 +77,12 @@
* A comparator used to sort the mime types based on their level (the level
* is the number of super-types for a type)
*/
- private final static Comparator LEVELS_COMPARATOR = new Comparator() {
- public int compare(Object o1, Object o2) {
- return ((MimeInfo) o2).getLevel() - ((MimeInfo) o1).getLevel();
- }
- };
+ private final static Comparator<MimeInfo> LEVELS_COMPARATOR =
+ new Comparator<MimeInfo>() {
+ public int compare(MimeInfo o1, MimeInfo o2) {
+ return o2.getLevel() - o1.getLevel();
+ }
+ };
/** The minimum length of data to provide to check all MimeTypes */
private int minLength = 0;
@@ -100,11 +96,6 @@
* is it Logger to uses for ouput messages.
*/
public MimeTypes(String filepath, Log logger) {
- if (logger == null) {
- this.logger = LogFactory.getLog(this.getClass());
- } else {
- this.logger = logger;
- }
MimeTypesReader reader = new MimeTypesReader(logger);
add(reader.read(filepath));
}
@@ -129,11 +120,6 @@
* is it Logger to uses for ouput messages.
*/
public MimeTypes(Document doc, Log logger) {
- if (logger == null) {
- this.logger = LogFactory.getLog(this.getClass());
- } else {
- this.logger = logger;
- }
MimeTypesReader reader = new MimeTypesReader(logger);
add(reader.read(doc));
}
@@ -211,20 +197,20 @@
}
// First, check for XML descriptions (level by level)
- for (int i = 0; i < xmls.size(); i++) {
- MimeType type = ((MimeInfo) xmls.get(i)).getType();
+ for (MimeInfo info : xmls) {
+ MimeType type = info.getType();
if (type.matchesXML(data)) {
return type;
}
}
// Then, check for magic bytes
- for (int i = 0; i < magics.size(); i++) {
- Magic magic = (Magic) magics.get(i);
+ for (Magic magic : magics) {
if (magic.eval(data)) {
return magic.getType();
}
}
+
return null;
}
@@ -246,7 +232,6 @@
* @see #getMinLength()
*/
public MimeType getMimeType(String name, byte[] data) {
-
// First, try to get the mime-type from the content
MimeType mimeType = getMimeType(data);
@@ -255,6 +240,7 @@
if (mimeType == null) {
mimeType = getMimeType(name);
}
+
return mimeType;
}
@@ -267,7 +253,7 @@
* MimeType is registered for this name.
*/
public MimeType forName(String name) {
- MimeInfo info = (MimeInfo) types.get(name);
+ MimeInfo info = types.get(name);
return (info == null) ? null : info.getType();
}
@@ -306,36 +292,32 @@
* is the mime-type to add.
*/
void add(MimeType type) {
-
if (type == null) {
return;
}
// Add the new type in the repository
MimeInfo info = new MimeInfo(type);
- types.put(info.getName(), info);
+ types.put(type.getName(), info);
// Checks for some unsolved dependencies on this new type
- List deps = (List) unsolvedDeps.get(info.getName());
+ List<MimeInfo> deps = unsolvedDeps.get(type.getName());
if (deps != null) {
int level = info.getLevel();
- for (int i = 0; i < deps.size(); i++) {
- level = Math
- .max(level, ((MimeInfo) deps.get(i)).getLevel() + 1);
+ for (MimeInfo dep : deps) {
+ level = Math.max(level, dep.getLevel() + 1);
}
info.setLevel(level);
- unsolvedDeps.remove(info.getName());
+ unsolvedDeps.remove(type.getName());
}
- // Checks if some of my super-types are not already solved
- String[] superTypes = type.getSuperTypes();
- for (int i = 0; i < superTypes.length; i++) {
- MimeInfo superType = (MimeInfo) types.get(superTypes[i]);
+ for (String name : type.getSuperTypes()) {
+ MimeInfo superType = types.get(name);
if (superType == null) {
- deps = (List) unsolvedDeps.get(superTypes[i]);
+ deps = unsolvedDeps.get(name);
if (deps == null) {
- deps = new ArrayList();
- unsolvedDeps.put(superTypes[i], deps);
+ deps = new ArrayList<MimeInfo>();
+ unsolvedDeps.put(name, deps);
}
deps.add(info);
}
@@ -347,10 +329,7 @@
patterns.add(type.getPatterns(), type);
// Update the magics index...
if (type.hasMagic()) {
- Magic[] magics = type.getMagics();
- for (int i = 0; i < magics.length; i++) {
- this.magics.add(magics[i]);
- }
+ magics.addAll(Arrays.asList(type.getMagics()));
}
Collections.sort(magics, MAGICS_COMPARATOR);
@@ -363,20 +342,18 @@
// Inherited Javadoc
public String toString() {
- StringBuffer buf = new StringBuffer();
- Iterator iter = types.values().iterator();
- while (iter.hasNext()) {
- MimeType type = ((MimeInfo) iter.next()).getType();
- buf.append(type).append("\n");
+ StringBuilder builder = new StringBuilder();
+ for (MimeInfo info : types.values()) {
+ builder.append(info.getType()).append("\n");
}
- return buf.toString();
+ return builder.toString();
}
private final class MimeInfo {
- private MimeType type = null;
+ private final MimeType type;
- private int level = 0;
+ private int level;
MimeInfo(MimeType type) {
this.type = type;
@@ -392,23 +369,18 @@
}
void setLevel(int level) {
- if (level <= this.level) {
- return;
- }
+ if (level > this.level) {
+ this.level = level;
- this.level = level;
- // Update all my super-types
- String[] supers = type.getSuperTypes();
- for (int i = 0; i < supers.length; i++) {
- MimeInfo sup = (MimeInfo) types.get(supers[i]);
- if (sup != null) {
- sup.setLevel(level + 1);
+ // Update all my super-types
+ for (String name : type.getSuperTypes()) {
+ MimeInfo info = types.get(name);
+ if (info != null) {
+ info.setLevel(level + 1);
+ }
}
}
}
- String getName() {
- return type.getName();
- }
}
}
Modified:
incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeTypesReader.java
URL:
http://svn.apache.org/viewvc/incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeTypesReader.java?rev=584595&r1=584594&r2=584595&view=diff
==============================================================================
---
incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeTypesReader.java
(original)
+++
incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeTypesReader.java
Sun Oct 14 13:07:20 2007
@@ -130,17 +130,17 @@
MimeType[] read(Document document) {
// printDOM(document);
- MimeType[] types = null;
Element element = document.getDocumentElement();
- if ((element != null) && element.getTagName().equals("mime-info")) {
- types = readMimeInfo(element);
+ if (element != null && element.getTagName().equals("mime-info")) {
+ return readMimeInfo(element);
+ } else {
+ return new MimeType[0];
}
- return (types == null) ? (new MimeType[0]) : types;
}
/** Read Element named mime-info. */
private MimeType[] readMimeInfo(Element element) {
- ArrayList types = new ArrayList();
+ ArrayList<MimeType> types = new ArrayList<MimeType>();
NodeList nodes = element.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
@@ -154,7 +154,7 @@
}
}
}
- return (MimeType[]) types.toArray(new MimeType[types.size()]);
+ return types.toArray(new MimeType[types.size()]);
}
/** Read Element named mime-type. */
Modified: incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeUtils.java
URL:
http://svn.apache.org/viewvc/incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeUtils.java?rev=584595&r1=584594&r2=584595&view=diff
==============================================================================
--- incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeUtils.java
(original)
+++ incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeUtils.java Sun
Oct 14 13:07:20 2007
@@ -38,18 +38,11 @@
private final static Logger LOG = Logger.getLogger(MimeUtils.class
.getName());
- /** The key used to cache the mime repository in conf */
- private final static String KEY = MimeUtils.class.getName();
-
- /** A flag that tells if magic resolution must be performed */
- private boolean magic = true;
-
/** The MimeTypes repository instance */
private MimeTypes repository = null;
/** Creates a new instance of MimeUtils */
- public MimeUtils(String resPath, boolean magic) {
- this.magic = magic;
+ public MimeUtils(String resPath) {
if(repository == null){
repository = load(resPath);
}
Modified: incubator/tika/trunk/src/main/java/org/apache/tika/mime/Patterns.java
URL:
http://svn.apache.org/viewvc/incubator/tika/trunk/src/main/java/org/apache/tika/mime/Patterns.java?rev=584595&r1=584594&r2=584595&view=diff
==============================================================================
--- incubator/tika/trunk/src/main/java/org/apache/tika/mime/Patterns.java
(original)
+++ incubator/tika/trunk/src/main/java/org/apache/tika/mime/Patterns.java Sun
Oct 14 13:07:20 2007
@@ -19,50 +19,45 @@
// JDK imports
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
/**
* Defines a MimeType pattern.
- *
- *
*/
class Patterns {
- private static Map escapeMap = new HashMap();
+ private static Map<Character, String> escapeMap =
+ new HashMap<Character, String>();
+
static {
- escapeMap.put("\\", "\\\\");
- escapeMap.put("?", "\\?");
- escapeMap.put("[", "\\[");
- escapeMap.put("]", "\\]");
- escapeMap.put("^", "\\^");
- escapeMap.put(".", "\\.");
- escapeMap.put("-", "\\-");
- escapeMap.put("$", "\\$");
- escapeMap.put("+", "\\+");
- escapeMap.put("(", "\\(");
- escapeMap.put(")", "\\)");
- escapeMap.put("{", "\\{");
- escapeMap.put("}", "\\}");
- escapeMap.put("|", "\\|");
- escapeMap.put("*", ".*");
+ escapeMap.put('\\', "\\\\");
+ escapeMap.put('?', "\\?");
+ escapeMap.put('[', "\\[");
+ escapeMap.put(']', "\\]");
+ escapeMap.put('^', "\\^");
+ escapeMap.put('.', "\\.");
+ escapeMap.put('-', "\\-");
+ escapeMap.put('$', "\\$");
+ escapeMap.put('+', "\\+");
+ escapeMap.put('(', "\\(");
+ escapeMap.put(')', "\\)");
+ escapeMap.put('{', "\\{");
+ escapeMap.put('}', "\\}");
+ escapeMap.put('|', "\\|");
+ escapeMap.put('*', ".*");
}
/** Gathers all the patterns */
- private ArrayList patterns = new ArrayList();
+ private ArrayList<String> patterns = new ArrayList<String>();
/** An index of exact matching patterns */
- private Map exactIdx = new HashMap();
+ private Map<String, MimeType> exactIdx = new HashMap<String, MimeType>();
/** An index of the patterns of the form "*.ext" */
- private Map extIdx = new HashMap();
+ private Map<String, MimeType> extIdx = new HashMap<String, MimeType>();
/** A list of other patterns */
- private Map others = new HashMap();
-
- /** Creates a new instance of Patterns */
- Patterns() {
- }
+ private Map<String, MimeType> others = new HashMap<String, MimeType>();
void add(String[] patterns, MimeType type) {
// Some preliminary checks
@@ -70,8 +65,8 @@
return;
}
// All is ok, so add the patterns
- for (int i = 0; i < patterns.length; i++) {
- add(patterns[i], type);
+ for (String pattern : patterns) {
+ add(pattern, type);
}
}
@@ -85,10 +80,8 @@
if ((pattern.indexOf('*') == -1) && (pattern.indexOf('?') == -1)
&& (pattern.indexOf('[') == -1)) {
exactIdx.put(pattern, type);
-
} else if (pattern.startsWith("*.")) {
extIdx.put(pattern.substring(2), type);
-
} else {
others.put(escape(pattern), type);
}
@@ -97,7 +90,7 @@
}
String[] getPatterns() {
- return (String[]) patterns.toArray(new String[patterns.size()]);
+ return patterns.toArray(new String[patterns.size()]);
}
/**
@@ -122,7 +115,7 @@
}
// First, try exact match of the provided filename
- MimeType type = (MimeType) exactIdx.get(filename);
+ MimeType type = exactIdx.get(filename);
if (type != null) {
return type;
}
@@ -130,14 +123,14 @@
// Then try exact match with only the filename
String str = last(filename, '/');
if (str != null) {
- type = (MimeType) exactIdx.get(str);
+ type = exactIdx.get(str);
if (type != null) {
return type;
}
}
str = last(filename, '\\');
if (str != null) {
- type = (MimeType) exactIdx.get(str);
+ type = exactIdx.get(str);
if (type != null) {
return type;
}
@@ -146,7 +139,7 @@
// Then try "extension" (*.xxx) matching
int idx = filename.indexOf('.', 0);
while (idx != -1) {
- type = (MimeType) extIdx.get(filename.substring(idx + 1));
+ type = extIdx.get(filename.substring(idx + 1));
if (type != null) {
return type;
}
@@ -155,16 +148,14 @@
// And finally, try complex regexp matching
String longest = null;
- Iterator iter = others.keySet().iterator();
- while (iter.hasNext()) {
- String pattern = (String) iter.next();
+ for (String pattern : others.keySet()) {
if ((filename.matches(pattern))
&& (pattern.length() > longest.length())) {
longest = pattern;
}
}
if (longest != null) {
- type = (MimeType) others.get(longest);
+ type = others.get(longest);
}
return type;
}
@@ -181,11 +172,10 @@
}
private final static String escape(String str) {
- char[] chars = str.toCharArray();
StringBuffer result = new StringBuffer(str.length());
for (int i = 0; i < str.length(); i++) {
String charAt = String.valueOf(str.charAt(i));
- String replace = (String) escapeMap.get(charAt);
+ String replace = escapeMap.get(charAt);
result.append((replace != null) ? replace : charAt);
}
return result.toString();
Modified:
incubator/tika/trunk/src/test/java/org/apache/tika/mime/TestMimeUtils.java
URL:
http://svn.apache.org/viewvc/incubator/tika/trunk/src/test/java/org/apache/tika/mime/TestMimeUtils.java?rev=584595&r1=584594&r2=584595&view=diff
==============================================================================
--- incubator/tika/trunk/src/test/java/org/apache/tika/mime/TestMimeUtils.java
(original)
+++ incubator/tika/trunk/src/test/java/org/apache/tika/mime/TestMimeUtils.java
Sun Oct 14 13:07:20 2007
@@ -37,8 +37,6 @@
private static final String tikaMimeFile =
"org/apache/tika/mime/tika-mimetypes.xml";
- private static final boolean magic = false;
-
private static URL u;
static {
@@ -54,7 +52,7 @@
private MimeUtils utils;
public TestMimeUtils() {
- utils = new MimeUtils(tikaMimeFile, magic);
+ utils = new MimeUtils(tikaMimeFile);
assertNotNull(utils);
}