diff --git a/.mvn/jvm.config b/.mvn/jvm.config
new file mode 100644
index 0000000000..e2a50e0834
--- /dev/null
+++ b/.mvn/jvm.config
@@ -0,0 +1 @@
+--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
\ No newline at end of file
diff --git a/tika-core/pom.xml b/tika-core/pom.xml
index 8426ac55ff..1fbef62281 100644
--- a/tika-core/pom.xml
+++ b/tika-core/pom.xml
@@ -34,6 +34,10 @@
Apache Tika corehttps://tika.apache.org/
+
+ 5.3
+
+
@@ -130,6 +134,46 @@
+
+ com.cosium.code
+ git-code-format-maven-plugin
+ ${git-code-format-maven-plugin.version}
+
+
+
+ install-formatter-hook
+
+ install-hooks
+
+
+
+
+ validate-code-format
+
+ validate-code-format
+
+
+
+
+
+
+ com.cosium.code
+ google-java-format
+ ${git-code-format-maven-plugin.version}
+
+
+
+
+ true
+ false
+ false
+ false
+
+
+
+
org.apache.felixmaven-bundle-plugin
diff --git a/tika-core/src/main/java/org/apache/tika/Tika.java b/tika-core/src/main/java/org/apache/tika/Tika.java
index 22811f9c0b..23f4769c59 100644
--- a/tika-core/src/main/java/org/apache/tika/Tika.java
+++ b/tika-core/src/main/java/org/apache/tika/Tika.java
@@ -24,9 +24,6 @@
import java.net.URL;
import java.nio.file.Path;
import java.util.Properties;
-
-import org.xml.sax.SAXException;
-
import org.apache.tika.config.TikaConfig;
import org.apache.tika.detect.Detector;
import org.apache.tika.exception.TikaException;
@@ -41,11 +38,12 @@
import org.apache.tika.parser.ParsingReader;
import org.apache.tika.sax.BodyContentHandler;
import org.apache.tika.sax.WriteOutContentHandler;
+import org.xml.sax.SAXException;
/**
- * Facade class for accessing Tika functionality. This class hides much of
- * the underlying complexity of the lower level Tika classes and provides
- * simple methods for many common parsing and type detection operations.
+ * Facade class for accessing Tika functionality. This class hides much of the underlying complexity
+ * of the lower level Tika classes and provides simple methods for many common parsing and type
+ * detection operations.
*
* @see Parser
* @see Detector
@@ -53,25 +51,18 @@
*/
public class Tika {
- /**
- * The detector instance used by this facade.
- */
+ /** The detector instance used by this facade. */
private final Detector detector;
- /**
- * The parser instance used by this facade.
- */
+ /** The parser instance used by this facade. */
private final Parser parser;
- /**
- * The Translator instance used by this facade.
- */
+ /** The Translator instance used by this facade. */
private final Translator translator;
/**
- * Maximum length of the strings returned by the parseToString methods.
- * Used to prevent out of memory problems with huge input documents.
- * The default setting is 100k characters.
+ * Maximum length of the strings returned by the parseToString methods. Used to prevent out of
+ * memory problems with huge input documents. The default setting is 100k characters.
*/
private int maxStringLength = 100 * 1000;
@@ -80,7 +71,7 @@ public class Tika {
* Translator.
*
* @param detector type detector
- * @param parser document parser
+ * @param parser document parser
* @since Apache Tika 0.8
*/
public Tika(Detector detector, Parser parser) {
@@ -92,8 +83,8 @@ public Tika(Detector detector, Parser parser) {
/**
* Creates a Tika facade using the given detector, parser, and translator instances.
*
- * @param detector type detector
- * @param parser document parser
+ * @param detector type detector
+ * @param parser document parser
* @param translator text translator
* @since Apache Tika 1.6
*/
@@ -112,16 +103,14 @@ public Tika(TikaConfig config) {
this(config.getDetector(), new AutoDetectParser(config), config.getTranslator());
}
- /**
- * Creates a Tika facade using the default configuration.
- */
+ /** Creates a Tika facade using the default configuration. */
public Tika() {
this(TikaConfig.getDefaultConfig());
}
/**
- * Creates a Tika facade using the given detector instance, the
- * default parser configuration, and the default Translator.
+ * Creates a Tika facade using the given detector instance, the default parser configuration,
+ * and the default Translator.
*
* @param detector type detector
* @since Apache Tika 0.8
@@ -130,25 +119,21 @@ public Tika(Detector detector) {
this(detector, new AutoDetectParser(detector));
}
-
/**
- * Detects the media type of the given document. The type detection is
- * based on the content of the given document stream and any given
- * document metadata. The document stream can be null,
- * in which case only the given document metadata is used for type
- * detection.
- *
- * If the document stream supports the
- * {@link InputStream#markSupported() mark feature}, then the stream is
- * marked and reset to the original position before this method returns.
- * Only a limited number of bytes are read from the stream.
- *
- * The given document stream is not closed by this method.
- *
- * Unlike in the {@link #parse(InputStream, Metadata)} method, the
- * given document metadata is not modified by this method.
+ * Detects the media type of the given document. The type detection is based on the content of
+ * the given document stream and any given document metadata. The document stream can be
+ * null, in which case only the given document metadata is used for type detection.
+ *
+ *
If the document stream supports the {@link InputStream#markSupported() mark feature}, then
+ * the stream is marked and reset to the original position before this method returns. Only a
+ * limited number of bytes are read from the stream.
*
- * @param stream the document stream, or null
+ *
The given document stream is not closed by this method.
+ *
+ *
Unlike in the {@link #parse(InputStream, Metadata)} method, the given document metadata is
+ * not modified by this method.
+ *
+ * @param stream the document stream, or null
* @param metadata document metadata
* @return detected media type
* @throws IOException if the stream can not be read
@@ -162,19 +147,17 @@ public String detect(InputStream stream, Metadata metadata) throws IOException {
}
/**
- * Detects the media type of the given document. The type detection is
- * based on the content of the given document stream and the name of the
- * document.
- *
- * If the document stream supports the
- * {@link InputStream#markSupported() mark feature}, then the stream is
- * marked and reset to the original position before this method returns.
- * Only a limited number of bytes are read from the stream.
- *
- * The given document stream is not closed by this method.
+ * Detects the media type of the given document. The type detection is based on the content of
+ * the given document stream and the name of the document.
+ *
+ *
If the document stream supports the {@link InputStream#markSupported() mark feature}, then
+ * the stream is marked and reset to the original position before this method returns. Only a
+ * limited number of bytes are read from the stream.
+ *
+ *
The given document stream is not closed by this method.
*
* @param stream the document stream
- * @param name document name
+ * @param name document name
* @return detected media type
* @throws IOException if the stream can not be read
* @since Apache Tika 0.9
@@ -186,15 +169,14 @@ public String detect(InputStream stream, String name) throws IOException {
}
/**
- * Detects the media type of the given document. The type detection is
- * based on the content of the given document stream.
- *
- * If the document stream supports the
- * {@link InputStream#markSupported() mark feature}, then the stream is
- * marked and reset to the original position before this method returns.
- * Only a limited number of bytes are read from the stream.
- *
- * The given document stream is not closed by this method.
+ * Detects the media type of the given document. The type detection is based on the content of
+ * the given document stream.
+ *
+ *
If the document stream supports the {@link InputStream#markSupported() mark feature}, then
+ * the stream is marked and reset to the original position before this method returns. Only a
+ * limited number of bytes are read from the stream.
+ *
+ *
The given document stream is not closed by this method.
*
* @param stream the document stream
* @return detected media type
@@ -205,16 +187,15 @@ public String detect(InputStream stream) throws IOException {
}
/**
- * Detects the media type of the given document. The type detection is
- * based on the first few bytes of a document and the document name.
- *
- * For best results at least a few kilobytes of the document data
- * are needed. See also the other detect() methods for better
- * alternatives when you have more than just the document prefix
- * available for type detection.
+ * Detects the media type of the given document. The type detection is based on the first few
+ * bytes of a document and the document name.
+ *
+ *
For best results at least a few kilobytes of the document data are needed. See also the
+ * other detect() methods for better alternatives when you have more than just the document
+ * prefix available for type detection.
*
* @param prefix first few bytes of the document
- * @param name document name
+ * @param name document name
* @return detected media type
* @since Apache Tika 0.9
*/
@@ -229,13 +210,12 @@ public String detect(byte[] prefix, String name) {
}
/**
- * Detects the media type of the given document. The type detection is
- * based on the first few bytes of a document.
- *
- * For best results at least a few kilobytes of the document data
- * are needed. See also the other detect() methods for better
- * alternatives when you have more than just the document prefix
- * available for type detection.
+ * Detects the media type of the given document. The type detection is based on the first few
+ * bytes of a document.
+ *
+ *
For best results at least a few kilobytes of the document data are needed. See also the
+ * other detect() methods for better alternatives when you have more than just the document
+ * prefix available for type detection.
*
* @param prefix first few bytes of the document
* @return detected media type
@@ -252,12 +232,11 @@ public String detect(byte[] prefix) {
}
/**
- * Detects the media type of the file at the given path. The type
- * detection is based on the document content and a potential known
- * file extension.
- *
- * Use the {@link #detect(String)} method when you want to detect the
- * type of the document without actually accessing the file.
+ * Detects the media type of the file at the given path. The type detection is based on the
+ * document content and a potential known file extension.
+ *
+ *
Use the {@link #detect(String)} method when you want to detect the type of the document
+ * without actually accessing the file.
*
* @param path the path of the file
* @return detected media type
@@ -271,11 +250,11 @@ public String detect(Path path) throws IOException {
}
/**
- * Detects the media type of the given file. The type detection is
- * based on the document content and a potential known file extension.
- *
- * Use the {@link #detect(String)} method when you want to detect the
- * type of the document without actually accessing the file.
+ * Detects the media type of the given file. The type detection is based on the document content
+ * and a potential known file extension.
+ *
+ *
Use the {@link #detect(String)} method when you want to detect the type of the document
+ * without actually accessing the file.
*
* @param file the file
* @return detected media type
@@ -284,19 +263,18 @@ public String detect(Path path) throws IOException {
*/
public String detect(File file) throws IOException {
Metadata metadata = new Metadata();
- try (@SuppressWarnings("deprecation") InputStream stream = TikaInputStream
- .get(file, metadata)) {
+ try (@SuppressWarnings("deprecation")
+ InputStream stream = TikaInputStream.get(file, metadata)) {
return detect(stream, metadata);
}
}
/**
- * Detects the media type of the resource at the given URL. The type
- * detection is based on the document content and a potential known
- * file extension included in the URL.
- *
- * Use the {@link #detect(String)} method when you want to detect the
- * type of the document without actually accessing the URL.
+ * Detects the media type of the resource at the given URL. The type detection is based on the
+ * document content and a potential known file extension included in the URL.
+ *
+ *
Use the {@link #detect(String)} method when you want to detect the type of the document
+ * without actually accessing the URL.
*
* @param url the URL of the resource
* @return detected media type
@@ -310,11 +288,11 @@ public String detect(URL url) throws IOException {
}
/**
- * Detects the media type of a document with the given file name.
- * The type detection is based on known file name extensions.
- *
- * The given name can also be a URL or a full file path. In such cases
- * only the file name part of the string is used for type detection.
+ * Detects the media type of a document with the given file name. The type detection is based on
+ * known file name extensions.
+ *
+ *
The given name can also be a URL or a full file path. In such cases only the file name
+ * part of the string is used for type detection.
*
* @param name the file name of the document
* @return detected media type
@@ -330,11 +308,11 @@ public String detect(String name) {
/**
* Translate the given text String to and from the given languages.
*
- * @param text The text to translate.
+ * @param text The text to translate.
* @param sourceLanguage The input text language (for example, "hi").
* @param targetLanguage The desired output language (for example, "fr").
- * @return The translated text. If translation is unavailable (client keys not set), returns
- * the same text back.
+ * @return The translated text. If translation is unavailable (client keys not set), returns the
+ * same text back.
* @see org.apache.tika.language.translate.Translator
*/
public String translate(String text, String sourceLanguage, String targetLanguage) {
@@ -346,13 +324,13 @@ public String translate(String text, String sourceLanguage, String targetLanguag
}
/**
- * Translate the given text String to the given language, attempting to auto-detect the
- * source language.
+ * Translate the given text String to the given language, attempting to auto-detect the source
+ * language.
*
- * @param text The text to translate.
+ * @param text The text to translate.
* @param targetLanguage The desired output language (for example, "en").
- * @return The translated text. If translation is unavailable (client keys not set), returns
- * the same text back.
+ * @return The translated text. If translation is unavailable (client keys not set), returns the
+ * same text back.
* @see org.apache.tika.language.translate.Translator
*/
public String translate(String text, String targetLanguage) {
@@ -363,18 +341,16 @@ public String translate(String text, String targetLanguage) {
}
}
-
/**
- * Parses the given document and returns the extracted text content.
- * Input metadata like a file name or a content type hint can be passed
- * in the given metadata instance. Metadata information extracted from
- * the document is returned in that same metadata instance.
- *
- * The returned reader will be responsible for closing the given stream.
- * The stream and any associated resources will be closed at or before
- * the time when the {@link Reader#close()} method is called.
- *
- * @param stream the document to be parsed
+ * Parses the given document and returns the extracted text content. Input metadata like a file
+ * name or a content type hint can be passed in the given metadata instance. Metadata
+ * information extracted from the document is returned in that same metadata instance.
+ *
+ *
The returned reader will be responsible for closing the given stream. The stream and any
+ * associated resources will be closed at or before the time when the {@link Reader#close()}
+ * method is called.
+ *
+ * @param stream the document to be parsed
* @param metadata where document's metadata will be populated
* @return extracted text content
* @throws IOException if the document can not be read or parsed
@@ -387,10 +363,10 @@ public Reader parse(InputStream stream, Metadata metadata) throws IOException {
/**
* Parses the given document and returns the extracted text content.
- *
- * The returned reader will be responsible for closing the given stream.
- * The stream and any associated resources will be closed at or before
- * the time when the {@link Reader#close()} method is called.
+ *
+ *
The returned reader will be responsible for closing the given stream. The stream and any
+ * associated resources will be closed at or before the time when the {@link Reader#close()}
+ * method is called.
*
* @param stream the document to be parsed
* @return extracted text content
@@ -402,11 +378,11 @@ public Reader parse(InputStream stream) throws IOException {
/**
* Parses the file at the given path and returns the extracted text content.
- *
- * Metadata information extracted from the document is returned in
- * the supplied metadata instance.
*
- * @param path the path of the file to be parsed
+ *
Metadata information extracted from the document is returned in the supplied metadata
+ * instance.
+ *
+ * @param path the path of the file to be parsed
* @param metadata where document's metadata will be populated
* @return extracted text content
* @throws IOException if the file can not be read or parsed
@@ -429,18 +405,19 @@ public Reader parse(Path path) throws IOException {
/**
* Parses the given file and returns the extracted text content.
- *
- * Metadata information extracted from the document is returned in
- * the supplied metadata instance.
*
- * @param file the file to be parsed
+ *
Metadata information extracted from the document is returned in the supplied metadata
+ * instance.
+ *
+ * @param file the file to be parsed
* @param metadata where document's metadata will be populated
* @return extracted text content
* @throws IOException if the file can not be read or parsed
* @see #parse(Path)
*/
public Reader parse(File file, Metadata metadata) throws IOException {
- @SuppressWarnings("deprecation") InputStream stream = TikaInputStream.get(file, metadata);
+ @SuppressWarnings("deprecation")
+ InputStream stream = TikaInputStream.get(file, metadata);
return parse(stream, metadata);
}
@@ -457,8 +434,7 @@ public Reader parse(File file) throws IOException {
}
/**
- * Parses the resource at the given URL and returns the extracted
- * text content.
+ * Parses the resource at the given URL and returns the extracted text content.
*
* @param url the URL of the resource to be parsed
* @return extracted text content
@@ -471,23 +447,21 @@ public Reader parse(URL url) throws IOException {
}
/**
- * Parses the given document and returns the extracted text content.
- * The given input stream is closed by this method.
- *
- * To avoid unpredictable excess memory use, the returned string contains
- * only up to {@link #getMaxStringLength()} first characters extracted
- * from the input document. Use the {@link #setMaxStringLength(int)}
- * method to adjust this limitation.
- *
- * NOTE: Unlike most other Tika methods that take an
- * {@link InputStream}, this method will close the given stream for
- * you as a convenience. With other methods you are still responsible
- * for closing the stream or a wrapper instance returned by Tika.
- *
- * @param stream the document to be parsed
+ * Parses the given document and returns the extracted text content. The given input stream is
+ * closed by this method.
+ *
+ *
To avoid unpredictable excess memory use, the returned string contains only up to {@link
+ * #getMaxStringLength()} first characters extracted from the input document. Use the {@link
+ * #setMaxStringLength(int)} method to adjust this limitation.
+ *
+ *
NOTE: Unlike most other Tika methods that take an {@link InputStream},
+ * this method will close the given stream for you as a convenience. With other methods you are
+ * still responsible for closing the stream or a wrapper instance returned by Tika.
+ *
+ * @param stream the document to be parsed
* @param metadata document metadata
* @return extracted text content
- * @throws IOException if the document can not be read
+ * @throws IOException if the document can not be read
* @throws TikaException if the document can not be parsed
*/
public String parseToString(InputStream stream, Metadata metadata)
@@ -496,24 +470,21 @@ public String parseToString(InputStream stream, Metadata metadata)
}
/**
- * Parses the given document and returns the extracted text content.
- * The given input stream is closed by this method. This method lets
- * you control the maxStringLength per call.
- *
- * To avoid unpredictable excess memory use, the returned string contains
- * only up to maxLength (parameter) first characters extracted
- * from the input document.
- *
- * NOTE: Unlike most other Tika methods that take an
- * {@link InputStream}, this method will close the given stream for
- * you as a convenience. With other methods you are still responsible
- * for closing the stream or a wrapper instance returned by Tika.
- *
- * @param stream the document to be parsed
- * @param metadata document metadata
+ * Parses the given document and returns the extracted text content. The given input stream is
+ * closed by this method. This method lets you control the maxStringLength per call.
+ *
+ *
To avoid unpredictable excess memory use, the returned string contains only up to
+ * maxLength (parameter) first characters extracted from the input document.
+ *
+ *
NOTE: Unlike most other Tika methods that take an {@link InputStream},
+ * this method will close the given stream for you as a convenience. With other methods you are
+ * still responsible for closing the stream or a wrapper instance returned by Tika.
+ *
+ * @param stream the document to be parsed
+ * @param metadata document metadata
* @param maxLength maximum length of the returned string
* @return extracted text content
- * @throws IOException if the document can not be read
+ * @throws IOException if the document can not be read
* @throws TikaException if the document can not be parsed
*/
public String parseToString(InputStream stream, Metadata metadata, int maxLength)
@@ -535,22 +506,20 @@ public String parseToString(InputStream stream, Metadata metadata, int maxLength
}
/**
- * Parses the given document and returns the extracted text content.
- * The given input stream is closed by this method.
- *
- * To avoid unpredictable excess memory use, the returned string contains
- * only up to {@link #getMaxStringLength()} first characters extracted
- * from the input document. Use the {@link #setMaxStringLength(int)}
- * method to adjust this limitation.
- *
- * NOTE: Unlike most other Tika methods that take an
- * {@link InputStream}, this method will close the given stream for
- * you as a convenience. With other methods you are still responsible
- * for closing the stream or a wrapper instance returned by Tika.
+ * Parses the given document and returns the extracted text content. The given input stream is
+ * closed by this method.
+ *
+ *
To avoid unpredictable excess memory use, the returned string contains only up to {@link
+ * #getMaxStringLength()} first characters extracted from the input document. Use the {@link
+ * #setMaxStringLength(int)} method to adjust this limitation.
+ *
+ *
NOTE: Unlike most other Tika methods that take an {@link InputStream},
+ * this method will close the given stream for you as a convenience. With other methods you are
+ * still responsible for closing the stream or a wrapper instance returned by Tika.
*
* @param stream the document to be parsed
* @return extracted text content
- * @throws IOException if the document can not be read
+ * @throws IOException if the document can not be read
* @throws TikaException if the document can not be parsed
*/
public String parseToString(InputStream stream) throws IOException, TikaException {
@@ -559,15 +528,14 @@ public String parseToString(InputStream stream) throws IOException, TikaExceptio
/**
* Parses the file at the given path and returns the extracted text content.
- *
- * To avoid unpredictable excess memory use, the returned string contains
- * only up to {@link #getMaxStringLength()} first characters extracted
- * from the input document. Use the {@link #setMaxStringLength(int)}
- * method to adjust this limitation.
+ *
+ *
To avoid unpredictable excess memory use, the returned string contains only up to {@link
+ * #getMaxStringLength()} first characters extracted from the input document. Use the {@link
+ * #setMaxStringLength(int)} method to adjust this limitation.
*
* @param path the path of the file to be parsed
* @return extracted text content
- * @throws IOException if the file can not be read
+ * @throws IOException if the file can not be read
* @throws TikaException if the file can not be parsed
*/
public String parseToString(Path path) throws IOException, TikaException {
@@ -578,36 +546,34 @@ public String parseToString(Path path) throws IOException, TikaException {
/**
* Parses the given file and returns the extracted text content.
- *
- * To avoid unpredictable excess memory use, the returned string contains
- * only up to {@link #getMaxStringLength()} first characters extracted
- * from the input document. Use the {@link #setMaxStringLength(int)}
- * method to adjust this limitation.
+ *
+ *
To avoid unpredictable excess memory use, the returned string contains only up to {@link
+ * #getMaxStringLength()} first characters extracted from the input document. Use the {@link
+ * #setMaxStringLength(int)} method to adjust this limitation.
*
* @param file the file to be parsed
* @return extracted text content
- * @throws IOException if the file can not be read
+ * @throws IOException if the file can not be read
* @throws TikaException if the file can not be parsed
* @see #parseToString(Path)
*/
public String parseToString(File file) throws IOException, TikaException {
Metadata metadata = new Metadata();
- @SuppressWarnings("deprecation") InputStream stream = TikaInputStream.get(file, metadata);
+ @SuppressWarnings("deprecation")
+ InputStream stream = TikaInputStream.get(file, metadata);
return parseToString(stream, metadata);
}
/**
- * Parses the resource at the given URL and returns the extracted
- * text content.
- *
- * To avoid unpredictable excess memory use, the returned string contains
- * only up to {@link #getMaxStringLength()} first characters extracted
- * from the input document. Use the {@link #setMaxStringLength(int)}
- * method to adjust this limitation.
+ * Parses the resource at the given URL and returns the extracted text content.
+ *
+ *
To avoid unpredictable excess memory use, the returned string contains only up to {@link
+ * #getMaxStringLength()} first characters extracted from the input document. Use the {@link
+ * #setMaxStringLength(int)} method to adjust this limitation.
*
* @param url the URL of the resource to be parsed
* @return extracted text content
- * @throws IOException if the resource can not be read
+ * @throws IOException if the resource can not be read
* @throws TikaException if the resource can not be parsed
*/
public String parseToString(URL url) throws IOException, TikaException {
@@ -617,8 +583,7 @@ public String parseToString(URL url) throws IOException, TikaException {
}
/**
- * Returns the maximum length of strings returned by the
- * parseToString methods.
+ * Returns the maximum length of strings returned by the parseToString methods.
*
* @return maximum string length, or -1 if the limit has been disabled
* @since Apache Tika 0.7
@@ -628,11 +593,9 @@ public int getMaxStringLength() {
}
/**
- * Sets the maximum length of strings returned by the parseToString
- * methods.
+ * Sets the maximum length of strings returned by the parseToString methods.
*
- * @param maxStringLength maximum string length,
- * or -1 to disable this limit
+ * @param maxStringLength maximum string length, or -1 to disable this limit
* @since Apache Tika 0.7
*/
public void setMaxStringLength(int maxStringLength) {
@@ -669,7 +632,7 @@ public Translator getTranslator() {
return translator;
}
- //--------------------------------------------------------------< Object >
+ // --------------------------------------------------------------< Object >
public String toString() {
return getString();
@@ -678,8 +641,9 @@ public String toString() {
public static String getString() {
String version = null;
- try (InputStream stream = Tika.class
- .getResourceAsStream("/META-INF/maven/org.apache.tika/tika-core/pom.properties")) {
+ try (InputStream stream =
+ Tika.class.getResourceAsStream(
+ "/META-INF/maven/org.apache.tika/tika-core/pom.properties")) {
if (stream != null) {
Properties properties = new Properties();
properties.load(stream);
@@ -694,5 +658,4 @@ public static String getString() {
return "Apache Tika";
}
}
-
}
diff --git a/tika-core/src/main/java/org/apache/tika/concurrent/ConfigurableThreadPoolExecutor.java b/tika-core/src/main/java/org/apache/tika/concurrent/ConfigurableThreadPoolExecutor.java
index 1f7c4a0567..f3a5ffadf0 100644
--- a/tika-core/src/main/java/org/apache/tika/concurrent/ConfigurableThreadPoolExecutor.java
+++ b/tika-core/src/main/java/org/apache/tika/concurrent/ConfigurableThreadPoolExecutor.java
@@ -24,9 +24,8 @@
* @since Apache Tika 1.11
*/
public interface ConfigurableThreadPoolExecutor extends ExecutorService {
-
+
public void setMaximumPoolSize(int threads);
-
- public void setCorePoolSize(int threads);
+ public void setCorePoolSize(int threads);
}
diff --git a/tika-core/src/main/java/org/apache/tika/concurrent/SimpleThreadPoolExecutor.java b/tika-core/src/main/java/org/apache/tika/concurrent/SimpleThreadPoolExecutor.java
index a4385e279e..6a7ee32cf4 100644
--- a/tika-core/src/main/java/org/apache/tika/concurrent/SimpleThreadPoolExecutor.java
+++ b/tika-core/src/main/java/org/apache/tika/concurrent/SimpleThreadPoolExecutor.java
@@ -25,11 +25,16 @@
*
* @since Apache Tika 1.11
*/
-public class SimpleThreadPoolExecutor extends ThreadPoolExecutor implements
- ConfigurableThreadPoolExecutor {
+public class SimpleThreadPoolExecutor extends ThreadPoolExecutor
+ implements ConfigurableThreadPoolExecutor {
public SimpleThreadPoolExecutor() {
- super(1, 2, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),
+ super(
+ 1,
+ 2,
+ 0L,
+ TimeUnit.SECONDS,
+ new LinkedBlockingQueue<>(),
r -> new Thread(r, "Tika Executor Thread"));
}
}
diff --git a/tika-core/src/main/java/org/apache/tika/config/ConfigBase.java b/tika-core/src/main/java/org/apache/tika/config/ConfigBase.java
index 405294faed..448f8820e9 100644
--- a/tika-core/src/main/java/org/apache/tika/config/ConfigBase.java
+++ b/tika-core/src/main/java/org/apache/tika/config/ConfigBase.java
@@ -29,23 +29,21 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
-
+import org.apache.tika.exception.TikaConfigException;
+import org.apache.tika.exception.TikaException;
+import org.apache.tika.utils.XMLReaderUtils;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
-import org.apache.tika.exception.TikaConfigException;
-import org.apache.tika.exception.TikaException;
-import org.apache.tika.utils.XMLReaderUtils;
-
-
public abstract class ConfigBase {
private static Class[] SUPPORTED_PRIMITIVES =
- new Class[]{String.class, boolean.class, long.class, int.class, double.class,
- float.class};
+ new Class[] {
+ String.class, boolean.class, long.class, int.class, double.class, float.class
+ };
/**
* Use this to build a single class, where the user specifies the instance class, e.g.
@@ -81,8 +79,9 @@ protected static T buildSingle(String itemName, Class itemClass, InputStr
* @throws TikaConfigException
* @throws IOException
*/
- protected static T buildSingle(String itemName, Class itemClass, Element properties,
- T defaultValue) throws TikaConfigException, IOException {
+ protected static T buildSingle(
+ String itemName, Class itemClass, Element properties, T defaultValue)
+ throws TikaConfigException, IOException {
NodeList children = properties.getChildNodes();
T toConfigure = null;
@@ -110,10 +109,9 @@ protected static T buildSingle(String itemName, Class itemClass, Element
return toConfigure;
}
-
/**
- * Use this to build a list of components for a composite item (e.g.
- * CompositeMetadataFilter, FetcherManager), each with their own configurations
+ * Use this to build a list of components for a composite item (e.g. CompositeMetadataFilter,
+ * FetcherManager), each with their own configurations
*
* @param compositeElementName
* @param itemName
@@ -121,8 +119,12 @@ protected static T buildSingle(String itemName, Class itemClass, Element
* @throws TikaConfigException
* @throws IOException
*/
- protected static
P buildComposite(String compositeElementName, Class
P buildComposite(String compositeElementName, Class
c
throw new TikaConfigException("could not find " + compositeElementName);
}
- private static List loadComposite(Node composite, String itemName,
- Class extends T> itemClass)
+ private static List loadComposite(
+ Node composite, String itemName, Class extends T> itemClass)
throws TikaConfigException {
NodeList children = composite.getChildNodes();
List items = new ArrayList<>();
@@ -199,14 +206,21 @@ private static T buildClass(Node node, String elementName, Class itemClass)
Class clazz = Class.forName(className);
if (!itemClass.isAssignableFrom(clazz)) {
throw new TikaConfigException(
- elementName + " with class name " + className + " must be of type '" +
- itemClass.getName() + "'");
+ elementName
+ + " with class name "
+ + className
+ + " must be of type '"
+ + itemClass.getName()
+ + "'");
}
return (T) clazz.getDeclaredConstructor().newInstance();
- } catch (InstantiationException | IllegalAccessException | ClassNotFoundException |
- NoSuchMethodException | InvocationTargetException e) {
- throw new TikaConfigException("problem loading " + elementName +
- " with class " + itemClass.getName(), e);
+ } catch (InstantiationException
+ | IllegalAccessException
+ | ClassNotFoundException
+ | NoSuchMethodException
+ | InvocationTargetException e) {
+ throw new TikaConfigException(
+ "problem loading " + elementName + " with class " + itemClass.getName(), e);
}
}
@@ -215,8 +229,9 @@ private static void setParams(Object object, Node targetNode, Set settin
setParams(object, targetNode, settings, null);
}
- private static void setParams(Object object, Node targetNode, Set settings,
- String exceptNodeName) throws TikaConfigException {
+ private static void setParams(
+ Object object, Node targetNode, Set settings, String exceptNodeName)
+ throws TikaConfigException {
NodeList children = targetNode.getChildNodes();
List params = new ArrayList<>();
for (int i = 0; i < children.getLength(); i++) {
@@ -257,7 +272,7 @@ private static void setParams(Object object, Node targetNode, Set settin
if (isPrimitive(setterClassPair.itemClass)) {
tryToSetPrimitive(object, setterClassPair, param.getTextContent());
} else {
- //tryToSetPrimitive(object, localName, txt);
+ // tryToSetPrimitive(object, localName, txt);
Object item = buildClass(param, itemName, setterClassPair.itemClass);
setParams(setterClassPair.itemClass.cast(item), param, new HashSet<>());
try {
@@ -298,8 +313,8 @@ private static boolean hasClass(Node param) {
private static SetterClassPair findSetterClassPair(Object object, String itemName)
throws TikaConfigException {
- //TODO -- we could do more with info from the node -- is it complex, does it have
- //a text value, does it have a class, etc... This works for now.
+ // TODO -- we could do more with info from the node -- is it complex, does it have
+ // a text value, does it have a class, etc... This works for now.
String setter =
"set" + itemName.substring(0, 1).toUpperCase(Locale.US) + itemName.substring(1);
Class itemClass = null;
@@ -308,7 +323,7 @@ private static SetterClassPair findSetterClassPair(Object object, String itemNam
if (setter.equals(method.getName())) {
Class>[] classes = method.getParameterTypes();
if (classes.length == 1) {
- //if both setX(String) and setX(Object), prefer setX(String)
+ // if both setX(String) and setX(Object), prefer setX(String)
if (itemClass == null || classes[0].equals(String.class)) {
itemClass = classes[0];
setterMethod = method;
@@ -319,14 +334,14 @@ private static SetterClassPair findSetterClassPair(Object object, String itemNam
if (setterMethod != null && itemClass != null) {
return new SetterClassPair(setterMethod, itemClass);
}
- //now try adders
+ // now try adders
String adder =
"add" + itemName.substring(0, 1).toUpperCase(Locale.US) + itemName.substring(1);
for (Method method : object.getClass().getMethods()) {
if (adder.equals(method.getName())) {
Class>[] classes = method.getParameterTypes();
if (classes.length == 1) {
- //if both setX(String) and setX(Object), prefer setX(String)
+ // if both setX(String) and setX(Object), prefer setX(String)
if (itemClass == null || classes[0].equals(String.class)) {
itemClass = classes[0];
setterMethod = method;
@@ -336,8 +351,14 @@ private static SetterClassPair findSetterClassPair(Object object, String itemNam
}
if (setterMethod == null && itemClass == null) {
throw new TikaConfigException(
- "Couldn't find setter '" + setter + "' or adder '" + adder + "' for " + itemName +
- " of class: " + object.getClass());
+ "Couldn't find setter '"
+ + setter
+ + "' or adder '"
+ + adder
+ + "' for "
+ + itemName
+ + " of class: "
+ + object.getClass());
}
return new SetterClassPair(setterMethod, itemClass);
}
@@ -385,8 +406,10 @@ private static void tryToSetClassList(Object object, Node node) throws TikaConfi
Method m = object.getClass().getMethod(setter, List.class);
m.invoke(object, items);
- } catch (ClassNotFoundException | InvocationTargetException | NoSuchMethodException |
- IllegalAccessException e) {
+ } catch (ClassNotFoundException
+ | InvocationTargetException
+ | NoSuchMethodException
+ | IllegalAccessException e) {
throw new TikaConfigException("couldn't build class for " + name, e);
}
}
@@ -415,8 +438,8 @@ private static void tryToSetStringList(Object object, Node param) throws TikaCon
private static void tryToSetMap(Object object, Node param) throws TikaConfigException {
String name = param.getLocalName();
- //only supports string, string at this point
- //use LinkedHashMap to keep insertion order!
+ // only supports string, string at this point
+ // use LinkedHashMap to keep insertion order!
Map map = new LinkedHashMap<>();
NodeList nodeList = param.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
@@ -450,7 +473,6 @@ private static void tryToSetMap(Object object, Node param) throws TikaConfigExce
}
map.put(key, value);
}
-
}
String setter = "set" + name.substring(0, 1).toUpperCase(Locale.US) + name.substring(1);
try {
@@ -467,11 +489,11 @@ private static boolean isMap(Node param) {
Node n = nodeList.item(i);
if (n.getNodeType() == 1) {
if (n.hasAttributes()) {
- if (n.getAttributes().getNamedItem("from") != null &&
- n.getAttributes().getNamedItem("to") != null) {
+ if (n.getAttributes().getNamedItem("from") != null
+ && n.getAttributes().getNamedItem("to") != null) {
return true;
- } else if (n.getAttributes().getNamedItem("k") != null &&
- n.getAttributes().getNamedItem("v") != null) {
+ } else if (n.getAttributes().getNamedItem("k") != null
+ && n.getAttributes().getNamedItem("v") != null) {
return true;
}
}
@@ -480,8 +502,9 @@ private static boolean isMap(Node param) {
return false;
}
- private static void tryToSetPrimitive(Object object, SetterClassPair setterClassPair,
- String value) throws TikaConfigException {
+ private static void tryToSetPrimitive(
+ Object object, SetterClassPair setterClassPair, String value)
+ throws TikaConfigException {
try {
if (setterClassPair.itemClass == int.class) {
setterClassPair.setterMethod.invoke(object, Integer.parseInt(value));
@@ -501,15 +524,13 @@ private static void tryToSetPrimitive(Object object, SetterClassPair setterClass
}
}
-
/**
- * This should be overridden to do something with the settings
- * after loading the object.
+ * This should be overridden to do something with the settings after loading the object.
*
* @param settings
*/
protected void handleSettings(Set settings) {
- //no-op
+ // no-op
}
/**
@@ -559,8 +580,12 @@ public SetterClassPair(Method setterMethod, Class itemClass) {
@Override
public String toString() {
- return "SetterClassPair{" + "setterMethod=" + setterMethod + ", itemClass=" +
- itemClass + '}';
+ return "SetterClassPair{"
+ + "setterMethod="
+ + setterMethod
+ + ", itemClass="
+ + itemClass
+ + '}';
}
}
}
diff --git a/tika-core/src/main/java/org/apache/tika/config/Field.java b/tika-core/src/main/java/org/apache/tika/config/Field.java
index 403ad6dcd3..bd52e5bbda 100644
--- a/tika-core/src/main/java/org/apache/tika/config/Field.java
+++ b/tika-core/src/main/java/org/apache/tika/config/Field.java
@@ -23,9 +23,8 @@
import java.lang.annotation.Target;
/**
- * Field annotation is a contract for binding {@link Param} value from
- * Tika Configuration to an object.
- * services
+ * Field annotation is a contract for binding {@link Param} value from Tika Configuration to an
+ * object. services
*
* @since Apache Tika 1.14
*/
diff --git a/tika-core/src/main/java/org/apache/tika/config/Initializable.java b/tika-core/src/main/java/org/apache/tika/config/Initializable.java
index f37bdd9095..df7a91d17c 100644
--- a/tika-core/src/main/java/org/apache/tika/config/Initializable.java
+++ b/tika-core/src/main/java/org/apache/tika/config/Initializable.java
@@ -17,18 +17,16 @@
package org.apache.tika.config;
import java.util.Map;
-
import org.apache.tika.exception.TikaConfigException;
/**
- * Components that must do special processing across multiple fields
- * at initialization time should implement this interface.
- *
- * TikaConfig will call initialize on Initializable classes after
- * setting the parameters for non-statically service loaded classes.
- *
- * TikaConfig will call checkInitialization on all Initializables,
- * whether loaded statically
+ * Components that must do special processing across multiple fields at initialization time should
+ * implement this interface.
+ *
+ *
TikaConfig will call initialize on Initializable classes after setting the parameters for
+ * non-statically service loaded classes.
+ *
+ *
TikaConfig will call checkInitialization on all Initializables, whether loaded statically
*/
public interface Initializable {
@@ -38,15 +36,10 @@ public interface Initializable {
*/
void initialize(Map params) throws TikaConfigException;
-
/**
- * @param problemHandler if there is a problem and no
- * custom initializableProblemHandler has been configured
- * via Initializable parameters,
- * this is called to respond.
+ * @param problemHandler if there is a problem and no custom initializableProblemHandler has
+ * been configured via Initializable parameters, this is called to respond.
* @throws TikaConfigException
*/
void checkInitialization(InitializableProblemHandler problemHandler) throws TikaConfigException;
-
-
}
diff --git a/tika-core/src/main/java/org/apache/tika/config/InitializableProblemHandler.java b/tika-core/src/main/java/org/apache/tika/config/InitializableProblemHandler.java
index fdca6901c9..8f933f300d 100644
--- a/tika-core/src/main/java/org/apache/tika/config/InitializableProblemHandler.java
+++ b/tika-core/src/main/java/org/apache/tika/config/InitializableProblemHandler.java
@@ -16,72 +16,71 @@
*/
package org.apache.tika.config;
-
-import org.slf4j.LoggerFactory;
-
import org.apache.tika.exception.TikaConfigException;
-
+import org.slf4j.LoggerFactory;
/**
- * This is to be used to handle potential recoverable problems that
- * might arise during initialization.
+ * This is to be used to handle potential recoverable problems that might arise during
+ * initialization.
*/
public interface InitializableProblemHandler {
+ /** Strategy that simply ignores all problems. */
+ InitializableProblemHandler IGNORE =
+ new InitializableProblemHandler() {
+ public void handleInitializableProblem(String className, String message) {}
- /**
- * Strategy that simply ignores all problems.
- */
- InitializableProblemHandler IGNORE = new InitializableProblemHandler() {
- public void handleInitializableProblem(String className, String message) {
- }
+ @Override
+ public String toString() {
+ return "IGNORE";
+ }
+ };
- @Override
- public String toString() {
- return "IGNORE";
- }
- };
/**
- * Strategy that logs warnings of all problems using a {@link org.slf4j.Logger}
- * created using the given class name.
+ * Strategy that logs warnings of all problems using a {@link org.slf4j.Logger} created using
+ * the given class name.
*/
- InitializableProblemHandler INFO = new InitializableProblemHandler() {
- public void handleInitializableProblem(String classname, String message) {
- LoggerFactory.getLogger(classname).info(message);
- }
+ InitializableProblemHandler INFO =
+ new InitializableProblemHandler() {
+ public void handleInitializableProblem(String classname, String message) {
+ LoggerFactory.getLogger(classname).info(message);
+ }
+
+ @Override
+ public String toString() {
+ return "INFO";
+ }
+ };
- @Override
- public String toString() {
- return "INFO";
- }
- };
/**
- * Strategy that logs warnings of all problems using a {@link org.slf4j.Logger}
- * created using the given class name.
+ * Strategy that logs warnings of all problems using a {@link org.slf4j.Logger} created using
+ * the given class name.
*/
- InitializableProblemHandler WARN = new InitializableProblemHandler() {
- public void handleInitializableProblem(String classname, String message) {
- LoggerFactory.getLogger(classname).warn(message);
- }
+ InitializableProblemHandler WARN =
+ new InitializableProblemHandler() {
+ public void handleInitializableProblem(String classname, String message) {
+ LoggerFactory.getLogger(classname).warn(message);
+ }
- @Override
- public String toString() {
- return "WARN";
- }
- };
- InitializableProblemHandler THROW = new InitializableProblemHandler() {
- public void handleInitializableProblem(String classname, String message)
- throws TikaConfigException {
- throw new TikaConfigException(message);
- }
+ @Override
+ public String toString() {
+ return "WARN";
+ }
+ };
- @Override
- public String toString() {
- return "THROW";
- }
- };
+ InitializableProblemHandler THROW =
+ new InitializableProblemHandler() {
+ public void handleInitializableProblem(String classname, String message)
+ throws TikaConfigException {
+ throw new TikaConfigException(message);
+ }
+
+ @Override
+ public String toString() {
+ return "THROW";
+ }
+ };
InitializableProblemHandler DEFAULT = WARN;
void handleInitializableProblem(String className, String message) throws TikaConfigException;
-
}
diff --git a/tika-core/src/main/java/org/apache/tika/config/LoadErrorHandler.java b/tika-core/src/main/java/org/apache/tika/config/LoadErrorHandler.java
index 666c20d23e..c134d0689e 100644
--- a/tika-core/src/main/java/org/apache/tika/config/LoadErrorHandler.java
+++ b/tika-core/src/main/java/org/apache/tika/config/LoadErrorHandler.java
@@ -16,67 +16,65 @@
*/
package org.apache.tika.config;
-
import org.slf4j.LoggerFactory;
-
/**
- * Interface for error handling strategies in service class loading.
- * You can implement this interface for a custom error handling mechanism,
- * or use one of the predefined strategies.
+ * Interface for error handling strategies in service class loading. You can implement this
+ * interface for a custom error handling mechanism, or use one of the predefined strategies.
*
* @since Apache Tika 0.9
*/
public interface LoadErrorHandler {
- /**
- * Strategy that simply ignores all problems.
- */
- LoadErrorHandler IGNORE = new LoadErrorHandler() {
- public void handleLoadError(String classname, Throwable throwable) {
- }
+ /** Strategy that simply ignores all problems. */
+ LoadErrorHandler IGNORE =
+ new LoadErrorHandler() {
+ public void handleLoadError(String classname, Throwable throwable) {}
+
+ @Override
+ public String toString() {
+ return "IGNORE";
+ }
+ };
- @Override
- public String toString() {
- return "IGNORE";
- }
- };
/**
- * Strategy that logs warnings of all problems using a {@link org.slf4j.Logger}
- * created using the given class name.
+ * Strategy that logs warnings of all problems using a {@link org.slf4j.Logger} created using
+ * the given class name.
*/
- LoadErrorHandler WARN = new LoadErrorHandler() {
- public void handleLoadError(String classname, Throwable throwable) {
- LoggerFactory.getLogger(classname).warn("Unable to load {}", classname, throwable);
- }
+ LoadErrorHandler WARN =
+ new LoadErrorHandler() {
+ public void handleLoadError(String classname, Throwable throwable) {
+ LoggerFactory.getLogger(classname)
+ .warn("Unable to load {}", classname, throwable);
+ }
+
+ @Override
+ public String toString() {
+ return "WARN";
+ }
+ };
- @Override
- public String toString() {
- return "WARN";
- }
- };
/**
- * Strategy that throws a {@link RuntimeException} with the given
- * throwable as the root cause, thus interrupting the entire service
- * loading operation.
+ * Strategy that throws a {@link RuntimeException} with the given throwable as the root cause,
+ * thus interrupting the entire service loading operation.
*/
- LoadErrorHandler THROW = new LoadErrorHandler() {
- public void handleLoadError(String classname, Throwable throwable) {
- throw new RuntimeException("Unable to load " + classname, throwable);
- }
+ LoadErrorHandler THROW =
+ new LoadErrorHandler() {
+ public void handleLoadError(String classname, Throwable throwable) {
+ throw new RuntimeException("Unable to load " + classname, throwable);
+ }
- @Override
- public String toString() {
- return "THROW";
- }
- };
+ @Override
+ public String toString() {
+ return "THROW";
+ }
+ };
/**
- * Handles a problem encountered when trying to load the specified
- * service class. The implementation can log or otherwise process
- * the given error information. If the method returns normally, then
- * the service loader simply skips this class and continues with the
- * next one.
+ * Handles a problem encountered when trying to load the specified service class. The
+ * implementation can log or otherwise process the given error information. If the method
+ * returns normally, then the service loader simply skips this class and continues with the next
+ * one.
*
* @param classname name of the service class
* @param throwable the encountered problem
diff --git a/tika-core/src/main/java/org/apache/tika/config/Param.java b/tika-core/src/main/java/org/apache/tika/config/Param.java
index 25d367fe16..0ebbc4ad43 100644
--- a/tika-core/src/main/java/org/apache/tika/config/Param.java
+++ b/tika-core/src/main/java/org/apache/tika/config/Param.java
@@ -38,24 +38,20 @@
import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-
+import org.apache.tika.exception.TikaConfigException;
+import org.apache.tika.exception.TikaException;
+import org.apache.tika.parser.multiple.AbstractMultipleParser;
+import org.apache.tika.utils.XMLReaderUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
-import org.apache.tika.exception.TikaConfigException;
-import org.apache.tika.exception.TikaException;
-import org.apache.tika.parser.multiple.AbstractMultipleParser;
-import org.apache.tika.utils.XMLReaderUtils;
-
-
/**
* This is a serializable model class for parameters from configuration file.
*
- * @param value type. Should be serializable to string and have a constructor
- * with string param
+ * @param value type. Should be serializable to string and have a constructor with string param
* @since Apache Tika 1.14
*/
public class Param implements Serializable {
@@ -88,7 +84,7 @@ public class Param implements Serializable {
wellKnownMap.put("metadataPolicy", AbstractMultipleParser.MetadataPolicy.class);
}
- //one of these two is used for serialization
+ // one of these two is used for serialization
private final List valueStrings = new ArrayList<>();
private final Map valueMap = new LinkedHashMap<>();
@@ -96,8 +92,7 @@ public class Param implements Serializable {
private String name;
private T actualValue;
- public Param() {
- }
+ public Param() {}
public Param(String name, Class type, T value) {
this.name = name;
@@ -106,7 +101,7 @@ public Param(String name, Class type, T value) {
if (List.class.isAssignableFrom(value.getClass())) {
this.valueStrings.addAll((List) value);
} else if (Map.class.isAssignableFrom(value.getClass())) {
- valueMap.putAll((Map)value);
+ valueMap.putAll((Map) value);
} else {
this.valueStrings.add(value.toString());
}
@@ -156,8 +151,8 @@ public static Param load(Node node) throws TikaConfigException {
String type = typeAttr.getTextContent();
if ("class".equals(type)) {
if (classAttr == null) {
- throw new TikaConfigException("must specify a class attribute if " +
- "type=\"class\"");
+ throw new TikaConfigException(
+ "must specify a class attribute if " + "type=\"class\"");
}
ret.setType(clazz);
} else {
@@ -180,7 +175,7 @@ public static Param load(Node node) throws TikaConfigException {
} else if (Map.class.isAssignableFrom(ret.type)) {
loadMap(ret, node);
} else {
- //allow the empty string
+ // allow the empty string
String textContent = "";
if (value != null) {
textContent = value.getTextContent();
@@ -190,12 +185,16 @@ public static Param load(Node node) throws TikaConfigException {
}
return ret;
}
- private static void loadObject(Param ret, Node root, Class clazz) throws TikaConfigException {
+
+ private static void loadObject(Param ret, Node root, Class clazz)
+ throws TikaConfigException {
try {
- ret.actualValue = (T)clazz.getDeclaredConstructor().newInstance();
- } catch (InstantiationException | IllegalAccessException | NoSuchMethodException |
- InvocationTargetException e) {
+ ret.actualValue = (T) clazz.getDeclaredConstructor().newInstance();
+ } catch (InstantiationException
+ | IllegalAccessException
+ | NoSuchMethodException
+ | InvocationTargetException e) {
throw new TikaConfigException("can't build class: " + clazz, e);
}
@@ -209,19 +208,23 @@ private static void loadObject(Param ret, Node root, Class clazz) throws
Param param = load(params.item(j));
Method method = null;
- String methodName = "set" +
- param.getName().substring(0,1).toUpperCase(Locale.US) +
- param.getName().substring(1);
+ String methodName =
+ "set"
+ + param.getName().substring(0, 1).toUpperCase(Locale.US)
+ + param.getName().substring(1);
try {
- method = ret.actualValue.getClass().getMethod(methodName,
- param.getType());
+ method =
+ ret.actualValue
+ .getClass()
+ .getMethod(methodName, param.getType());
} catch (NoSuchMethodException e) {
throw new TikaConfigException("can't find method: " + methodName, e);
}
try {
method.invoke(ret.actualValue, param.getValue());
} catch (IllegalAccessException | InvocationTargetException e) {
- throw new TikaConfigException("can't set param value: " + param.getName(), e);
+ throw new TikaConfigException(
+ "can't set param value: " + param.getName(), e);
}
}
}
@@ -247,10 +250,10 @@ private static void loadMap(Param ret, Node root) throws TikaConfigExcept
key = child.getLocalName();
value = child.getTextContent();
}
- if (((Map)ret.actualValue).containsKey(key)) {
+ if (((Map) ret.actualValue).containsKey(key)) {
throw new TikaConfigException("Duplicate keys are not allowed: " + key);
}
- ((Map)ret.actualValue).put(key, value);
+ ((Map) ret.actualValue).put(key, value);
ret.valueMap.put(key, value);
}
child = child.getNextSibling();
@@ -293,8 +296,8 @@ private static T getTypedValue(Class type, String value) {
constructor.setAccessible(true);
return constructor.newInstance(value);
} catch (NoSuchMethodException e) {
- throw new RuntimeException(type + " doesnt have a constructor that takes String arg",
- e);
+ throw new RuntimeException(
+ type + " doesnt have a constructor that takes String arg", e);
} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
throw new RuntimeException(e);
}
@@ -344,13 +347,20 @@ public T getValue() {
@Override
public String toString() {
- return "Param{" + "name='" + name + '\'' + ", valueStrings='" + valueStrings + '\'' +
- ", actualValue=" + actualValue + '}';
+ return "Param{"
+ + "name='"
+ + name
+ + '\''
+ + ", valueStrings='"
+ + valueStrings
+ + '\''
+ + ", actualValue="
+ + actualValue
+ + '}';
}
public void save(OutputStream stream) throws TransformerException, TikaException {
-
DocumentBuilder builder = XMLReaderUtils.getDocumentBuilder();
Document doc = builder.newDocument();
Element paramEl = doc.createElement("param");
@@ -381,9 +391,9 @@ public void save(Document doc, Node node) {
el.appendChild(item);
}
} else if (Map.class.isAssignableFrom(actualValue.getClass())) {
- for (Object key : ((Map)actualValue).keySet()) {
+ for (Object key : ((Map) actualValue).keySet()) {
String keyString = (String) key;
- String valueString = (String)((Map)actualValue).get(keyString);
+ String valueString = (String) ((Map) actualValue).get(keyString);
Node item = doc.createElement(keyString);
item.setTextContent(valueString);
el.appendChild(item);
@@ -392,5 +402,4 @@ public void save(Document doc, Node node) {
el.setTextContent(valueStrings.get(0));
}
}
-
}
diff --git a/tika-core/src/main/java/org/apache/tika/config/ParamField.java b/tika-core/src/main/java/org/apache/tika/config/ParamField.java
index 15e977ae6d..8a9707b479 100644
--- a/tika-core/src/main/java/org/apache/tika/config/ParamField.java
+++ b/tika-core/src/main/java/org/apache/tika/config/ParamField.java
@@ -22,12 +22,11 @@
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
-
import org.apache.tika.exception.TikaConfigException;
/**
- * This class stores metdata for {@link Field} annotation are used to map them
- * to {@link Param} at runtime
+ * This class stores metdata for {@link Field} annotation are used to map them to {@link Param} at
+ * runtime
*
* @since Apache Tika 1.14
*/
@@ -35,18 +34,20 @@ public class ParamField {
public static final String DEFAULT = "#default";
- //NOTE: since (primitive type) is NOT AssignableFrom (BoxedType),
+ // NOTE: since (primitive type) is NOT AssignableFrom (BoxedType),
// we just use boxed type for everything!
// Example : short.class.isAssignableFrom(Short.class) ? false
private static final Map, Class>> PRIMITIVE_MAP =
- new HashMap, Class>>() {{
+ new HashMap, Class>>() {
+ {
put(int.class, Integer.class);
put(short.class, Short.class);
put(boolean.class, Boolean.class);
put(long.class, Long.class);
put(float.class, Float.class);
put(double.class, Double.class);
- }};
+ }
+ };
private final String name;
private final Class> type;
private final boolean required;
@@ -94,9 +95,9 @@ public boolean isRequired() {
/**
* Sets given value to the annotated field of bean
*
- * @param bean bean with annotation for field
+ * @param bean bean with annotation for field
* @param value value of field
- * @throws IllegalAccessException when it occurs
+ * @throws IllegalAccessException when it occurs
* @throws InvocationTargetException when it occurs
*/
public void assignValue(Object bean, Object value)
@@ -117,15 +118,17 @@ private Class retrieveType() throws TikaConfigException {
if (params.length != 1) {
String msg = "Invalid setter method. Must have one and only one parameter. ";
if (setter.getName().startsWith("get")) {
- msg += "Perhaps the annotation is misplaced on " + setter.getName() +
- " while a set'X' is expected?";
+ msg +=
+ "Perhaps the annotation is misplaced on "
+ + setter.getName()
+ + " while a set'X' is expected?";
}
throw new TikaConfigException(msg);
}
type = params[0];
}
if (type.isPrimitive() && PRIMITIVE_MAP.containsKey(type)) {
- type = PRIMITIVE_MAP.get(type); //primitive types have hard time
+ type = PRIMITIVE_MAP.get(type); // primitive types have hard time
}
return type;
}
@@ -138,8 +141,9 @@ private String retrieveParamName(Field annotation) {
} else {
String setterName = setter.getName();
if (setterName.startsWith("set") && setterName.length() > 3) {
- name = setterName.substring(3, 4).toLowerCase(Locale.ROOT) +
- setterName.substring(4);
+ name =
+ setterName.substring(3, 4).toLowerCase(Locale.ROOT)
+ + setterName.substring(4);
} else {
name = setter.getName();
}
@@ -152,7 +156,14 @@ private String retrieveParamName(Field annotation) {
@Override
public String toString() {
- return "ParamField{" + "name='" + name + '\'' + ", type=" + type + ", required=" +
- required + '}';
+ return "ParamField{"
+ + "name='"
+ + name
+ + '\''
+ + ", type="
+ + type
+ + ", required="
+ + required
+ + '}';
}
}
diff --git a/tika-core/src/main/java/org/apache/tika/config/ServiceLoader.java b/tika-core/src/main/java/org/apache/tika/config/ServiceLoader.java
index acc53ca885..32e624ba2b 100644
--- a/tika-core/src/main/java/org/apache/tika/config/ServiceLoader.java
+++ b/tika-core/src/main/java/org/apache/tika/config/ServiceLoader.java
@@ -33,7 +33,6 @@
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
-
import org.apache.tika.exception.TikaConfigException;
import org.apache.tika.utils.ServiceLoaderUtils;
@@ -45,32 +44,37 @@
public class ServiceLoader {
/**
- * The dynamic set of services available in an OSGi environment.
- * Managed by the {@link TikaActivator} class and used as an additional
- * source of service instances in the {@link #loadServiceProviders(Class)}
- * method.
+ * The dynamic set of services available in an OSGi environment. Managed by the {@link
+ * TikaActivator} class and used as an additional source of service instances in the {@link
+ * #loadServiceProviders(Class)} method.
*/
private static final Map