You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2016/06/29 11:11:39 UTC
[33/39] tika git commit: Convert new lines from windows to unix
http://git-wip-us.apache.org/repos/asf/tika/blob/c7a6bcac/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/image/ImageParser.java
----------------------------------------------------------------------
diff --git a/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/image/ImageParser.java b/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/image/ImageParser.java
index e42f542..8fd23eb 100644
--- a/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/image/ImageParser.java
+++ b/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/image/ImageParser.java
@@ -1,203 +1,203 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tika.parser.image;
-
-import javax.imageio.IIOException;
-import javax.imageio.ImageIO;
-import javax.imageio.ImageReader;
-import javax.imageio.metadata.IIOMetadata;
-import javax.imageio.stream.ImageInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.apache.commons.io.input.CloseShieldInputStream;
-import org.apache.tika.exception.TikaException;
-import org.apache.tika.metadata.Metadata;
-import org.apache.tika.metadata.Property;
-import org.apache.tika.metadata.TikaCoreProperties;
-import org.apache.tika.mime.MediaType;
-import org.apache.tika.parser.AbstractParser;
-import org.apache.tika.parser.ParseContext;
-import org.apache.tika.sax.XHTMLContentHandler;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-
-public class ImageParser extends AbstractParser {
-
- /**
- * Serial version UID
- */
- private static final long serialVersionUID = 7852529269245520335L;
-
- private static final MediaType CANONICAL_BMP_TYPE = MediaType.image("x-ms-bmp");
- private static final MediaType JAVA_BMP_TYPE = MediaType.image("bmp");
-
- private static final Set<MediaType> SUPPORTED_TYPES =
- Collections.unmodifiableSet(new HashSet<MediaType>(Arrays.asList(
- CANONICAL_BMP_TYPE,
- JAVA_BMP_TYPE,
- MediaType.image("gif"),
- MediaType.image("png"),
- MediaType.image("vnd.wap.wbmp"),
- MediaType.image("x-icon"),
- MediaType.image("x-xcf"))));
-
- private static void setIfPresent(Metadata metadata, String imageIOkey, String tikaKey) {
- if (metadata.get(imageIOkey) != null) {
- metadata.set(tikaKey, metadata.get(imageIOkey));
- }
- }
-
- private static void setIfPresent(Metadata metadata, String imageIOkey, Property tikaProp) {
- if (metadata.get(imageIOkey) != null) {
- String v = metadata.get(imageIOkey);
- if (v.endsWith(" ")) {
- v = v.substring(0, v.lastIndexOf(' '));
- }
- metadata.set(tikaProp, v);
- }
- }
-
- private static void loadMetadata(IIOMetadata imageMetadata, Metadata metadata) {
- String[] names = imageMetadata.getMetadataFormatNames();
- if (names == null) {
- return;
- }
- for (String name : names) {
- loadNode(metadata, imageMetadata.getAsTree(name), "", false);
- }
- }
-
- private static void loadNode(
- Metadata metadata, Node node, String parents,
- boolean addThisNodeName) {
- if (addThisNodeName) {
- if (parents.length() > 0) {
- parents += " ";
- }
- parents += node.getNodeName();
- }
- NamedNodeMap map = node.getAttributes();
- if (map != null) {
-
- int length = map.getLength();
- if (length == 1) {
- metadata.add(parents, normalize(map.item(0).getNodeValue()));
- } else if (length > 1) {
- StringBuilder value = new StringBuilder();
- for (int i = 0; i < length; i++) {
- if (i > 0) {
- value.append(", ");
- }
- Node attr = map.item(i);
- value.append(attr.getNodeName());
- value.append("=");
- value.append(normalize(attr.getNodeValue()));
- }
- metadata.add(parents, value.toString());
- }
- }
-
- Node child = node.getFirstChild();
- while (child != null) {
- // print children recursively
- loadNode(metadata, child, parents, true);
- child = child.getNextSibling();
- }
- }
-
- private static String normalize(String value) {
- if (value != null) {
- value = value.trim();
- } else {
- value = "";
- }
- if (Boolean.TRUE.toString().equalsIgnoreCase(value)) {
- return Boolean.TRUE.toString();
- } else if (Boolean.FALSE.toString().equalsIgnoreCase(value)) {
- return Boolean.FALSE.toString();
- }
- return value;
- }
-
- public Set<MediaType> getSupportedTypes(ParseContext context) {
- return SUPPORTED_TYPES;
- }
-
- public void parse(
- InputStream stream, ContentHandler handler,
- Metadata metadata, ParseContext context)
- throws IOException, SAXException, TikaException {
- String type = metadata.get(Metadata.CONTENT_TYPE);
- if (type != null) {
- // Java has a different idea of the BMP mime type to
- // what the canonical one is, fix this up.
- if (CANONICAL_BMP_TYPE.toString().equals(type)) {
- type = JAVA_BMP_TYPE.toString();
- }
-
- try {
- Iterator<ImageReader> iterator =
- ImageIO.getImageReadersByMIMEType(type);
- if (iterator.hasNext()) {
- ImageReader reader = iterator.next();
- try {
- try (ImageInputStream imageStream = ImageIO.createImageInputStream(
- new CloseShieldInputStream(stream))) {
- reader.setInput(imageStream);
-
- metadata.set(Metadata.IMAGE_WIDTH, Integer.toString(reader.getWidth(0)));
- metadata.set(Metadata.IMAGE_LENGTH, Integer.toString(reader.getHeight(0)));
- metadata.set("height", Integer.toString(reader.getHeight(0)));
- metadata.set("width", Integer.toString(reader.getWidth(0)));
-
- loadMetadata(reader.getImageMetadata(0), metadata);
- }
- } finally {
- reader.dispose();
- }
- }
-
- // Translate certain Metadata tags from the ImageIO
- // specific namespace into the general Tika one
- setIfPresent(metadata, "CommentExtensions CommentExtension", TikaCoreProperties.COMMENTS);
- setIfPresent(metadata, "markerSequence com", TikaCoreProperties.COMMENTS);
- setIfPresent(metadata, "Data BitsPerSample", Metadata.BITS_PER_SAMPLE);
- } catch (IIOException e) {
- // TIKA-619: There is a known bug in the Sun API when dealing with GIF images
- // which Tika will just ignore.
- if (!(e.getMessage() != null &&
- e.getMessage().equals("Unexpected block type 0!") &&
- type.equals("image/gif"))) {
- throw new TikaException(type + " parse error", e);
- }
- }
- }
-
- XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
- xhtml.startDocument();
- xhtml.endDocument();
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.parser.image;
+
+import javax.imageio.IIOException;
+import javax.imageio.ImageIO;
+import javax.imageio.ImageReader;
+import javax.imageio.metadata.IIOMetadata;
+import javax.imageio.stream.ImageInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.commons.io.input.CloseShieldInputStream;
+import org.apache.tika.exception.TikaException;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.metadata.Property;
+import org.apache.tika.metadata.TikaCoreProperties;
+import org.apache.tika.mime.MediaType;
+import org.apache.tika.parser.AbstractParser;
+import org.apache.tika.parser.ParseContext;
+import org.apache.tika.sax.XHTMLContentHandler;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+public class ImageParser extends AbstractParser {
+
+ /**
+ * Serial version UID
+ */
+ private static final long serialVersionUID = 7852529269245520335L;
+
+ private static final MediaType CANONICAL_BMP_TYPE = MediaType.image("x-ms-bmp");
+ private static final MediaType JAVA_BMP_TYPE = MediaType.image("bmp");
+
+ private static final Set<MediaType> SUPPORTED_TYPES =
+ Collections.unmodifiableSet(new HashSet<MediaType>(Arrays.asList(
+ CANONICAL_BMP_TYPE,
+ JAVA_BMP_TYPE,
+ MediaType.image("gif"),
+ MediaType.image("png"),
+ MediaType.image("vnd.wap.wbmp"),
+ MediaType.image("x-icon"),
+ MediaType.image("x-xcf"))));
+
+ private static void setIfPresent(Metadata metadata, String imageIOkey, String tikaKey) {
+ if (metadata.get(imageIOkey) != null) {
+ metadata.set(tikaKey, metadata.get(imageIOkey));
+ }
+ }
+
+ private static void setIfPresent(Metadata metadata, String imageIOkey, Property tikaProp) {
+ if (metadata.get(imageIOkey) != null) {
+ String v = metadata.get(imageIOkey);
+ if (v.endsWith(" ")) {
+ v = v.substring(0, v.lastIndexOf(' '));
+ }
+ metadata.set(tikaProp, v);
+ }
+ }
+
+ private static void loadMetadata(IIOMetadata imageMetadata, Metadata metadata) {
+ String[] names = imageMetadata.getMetadataFormatNames();
+ if (names == null) {
+ return;
+ }
+ for (String name : names) {
+ loadNode(metadata, imageMetadata.getAsTree(name), "", false);
+ }
+ }
+
+ private static void loadNode(
+ Metadata metadata, Node node, String parents,
+ boolean addThisNodeName) {
+ if (addThisNodeName) {
+ if (parents.length() > 0) {
+ parents += " ";
+ }
+ parents += node.getNodeName();
+ }
+ NamedNodeMap map = node.getAttributes();
+ if (map != null) {
+
+ int length = map.getLength();
+ if (length == 1) {
+ metadata.add(parents, normalize(map.item(0).getNodeValue()));
+ } else if (length > 1) {
+ StringBuilder value = new StringBuilder();
+ for (int i = 0; i < length; i++) {
+ if (i > 0) {
+ value.append(", ");
+ }
+ Node attr = map.item(i);
+ value.append(attr.getNodeName());
+ value.append("=");
+ value.append(normalize(attr.getNodeValue()));
+ }
+ metadata.add(parents, value.toString());
+ }
+ }
+
+ Node child = node.getFirstChild();
+ while (child != null) {
+ // print children recursively
+ loadNode(metadata, child, parents, true);
+ child = child.getNextSibling();
+ }
+ }
+
+ private static String normalize(String value) {
+ if (value != null) {
+ value = value.trim();
+ } else {
+ value = "";
+ }
+ if (Boolean.TRUE.toString().equalsIgnoreCase(value)) {
+ return Boolean.TRUE.toString();
+ } else if (Boolean.FALSE.toString().equalsIgnoreCase(value)) {
+ return Boolean.FALSE.toString();
+ }
+ return value;
+ }
+
+ public Set<MediaType> getSupportedTypes(ParseContext context) {
+ return SUPPORTED_TYPES;
+ }
+
+ public void parse(
+ InputStream stream, ContentHandler handler,
+ Metadata metadata, ParseContext context)
+ throws IOException, SAXException, TikaException {
+ String type = metadata.get(Metadata.CONTENT_TYPE);
+ if (type != null) {
+ // Java has a different idea of the BMP mime type to
+ // what the canonical one is, fix this up.
+ if (CANONICAL_BMP_TYPE.toString().equals(type)) {
+ type = JAVA_BMP_TYPE.toString();
+ }
+
+ try {
+ Iterator<ImageReader> iterator =
+ ImageIO.getImageReadersByMIMEType(type);
+ if (iterator.hasNext()) {
+ ImageReader reader = iterator.next();
+ try {
+ try (ImageInputStream imageStream = ImageIO.createImageInputStream(
+ new CloseShieldInputStream(stream))) {
+ reader.setInput(imageStream);
+
+ metadata.set(Metadata.IMAGE_WIDTH, Integer.toString(reader.getWidth(0)));
+ metadata.set(Metadata.IMAGE_LENGTH, Integer.toString(reader.getHeight(0)));
+ metadata.set("height", Integer.toString(reader.getHeight(0)));
+ metadata.set("width", Integer.toString(reader.getWidth(0)));
+
+ loadMetadata(reader.getImageMetadata(0), metadata);
+ }
+ } finally {
+ reader.dispose();
+ }
+ }
+
+ // Translate certain Metadata tags from the ImageIO
+ // specific namespace into the general Tika one
+ setIfPresent(metadata, "CommentExtensions CommentExtension", TikaCoreProperties.COMMENTS);
+ setIfPresent(metadata, "markerSequence com", TikaCoreProperties.COMMENTS);
+ setIfPresent(metadata, "Data BitsPerSample", Metadata.BITS_PER_SAMPLE);
+ } catch (IIOException e) {
+ // TIKA-619: There is a known bug in the Sun API when dealing with GIF images
+ // which Tika will just ignore.
+ if (!(e.getMessage() != null &&
+ e.getMessage().equals("Unexpected block type 0!") &&
+ type.equals("image/gif"))) {
+ throw new TikaException(type + " parse error", e);
+ }
+ }
+ }
+
+ XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
+ xhtml.startDocument();
+ xhtml.endDocument();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tika/blob/c7a6bcac/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/image/MetadataFields.java
----------------------------------------------------------------------
diff --git a/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/image/MetadataFields.java b/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/image/MetadataFields.java
index c3b0fce..5238751 100644
--- a/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/image/MetadataFields.java
+++ b/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/image/MetadataFields.java
@@ -1,84 +1,84 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tika.parser.image;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.HashSet;
-
-import org.apache.tika.metadata.Metadata;
-import org.apache.tika.metadata.Property;
-import org.apache.tika.metadata.TikaCoreProperties;
-
-/**
- * Knowns about all declared {@link Metadata} fields.
- * Didn't find this functionality anywhere so it was added for
- * ImageMetadataExtractor, but it can be generalized.
- */
-public abstract class MetadataFields {
-
- private static HashSet<String> known;
-
- static {
- known = new HashSet<String>();
- setKnownForClass(TikaCoreProperties.class);
- setKnownForClass(Metadata.class);
- }
-
- private static void setKnownForClass(Class<?> clazz) {
- Field[] fields = clazz.getFields();
- for (Field f : fields) {
- int mod = f.getModifiers();
- if (Modifier.isPublic(mod) && Modifier.isStatic(mod) && Modifier.isFinal(mod)) {
- Class<?> c = f.getType();
- if (String.class.equals(c)) {
- try {
- String p = (String) f.get(null);
- if (p != null) {
- known.add(p);
- }
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- }
- if (Property.class.isAssignableFrom(c)) {
- try {
- Property p = (Property) f.get(null);
- if (p != null) {
- known.add(p.getName());
- }
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
-
- public static boolean isMetadataField(String name) {
- return known.contains(name);
- }
-
- public static boolean isMetadataField(Property property) {
- return known.contains(property.getName());
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.parser.image;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.HashSet;
+
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.metadata.Property;
+import org.apache.tika.metadata.TikaCoreProperties;
+
+/**
+ * Knowns about all declared {@link Metadata} fields.
+ * Didn't find this functionality anywhere so it was added for
+ * ImageMetadataExtractor, but it can be generalized.
+ */
+public abstract class MetadataFields {
+
+ private static HashSet<String> known;
+
+ static {
+ known = new HashSet<String>();
+ setKnownForClass(TikaCoreProperties.class);
+ setKnownForClass(Metadata.class);
+ }
+
+ private static void setKnownForClass(Class<?> clazz) {
+ Field[] fields = clazz.getFields();
+ for (Field f : fields) {
+ int mod = f.getModifiers();
+ if (Modifier.isPublic(mod) && Modifier.isStatic(mod) && Modifier.isFinal(mod)) {
+ Class<?> c = f.getType();
+ if (String.class.equals(c)) {
+ try {
+ String p = (String) f.get(null);
+ if (p != null) {
+ known.add(p);
+ }
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ }
+ if (Property.class.isAssignableFrom(c)) {
+ try {
+ Property p = (Property) f.get(null);
+ if (p != null) {
+ known.add(p.getName());
+ }
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+ public static boolean isMetadataField(String name) {
+ return known.contains(name);
+ }
+
+ public static boolean isMetadataField(Property property) {
+ return known.contains(property.getName());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tika/blob/c7a6bcac/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/image/TiffParser.java
----------------------------------------------------------------------
diff --git a/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/image/TiffParser.java b/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/image/TiffParser.java
index c98ce69..05dee1f 100644
--- a/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/image/TiffParser.java
+++ b/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/image/TiffParser.java
@@ -1,68 +1,68 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tika.parser.image;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collections;
-import java.util.Set;
-
-import org.apache.tika.exception.TikaException;
-import org.apache.tika.io.TemporaryResources;
-import org.apache.tika.io.TikaInputStream;
-import org.apache.tika.metadata.Metadata;
-import org.apache.tika.mime.MediaType;
-import org.apache.tika.parser.AbstractParser;
-import org.apache.tika.parser.ParseContext;
-import org.apache.tika.parser.xmp.JempboxExtractor;
-import org.apache.tika.sax.XHTMLContentHandler;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-
-public class TiffParser extends AbstractParser {
-
- /**
- * Serial version UID
- */
- private static final long serialVersionUID = -3941143576535464926L;
-
- private static final Set<MediaType> SUPPORTED_TYPES =
- Collections.singleton(MediaType.image("tiff"));
-
- public Set<MediaType> getSupportedTypes(ParseContext context) {
- return SUPPORTED_TYPES;
- }
-
- public void parse(
- InputStream stream, ContentHandler handler,
- Metadata metadata, ParseContext context)
- throws IOException, SAXException, TikaException {
- TemporaryResources tmp = new TemporaryResources();
- try {
- TikaInputStream tis = TikaInputStream.get(stream, tmp);
- new ImageMetadataExtractor(metadata).parseTiff(tis.getFile());
- new JempboxExtractor(metadata).parse(tis);
- } finally {
- tmp.dispose();
- }
-
- XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
- xhtml.startDocument();
- xhtml.endDocument();
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.parser.image;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.Set;
+
+import org.apache.tika.exception.TikaException;
+import org.apache.tika.io.TemporaryResources;
+import org.apache.tika.io.TikaInputStream;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.mime.MediaType;
+import org.apache.tika.parser.AbstractParser;
+import org.apache.tika.parser.ParseContext;
+import org.apache.tika.parser.xmp.JempboxExtractor;
+import org.apache.tika.sax.XHTMLContentHandler;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+public class TiffParser extends AbstractParser {
+
+ /**
+ * Serial version UID
+ */
+ private static final long serialVersionUID = -3941143576535464926L;
+
+ private static final Set<MediaType> SUPPORTED_TYPES =
+ Collections.singleton(MediaType.image("tiff"));
+
+ public Set<MediaType> getSupportedTypes(ParseContext context) {
+ return SUPPORTED_TYPES;
+ }
+
+ public void parse(
+ InputStream stream, ContentHandler handler,
+ Metadata metadata, ParseContext context)
+ throws IOException, SAXException, TikaException {
+ TemporaryResources tmp = new TemporaryResources();
+ try {
+ TikaInputStream tis = TikaInputStream.get(stream, tmp);
+ new ImageMetadataExtractor(metadata).parseTiff(tis.getFile());
+ new JempboxExtractor(metadata).parse(tis);
+ } finally {
+ tmp.dispose();
+ }
+
+ XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
+ xhtml.startDocument();
+ xhtml.endDocument();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tika/blob/c7a6bcac/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/jpeg/JpegParser.java
----------------------------------------------------------------------
diff --git a/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/jpeg/JpegParser.java b/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/jpeg/JpegParser.java
index 247194e..7ec666c 100644
--- a/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/jpeg/JpegParser.java
+++ b/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/jpeg/JpegParser.java
@@ -1,69 +1,69 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tika.parser.jpeg;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collections;
-import java.util.Set;
-
-import org.apache.tika.exception.TikaException;
-import org.apache.tika.io.TemporaryResources;
-import org.apache.tika.io.TikaInputStream;
-import org.apache.tika.metadata.Metadata;
-import org.apache.tika.mime.MediaType;
-import org.apache.tika.parser.AbstractParser;
-import org.apache.tika.parser.ParseContext;
-import org.apache.tika.parser.image.ImageMetadataExtractor;
-import org.apache.tika.parser.xmp.JempboxExtractor;
-import org.apache.tika.sax.XHTMLContentHandler;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-
-public class JpegParser extends AbstractParser {
-
- /**
- * Serial version UID
- */
- private static final long serialVersionUID = -1355028253756234603L;
-
- private static final Set<MediaType> SUPPORTED_TYPES =
- Collections.singleton(MediaType.image("jpeg"));
-
- public Set<MediaType> getSupportedTypes(ParseContext context) {
- return SUPPORTED_TYPES;
- }
-
- public void parse(
- InputStream stream, ContentHandler handler,
- Metadata metadata, ParseContext context)
- throws IOException, SAXException, TikaException {
- TemporaryResources tmp = new TemporaryResources();
- try {
- TikaInputStream tis = TikaInputStream.get(stream, tmp);
- new ImageMetadataExtractor(metadata).parseJpeg(tis.getFile());
- new JempboxExtractor(metadata).parse(tis);
- } finally {
- tmp.dispose();
- }
-
- XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
- xhtml.startDocument();
- xhtml.endDocument();
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.parser.jpeg;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.Set;
+
+import org.apache.tika.exception.TikaException;
+import org.apache.tika.io.TemporaryResources;
+import org.apache.tika.io.TikaInputStream;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.mime.MediaType;
+import org.apache.tika.parser.AbstractParser;
+import org.apache.tika.parser.ParseContext;
+import org.apache.tika.parser.image.ImageMetadataExtractor;
+import org.apache.tika.parser.xmp.JempboxExtractor;
+import org.apache.tika.sax.XHTMLContentHandler;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+public class JpegParser extends AbstractParser {
+
+ /**
+ * Serial version UID
+ */
+ private static final long serialVersionUID = -1355028253756234603L;
+
+ private static final Set<MediaType> SUPPORTED_TYPES =
+ Collections.singleton(MediaType.image("jpeg"));
+
+ public Set<MediaType> getSupportedTypes(ParseContext context) {
+ return SUPPORTED_TYPES;
+ }
+
+ public void parse(
+ InputStream stream, ContentHandler handler,
+ Metadata metadata, ParseContext context)
+ throws IOException, SAXException, TikaException {
+ TemporaryResources tmp = new TemporaryResources();
+ try {
+ TikaInputStream tis = TikaInputStream.get(stream, tmp);
+ new ImageMetadataExtractor(metadata).parseJpeg(tis.getFile());
+ new JempboxExtractor(metadata).parse(tis);
+ } finally {
+ tmp.dispose();
+ }
+
+ XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
+ xhtml.startDocument();
+ xhtml.endDocument();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tika/blob/c7a6bcac/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp3/AudioFrame.java
----------------------------------------------------------------------
diff --git a/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp3/AudioFrame.java b/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp3/AudioFrame.java
index 03dc833..abc4235 100644
--- a/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp3/AudioFrame.java
+++ b/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp3/AudioFrame.java
@@ -1,252 +1,252 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tika.parser.mp3;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.apache.tika.exception.TikaException;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-
-/**
- * An Audio Frame in an MP3 file. These come after the ID3v2 tags in the file.
- * Currently, only the header is processed, not the raw audio data.
- */
-public class AudioFrame implements MP3Frame {
- /** Constant for the MPEG version 1. */
- public static final int MPEG_V1 = 3;
-
- /** Constant for the MPEG version 2. */
- public static final int MPEG_V2 = 2;
-
- /** Constant for the MPEG version 2.5. */
- public static final int MPEG_V2_5 = 0;
-
- /** Constant for audio layer 1. */
- public static final int LAYER_1 = 3;
-
- /** Constant for audio layer 2. */
- public static final int LAYER_2 = 2;
-
- /** Constant for audio layer 3. */
- public static final int LAYER_3 = 1;
-
- private final String version;
- private final int versionCode;
- private final int layer;
- private final int sampleRate;
- private final int channels;
- private final int bitRate;
- private final int length;
- private final float duration;
-
- public String getVersion() {
- return version;
- }
-
- /**
- * Get the sampling rate, in Hz
- */
- public int getSampleRate() {
- return sampleRate;
- }
-
- /**
- * Get the number of channels (1=mono, 2=stereo)
- */
- public int getChannels() {
- return channels;
- }
-
- /**
- * Get the version code.
- * @return the version code (one of the {@code MPEG} constants)
- */
- public int getVersionCode()
- {
- return versionCode;
- }
-
- /**
- * Get the audio layer code.
- * @return the audio layer (one of the {@code LAYER} constants)
- */
- public int getLayer()
- {
- return layer;
- }
-
- /**
- * Get the bit rate in bit per second.
- * @return the bit rate
- */
- public int getBitRate()
- {
- return bitRate;
- }
-
- /**
- * Returns the frame length in bytes.
- * @return the frame length
- */
- public int getLength()
- {
- return length;
- }
-
- /**
- * Returns the duration in milliseconds.
- * @return the duration
- */
- public float getDuration()
- {
- return duration;
- }
-
- /**
- * Does this appear to be a 4 byte audio frame header?
- */
- public static boolean isAudioHeader(int h1, int h2, int h3, int h4) {
- if (h1 == -1 || h2 == -1 || h3 == -1 || h4 == -1) {
- return false;
- }
- // Check for the magic 11 bits set at the start
- // Note - doesn't do a CRC check
- if (h1 == 0xff && (h2 & 0x60) == 0x60) {
- return true;
- }
- return false;
- }
-
- /**
- * @deprecated Use the constructor which is passed all values directly.
- */
- @Deprecated
- public AudioFrame(InputStream stream, ContentHandler handler)
- throws IOException, SAXException, TikaException {
- this(-2, -2, -2, -2, stream);
- }
-
- /**
- * @deprecated Use the constructor which is passed all values directly.
- */
- @Deprecated
- public AudioFrame(int h1, int h2, int h3, int h4, InputStream in)
- throws IOException {
- if (h1 == -2 && h2 == -2 && h3 == -2 && h4 == -2) {
- h1 = in.read();
- h2 = in.read();
- h3 = in.read();
- h4 = in.read();
- }
-
- if (isAudioHeader(h1, h2, h3, h4)) {
- layer = (h2 >> 1) & 0x03;
- versionCode = (h2 >> 3) & 0x03;
- version = generateVersionStr(versionCode, layer);
-
- int rateCode = (h3 >> 2) & 0x03;
- int rate;
- switch (rateCode) {
- case 0:
- rate = 11025;
- break;
- case 1:
- rate = 12000;
- break;
- default:
- rate = 8000;
- }
- if (versionCode == MPEG_V2) {
- rate *= 2;
- } else if(versionCode == MPEG_V1) {
- rate *= 4;
- }
- sampleRate = rate;
-
- int chans = h4 & 0x192;
- if (chans < 3) {
- // Stereo, joint stereo, dual channel
- channels = 2;
- } else {
- channels = 1;
- }
- bitRate = 0;
- duration = 0;
- length = 0;
- } else {
- throw new IllegalArgumentException("Magic Audio Frame Header not found");
- }
- }
-
- /**
- *
- * Creates a new instance of {@code AudioFrame} and initializes all properties.
- * @param mpegVersion the code for the MPEG version
- * @param layer the code for the layer
- * @param bitRate the bit rate (in bps)
- * @param sampleRate the sample rate (in samples per second)
- * @param channels the number of channels
- * @param length the frame length (in bytes)
- * @param duration the duration of this frame (in milliseconds)
- */
- public AudioFrame(int mpegVersion, int layer, int bitRate, int sampleRate,
- int channels, int length, float duration) {
- versionCode = mpegVersion;
- this.layer = layer;
- this.bitRate = bitRate;
- this.sampleRate = sampleRate;
- this.channels = channels;
- this.length = length;
- this.duration = duration;
- version = generateVersionStr(mpegVersion, layer);
- }
-
- /**
- * Generates a string for the version of this audio frame.
- * @param version the code for the MPEG version
- * @param layer the code for the layer
- * @return a string for the version
- */
- private static String generateVersionStr(int version, int layer) {
- StringBuilder buf = new StringBuilder(64);
- buf.append("MPEG 3 Layer ");
- if (layer == LAYER_3) {
- buf.append("III");
- } else if (layer == LAYER_2) {
- buf.append("II");
- } else if (layer == LAYER_1) {
- buf.append("I");
- } else {
- buf.append("(reserved)");
- }
-
- buf.append(" Version ");
- if (version == MPEG_V2_5) {
- buf.append("2.5");
- } else if(version == MPEG_V2) {
- buf.append("2");
- } else if(version == MPEG_V1) {
- buf.append("1");
- } else {
- buf.append("(reseved)");
- }
-
- return buf.toString();
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.parser.mp3;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.tika.exception.TikaException;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+/**
+ * An Audio Frame in an MP3 file. These come after the ID3v2 tags in the file.
+ * Currently, only the header is processed, not the raw audio data.
+ */
+public class AudioFrame implements MP3Frame {
+ /** Constant for the MPEG version 1. */
+ public static final int MPEG_V1 = 3;
+
+ /** Constant for the MPEG version 2. */
+ public static final int MPEG_V2 = 2;
+
+ /** Constant for the MPEG version 2.5. */
+ public static final int MPEG_V2_5 = 0;
+
+ /** Constant for audio layer 1. */
+ public static final int LAYER_1 = 3;
+
+ /** Constant for audio layer 2. */
+ public static final int LAYER_2 = 2;
+
+ /** Constant for audio layer 3. */
+ public static final int LAYER_3 = 1;
+
+ private final String version;
+ private final int versionCode;
+ private final int layer;
+ private final int sampleRate;
+ private final int channels;
+ private final int bitRate;
+ private final int length;
+ private final float duration;
+
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * Get the sampling rate, in Hz
+ */
+ public int getSampleRate() {
+ return sampleRate;
+ }
+
+ /**
+ * Get the number of channels (1=mono, 2=stereo)
+ */
+ public int getChannels() {
+ return channels;
+ }
+
+ /**
+ * Get the version code.
+ * @return the version code (one of the {@code MPEG} constants)
+ */
+ public int getVersionCode()
+ {
+ return versionCode;
+ }
+
+ /**
+ * Get the audio layer code.
+ * @return the audio layer (one of the {@code LAYER} constants)
+ */
+ public int getLayer()
+ {
+ return layer;
+ }
+
+ /**
+ * Get the bit rate in bit per second.
+ * @return the bit rate
+ */
+ public int getBitRate()
+ {
+ return bitRate;
+ }
+
+ /**
+ * Returns the frame length in bytes.
+ * @return the frame length
+ */
+ public int getLength()
+ {
+ return length;
+ }
+
+ /**
+ * Returns the duration in milliseconds.
+ * @return the duration
+ */
+ public float getDuration()
+ {
+ return duration;
+ }
+
+ /**
+ * Does this appear to be a 4 byte audio frame header?
+ */
+ public static boolean isAudioHeader(int h1, int h2, int h3, int h4) {
+ if (h1 == -1 || h2 == -1 || h3 == -1 || h4 == -1) {
+ return false;
+ }
+ // Check for the magic 11 bits set at the start
+ // Note - doesn't do a CRC check
+ if (h1 == 0xff && (h2 & 0x60) == 0x60) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @deprecated Use the constructor which is passed all values directly.
+ */
+ @Deprecated
+ public AudioFrame(InputStream stream, ContentHandler handler)
+ throws IOException, SAXException, TikaException {
+ this(-2, -2, -2, -2, stream);
+ }
+
+ /**
+ * @deprecated Use the constructor which is passed all values directly.
+ */
+ @Deprecated
+ public AudioFrame(int h1, int h2, int h3, int h4, InputStream in)
+ throws IOException {
+ if (h1 == -2 && h2 == -2 && h3 == -2 && h4 == -2) {
+ h1 = in.read();
+ h2 = in.read();
+ h3 = in.read();
+ h4 = in.read();
+ }
+
+ if (isAudioHeader(h1, h2, h3, h4)) {
+ layer = (h2 >> 1) & 0x03;
+ versionCode = (h2 >> 3) & 0x03;
+ version = generateVersionStr(versionCode, layer);
+
+ int rateCode = (h3 >> 2) & 0x03;
+ int rate;
+ switch (rateCode) {
+ case 0:
+ rate = 11025;
+ break;
+ case 1:
+ rate = 12000;
+ break;
+ default:
+ rate = 8000;
+ }
+ if (versionCode == MPEG_V2) {
+ rate *= 2;
+ } else if(versionCode == MPEG_V1) {
+ rate *= 4;
+ }
+ sampleRate = rate;
+
+ int chans = h4 & 0x192;
+ if (chans < 3) {
+ // Stereo, joint stereo, dual channel
+ channels = 2;
+ } else {
+ channels = 1;
+ }
+ bitRate = 0;
+ duration = 0;
+ length = 0;
+ } else {
+ throw new IllegalArgumentException("Magic Audio Frame Header not found");
+ }
+ }
+
+ /**
+ *
+ * Creates a new instance of {@code AudioFrame} and initializes all properties.
+ * @param mpegVersion the code for the MPEG version
+ * @param layer the code for the layer
+ * @param bitRate the bit rate (in bps)
+ * @param sampleRate the sample rate (in samples per second)
+ * @param channels the number of channels
+ * @param length the frame length (in bytes)
+ * @param duration the duration of this frame (in milliseconds)
+ */
+ public AudioFrame(int mpegVersion, int layer, int bitRate, int sampleRate,
+ int channels, int length, float duration) {
+ versionCode = mpegVersion;
+ this.layer = layer;
+ this.bitRate = bitRate;
+ this.sampleRate = sampleRate;
+ this.channels = channels;
+ this.length = length;
+ this.duration = duration;
+ version = generateVersionStr(mpegVersion, layer);
+ }
+
+ /**
+ * Generates a string for the version of this audio frame.
+ * @param version the code for the MPEG version
+ * @param layer the code for the layer
+ * @return a string for the version
+ */
+ private static String generateVersionStr(int version, int layer) {
+ StringBuilder buf = new StringBuilder(64);
+ buf.append("MPEG 3 Layer ");
+ if (layer == LAYER_3) {
+ buf.append("III");
+ } else if (layer == LAYER_2) {
+ buf.append("II");
+ } else if (layer == LAYER_1) {
+ buf.append("I");
+ } else {
+ buf.append("(reserved)");
+ }
+
+ buf.append(" Version ");
+ if (version == MPEG_V2_5) {
+ buf.append("2.5");
+ } else if(version == MPEG_V2) {
+ buf.append("2");
+ } else if(version == MPEG_V1) {
+ buf.append("1");
+ } else {
+ buf.append("(reseved)");
+ }
+
+ return buf.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/tika/blob/c7a6bcac/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp3/CompositeTagHandler.java
----------------------------------------------------------------------
diff --git a/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp3/CompositeTagHandler.java b/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp3/CompositeTagHandler.java
index 6f20c3c..b7d2d75 100644
--- a/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp3/CompositeTagHandler.java
+++ b/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp3/CompositeTagHandler.java
@@ -1,142 +1,142 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tika.parser.mp3;
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Takes an array of {@link ID3Tags} in preference order, and when asked for
- * a given tag, will return it from the first {@link ID3Tags} that has it.
- */
-public class CompositeTagHandler implements ID3Tags {
-
- private ID3Tags[] tags;
-
- public CompositeTagHandler(ID3Tags[] tags) {
- this.tags = tags;
- }
-
- public boolean getTagsPresent() {
- for (ID3Tags tag : tags) {
- if (tag.getTagsPresent()) {
- return true;
- }
- }
- return false;
- }
-
- public String getTitle() {
- for (ID3Tags tag : tags) {
- if (tag.getTitle() != null) {
- return tag.getTitle();
- }
- }
- return null;
- }
-
- public String getArtist() {
- for (ID3Tags tag : tags) {
- if (tag.getArtist() != null) {
- return tag.getArtist();
- }
- }
- return null;
- }
-
- public String getAlbum() {
- for (ID3Tags tag : tags) {
- if (tag.getAlbum() != null) {
- return tag.getAlbum();
- }
- }
- return null;
- }
-
- public String getComposer() {
- for (ID3Tags tag : tags) {
- if (tag.getComposer() != null) {
- return tag.getComposer();
- }
- }
- return null;
- }
-
- public String getYear() {
- for (ID3Tags tag : tags) {
- if (tag.getYear() != null) {
- return tag.getYear();
- }
- }
- return null;
- }
-
- public List<ID3Comment> getComments() {
- for (ID3Tags tag : tags) {
- List<ID3Comment> comments = tag.getComments();
- if (comments != null && comments.size() > 0) {
- return comments;
- }
- }
- return Collections.emptyList();
- }
-
- public String getGenre() {
- for (ID3Tags tag : tags) {
- if (tag.getGenre() != null) {
- return tag.getGenre();
- }
- }
- return null;
- }
-
- public String getTrackNumber() {
- for (ID3Tags tag : tags) {
- if (tag.getTrackNumber() != null) {
- return tag.getTrackNumber();
- }
- }
- return null;
- }
-
- public String getAlbumArtist() {
- for (ID3Tags tag : tags) {
- if (tag.getAlbumArtist() != null) {
- return tag.getAlbumArtist();
- }
- }
- return null;
- }
-
- public String getDisc() {
- for (ID3Tags tag : tags) {
- if (tag.getDisc() != null) {
- return tag.getDisc();
- }
- }
- return null;
- }
-
- public String getCompilation() {
- for (ID3Tags tag : tags) {
- if (tag.getCompilation() != null) {
- return tag.getCompilation();
- }
- }
- return null;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.parser.mp3;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Takes an array of {@link ID3Tags} in preference order, and when asked for
+ * a given tag, will return it from the first {@link ID3Tags} that has it.
+ */
+public class CompositeTagHandler implements ID3Tags {
+
+ private ID3Tags[] tags;
+
+ public CompositeTagHandler(ID3Tags[] tags) {
+ this.tags = tags;
+ }
+
+ public boolean getTagsPresent() {
+ for (ID3Tags tag : tags) {
+ if (tag.getTagsPresent()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public String getTitle() {
+ for (ID3Tags tag : tags) {
+ if (tag.getTitle() != null) {
+ return tag.getTitle();
+ }
+ }
+ return null;
+ }
+
+ public String getArtist() {
+ for (ID3Tags tag : tags) {
+ if (tag.getArtist() != null) {
+ return tag.getArtist();
+ }
+ }
+ return null;
+ }
+
+ public String getAlbum() {
+ for (ID3Tags tag : tags) {
+ if (tag.getAlbum() != null) {
+ return tag.getAlbum();
+ }
+ }
+ return null;
+ }
+
+ public String getComposer() {
+ for (ID3Tags tag : tags) {
+ if (tag.getComposer() != null) {
+ return tag.getComposer();
+ }
+ }
+ return null;
+ }
+
+ public String getYear() {
+ for (ID3Tags tag : tags) {
+ if (tag.getYear() != null) {
+ return tag.getYear();
+ }
+ }
+ return null;
+ }
+
+ public List<ID3Comment> getComments() {
+ for (ID3Tags tag : tags) {
+ List<ID3Comment> comments = tag.getComments();
+ if (comments != null && comments.size() > 0) {
+ return comments;
+ }
+ }
+ return Collections.emptyList();
+ }
+
+ public String getGenre() {
+ for (ID3Tags tag : tags) {
+ if (tag.getGenre() != null) {
+ return tag.getGenre();
+ }
+ }
+ return null;
+ }
+
+ public String getTrackNumber() {
+ for (ID3Tags tag : tags) {
+ if (tag.getTrackNumber() != null) {
+ return tag.getTrackNumber();
+ }
+ }
+ return null;
+ }
+
+ public String getAlbumArtist() {
+ for (ID3Tags tag : tags) {
+ if (tag.getAlbumArtist() != null) {
+ return tag.getAlbumArtist();
+ }
+ }
+ return null;
+ }
+
+ public String getDisc() {
+ for (ID3Tags tag : tags) {
+ if (tag.getDisc() != null) {
+ return tag.getDisc();
+ }
+ }
+ return null;
+ }
+
+ public String getCompilation() {
+ for (ID3Tags tag : tags) {
+ if (tag.getCompilation() != null) {
+ return tag.getCompilation();
+ }
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/tika/blob/c7a6bcac/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp3/ID3Tags.java
----------------------------------------------------------------------
diff --git a/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp3/ID3Tags.java b/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp3/ID3Tags.java
index 6ee19db..98ef504 100644
--- a/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp3/ID3Tags.java
+++ b/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp3/ID3Tags.java
@@ -1,254 +1,254 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tika.parser.mp3;
-
-import java.util.List;
-
-/**
- * Interface that defines the common interface for ID3 tag parsers,
- * such as ID3v1 and ID3v2.3.
- * Implementations should return NULL if the file lacks a given
- * tag, or if the tag isn't defined for the version.
- *
- * Note that so far, only the ID3v1 core tags are listed here. In
- * future, we may wish to add more to cover the extra tags that
- * our ID3v2 handlers can produce.
- */
-public interface ID3Tags {
- /**
- * List of predefined genres.
- *
- * @see http://www.id3.org/id3v2-00
- */
- String[] GENRES = new String[] {
- /* 0 */ "Blues",
- /* 1 */ "Classic Rock",
- /* 2 */ "Country",
- /* 3 */ "Dance",
- /* 4 */ "Disco",
- /* 5 */ "Funk",
- /* 6 */ "Grunge",
- /* 7 */ "Hip-Hop",
- /* 8 */ "Jazz",
- /* 9 */ "Metal",
- /* 10 */ "New Age",
- /* 11 */ "Oldies",
- /* 12 */ "Other",
- /* 13 */ "Pop",
- /* 14 */ "R&B",
- /* 15 */ "Rap",
- /* 16 */ "Reggae",
- /* 17 */ "Rock",
- /* 18 */ "Techno",
- /* 19 */ "Industrial",
- /* 20 */ "Alternative",
- /* 21 */ "Ska",
- /* 22 */ "Death Metal",
- /* 23 */ "Pranks",
- /* 24 */ "Soundtrack",
- /* 25 */ "Euro-Techno",
- /* 26 */ "Ambient",
- /* 27 */ "Trip-Hop",
- /* 28 */ "Vocal",
- /* 29 */ "Jazz+Funk",
- /* 30 */ "Fusion",
- /* 31 */ "Trance",
- /* 32 */ "Classical",
- /* 33 */ "Instrumental",
- /* 34 */ "Acid",
- /* 35 */ "House",
- /* 36 */ "Game",
- /* 37 */ "Sound Clip",
- /* 38 */ "Gospel",
- /* 39 */ "Noise",
- /* 40 */ "AlternRock",
- /* 41 */ "Bass",
- /* 42 */ "Soul",
- /* 43 */ "Punk",
- /* 44 */ "Space",
- /* 45 */ "Meditative",
- /* 46 */ "Instrumental Pop",
- /* 47 */ "Instrumental Rock",
- /* 48 */ "Ethnic",
- /* 49 */ "Gothic",
- /* 50 */ "Darkwave",
- /* 51 */ "Techno-Industrial",
- /* 52 */ "Electronic",
- /* 53 */ "Pop-Folk",
- /* 54 */ "Eurodance",
- /* 55 */ "Dream",
- /* 56 */ "Southern Rock",
- /* 57 */ "Comedy",
- /* 58 */ "Cult",
- /* 59 */ "Gangsta",
- /* 60 */ "Top 40",
- /* 61 */ "Christian Rap",
- /* 62 */ "Pop/Funk",
- /* 63 */ "Jungle",
- /* 64 */ "Native American",
- /* 65 */ "Cabaret",
- /* 66 */ "New Wave",
- /* 67 */ "Psychadelic",
- /* 68 */ "Rave",
- /* 69 */ "Showtunes",
- /* 70 */ "Trailer",
- /* 71 */ "Lo-Fi",
- /* 72 */ "Tribal",
- /* 73 */ "Acid Punk",
- /* 74 */ "Acid Jazz",
- /* 75 */ "Polka",
- /* 76 */ "Retro",
- /* 77 */ "Musical",
- /* 78 */ "Rock & Roll",
- /* 79 */ "Hard Rock",
- /* 80 */ "Folk",
- /* 81 */ "Folk-Rock",
- /* 82 */ "National Folk",
- /* 83 */ "Swing",
- /* 84 */ "Fast Fusion",
- /* 85 */ "Bebob",
- /* 86 */ "Latin",
- /* 87 */ "Revival",
- /* 88 */ "Celtic",
- /* 89 */ "Bluegrass",
- /* 90 */ "Avantgarde",
- /* 91 */ "Gothic Rock",
- /* 92 */ "Progressive Rock",
- /* 93 */ "Psychedelic Rock",
- /* 94 */ "Symphonic Rock",
- /* 95 */ "Slow Rock",
- /* 96 */ "Big Band",
- /* 97 */ "Chorus",
- /* 98 */ "Easy Listening",
- /* 99 */ "Acoustic",
- /* 100 */ "Humour",
- /* 101 */ "Speech",
- /* 102 */ "Chanson",
- /* 103 */ "Opera",
- /* 104 */ "Chamber Music",
- /* 105 */ "Sonata",
- /* 106 */ "Symphony",
- /* 107 */ "Booty Bass",
- /* 108 */ "Primus",
- /* 109 */ "Porn Groove",
- /* 110 */ "Satire",
- /* 111 */ "Slow Jam",
- /* 112 */ "Club",
- /* 113 */ "Tango",
- /* 114 */ "Samba",
- /* 115 */ "Folklore",
- /* 116 */ "Ballad",
- /* 117 */ "Power Ballad",
- /* 118 */ "Rhythmic Soul",
- /* 119 */ "Freestyle",
- /* 120 */ "Duet",
- /* 121 */ "Punk Rock",
- /* 122 */ "Drum Solo",
- /* 123 */ "A capella",
- /* 124 */ "Euro-House",
- /* 125 */ "Dance Hall",
- /* sentinel */ ""
- };
-
- /**
- * Does the file contain this kind of tags?
- */
- boolean getTagsPresent();
-
- String getTitle();
-
- /**
- * The Artist for the track
- */
- String getArtist();
-
- /**
- * The Artist for the overall album / compilation of albums
- */
- String getAlbumArtist();
-
- String getAlbum();
-
- String getComposer();
-
- String getCompilation();
-
- /**
- * Retrieves the comments, if any.
- * Files may have more than one comment, but normally only
- * one with any language/description pair.
- */
- List<ID3Comment> getComments();
-
- String getGenre();
-
- String getYear();
-
- /**
- * The number of the track within the album / recording
- */
- String getTrackNumber();
-
- /**
- * The number of the disc this belongs to, within the set
- */
- String getDisc();
-
- /**
- * Represents a comments in ID3 (especially ID3 v2), where are
- * made up of several parts
- */
- public static class ID3Comment {
- private String language;
- private String description;
- private String text;
-
- /**
- * Creates an ID3 v1 style comment tag
- */
- public ID3Comment(String id3v1Text) {
- this.text = id3v1Text;
- }
- /**
- * Creates an ID3 v2 style comment tag
- */
- public ID3Comment(String language, String description, String text) {
- this.language = language;
- this.description = description;
- this.text = text;
- }
-
- /**
- * Gets the language, if present
- */
- public String getLanguage() {
- return language;
- }
- /**
- * Gets the description, if present
- */
- public String getDescription() {
- return description;
- }
- /**
- * Gets the text, if present
- */
- public String getText() {
- return text;
- }
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.parser.mp3;
+
+import java.util.List;
+
+/**
+ * Interface that defines the common interface for ID3 tag parsers,
+ * such as ID3v1 and ID3v2.3.
+ * Implementations should return NULL if the file lacks a given
+ * tag, or if the tag isn't defined for the version.
+ *
+ * Note that so far, only the ID3v1 core tags are listed here. In
+ * future, we may wish to add more to cover the extra tags that
+ * our ID3v2 handlers can produce.
+ */
+public interface ID3Tags {
+ /**
+ * List of predefined genres.
+ *
+ * @see http://www.id3.org/id3v2-00
+ */
+ String[] GENRES = new String[] {
+ /* 0 */ "Blues",
+ /* 1 */ "Classic Rock",
+ /* 2 */ "Country",
+ /* 3 */ "Dance",
+ /* 4 */ "Disco",
+ /* 5 */ "Funk",
+ /* 6 */ "Grunge",
+ /* 7 */ "Hip-Hop",
+ /* 8 */ "Jazz",
+ /* 9 */ "Metal",
+ /* 10 */ "New Age",
+ /* 11 */ "Oldies",
+ /* 12 */ "Other",
+ /* 13 */ "Pop",
+ /* 14 */ "R&B",
+ /* 15 */ "Rap",
+ /* 16 */ "Reggae",
+ /* 17 */ "Rock",
+ /* 18 */ "Techno",
+ /* 19 */ "Industrial",
+ /* 20 */ "Alternative",
+ /* 21 */ "Ska",
+ /* 22 */ "Death Metal",
+ /* 23 */ "Pranks",
+ /* 24 */ "Soundtrack",
+ /* 25 */ "Euro-Techno",
+ /* 26 */ "Ambient",
+ /* 27 */ "Trip-Hop",
+ /* 28 */ "Vocal",
+ /* 29 */ "Jazz+Funk",
+ /* 30 */ "Fusion",
+ /* 31 */ "Trance",
+ /* 32 */ "Classical",
+ /* 33 */ "Instrumental",
+ /* 34 */ "Acid",
+ /* 35 */ "House",
+ /* 36 */ "Game",
+ /* 37 */ "Sound Clip",
+ /* 38 */ "Gospel",
+ /* 39 */ "Noise",
+ /* 40 */ "AlternRock",
+ /* 41 */ "Bass",
+ /* 42 */ "Soul",
+ /* 43 */ "Punk",
+ /* 44 */ "Space",
+ /* 45 */ "Meditative",
+ /* 46 */ "Instrumental Pop",
+ /* 47 */ "Instrumental Rock",
+ /* 48 */ "Ethnic",
+ /* 49 */ "Gothic",
+ /* 50 */ "Darkwave",
+ /* 51 */ "Techno-Industrial",
+ /* 52 */ "Electronic",
+ /* 53 */ "Pop-Folk",
+ /* 54 */ "Eurodance",
+ /* 55 */ "Dream",
+ /* 56 */ "Southern Rock",
+ /* 57 */ "Comedy",
+ /* 58 */ "Cult",
+ /* 59 */ "Gangsta",
+ /* 60 */ "Top 40",
+ /* 61 */ "Christian Rap",
+ /* 62 */ "Pop/Funk",
+ /* 63 */ "Jungle",
+ /* 64 */ "Native American",
+ /* 65 */ "Cabaret",
+ /* 66 */ "New Wave",
+ /* 67 */ "Psychadelic",
+ /* 68 */ "Rave",
+ /* 69 */ "Showtunes",
+ /* 70 */ "Trailer",
+ /* 71 */ "Lo-Fi",
+ /* 72 */ "Tribal",
+ /* 73 */ "Acid Punk",
+ /* 74 */ "Acid Jazz",
+ /* 75 */ "Polka",
+ /* 76 */ "Retro",
+ /* 77 */ "Musical",
+ /* 78 */ "Rock & Roll",
+ /* 79 */ "Hard Rock",
+ /* 80 */ "Folk",
+ /* 81 */ "Folk-Rock",
+ /* 82 */ "National Folk",
+ /* 83 */ "Swing",
+ /* 84 */ "Fast Fusion",
+ /* 85 */ "Bebob",
+ /* 86 */ "Latin",
+ /* 87 */ "Revival",
+ /* 88 */ "Celtic",
+ /* 89 */ "Bluegrass",
+ /* 90 */ "Avantgarde",
+ /* 91 */ "Gothic Rock",
+ /* 92 */ "Progressive Rock",
+ /* 93 */ "Psychedelic Rock",
+ /* 94 */ "Symphonic Rock",
+ /* 95 */ "Slow Rock",
+ /* 96 */ "Big Band",
+ /* 97 */ "Chorus",
+ /* 98 */ "Easy Listening",
+ /* 99 */ "Acoustic",
+ /* 100 */ "Humour",
+ /* 101 */ "Speech",
+ /* 102 */ "Chanson",
+ /* 103 */ "Opera",
+ /* 104 */ "Chamber Music",
+ /* 105 */ "Sonata",
+ /* 106 */ "Symphony",
+ /* 107 */ "Booty Bass",
+ /* 108 */ "Primus",
+ /* 109 */ "Porn Groove",
+ /* 110 */ "Satire",
+ /* 111 */ "Slow Jam",
+ /* 112 */ "Club",
+ /* 113 */ "Tango",
+ /* 114 */ "Samba",
+ /* 115 */ "Folklore",
+ /* 116 */ "Ballad",
+ /* 117 */ "Power Ballad",
+ /* 118 */ "Rhythmic Soul",
+ /* 119 */ "Freestyle",
+ /* 120 */ "Duet",
+ /* 121 */ "Punk Rock",
+ /* 122 */ "Drum Solo",
+ /* 123 */ "A capella",
+ /* 124 */ "Euro-House",
+ /* 125 */ "Dance Hall",
+ /* sentinel */ ""
+ };
+
+ /**
+ * Does the file contain this kind of tags?
+ */
+ boolean getTagsPresent();
+
+ String getTitle();
+
+ /**
+ * The Artist for the track
+ */
+ String getArtist();
+
+ /**
+ * The Artist for the overall album / compilation of albums
+ */
+ String getAlbumArtist();
+
+ String getAlbum();
+
+ String getComposer();
+
+ String getCompilation();
+
+ /**
+ * Retrieves the comments, if any.
+ * Files may have more than one comment, but normally only
+ * one with any language/description pair.
+ */
+ List<ID3Comment> getComments();
+
+ String getGenre();
+
+ String getYear();
+
+ /**
+ * The number of the track within the album / recording
+ */
+ String getTrackNumber();
+
+ /**
+ * The number of the disc this belongs to, within the set
+ */
+ String getDisc();
+
+ /**
+ * Represents a comments in ID3 (especially ID3 v2), where are
+ * made up of several parts
+ */
+ public static class ID3Comment {
+ private String language;
+ private String description;
+ private String text;
+
+ /**
+ * Creates an ID3 v1 style comment tag
+ */
+ public ID3Comment(String id3v1Text) {
+ this.text = id3v1Text;
+ }
+ /**
+ * Creates an ID3 v2 style comment tag
+ */
+ public ID3Comment(String language, String description, String text) {
+ this.language = language;
+ this.description = description;
+ this.text = text;
+ }
+
+ /**
+ * Gets the language, if present
+ */
+ public String getLanguage() {
+ return language;
+ }
+ /**
+ * Gets the description, if present
+ */
+ public String getDescription() {
+ return description;
+ }
+ /**
+ * Gets the text, if present
+ */
+ public String getText() {
+ return text;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tika/blob/c7a6bcac/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp3/ID3v1Handler.java
----------------------------------------------------------------------
diff --git a/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp3/ID3v1Handler.java b/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp3/ID3v1Handler.java
index 4d41fa3..2111356 100644
--- a/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp3/ID3v1Handler.java
+++ b/tika-parser-modules/tika-parser-multimedia-module/src/main/java/org/apache/tika/parser/mp3/ID3v1Handler.java
@@ -1,183 +1,183 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tika.parser.mp3;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.tika.exception.TikaException;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-
-import static java.nio.charset.StandardCharsets.ISO_8859_1;
-
-/**
- * This is used to parse ID3 Version 1 Tag information from an MP3 file,
- * if available.
- *
- * @see <a href="http://www.id3.org/ID3v1">MP3 ID3 Version 1 specification</a>
- */
-public class ID3v1Handler implements ID3Tags {
- private String title;
- private String artist;
- private String album;
- private String year;
- private ID3Comment comment;
- private String genre;
- private String trackNumber;
-
- boolean found = false;
-
- public ID3v1Handler(InputStream stream, ContentHandler handler)
- throws IOException, SAXException, TikaException {
- this(LyricsHandler.getSuffix(stream, 128));
- }
-
- /**
- * Creates from the last 128 bytes of a stream.
- * @param tagData Must be the last 128 bytes
- */
- protected ID3v1Handler(byte[] tagData)
- throws IOException, SAXException, TikaException {
- if (tagData.length == 128
- && tagData[0] == 'T' && tagData[1] == 'A' && tagData[2] == 'G') {
- found = true;
-
- title = getString(tagData, 3, 33);
- artist = getString(tagData, 33, 63);
- album = getString(tagData, 63, 93);
- year = getString(tagData, 93, 97);
-
- String commentStr = getString(tagData, 97, 127);
- comment = new ID3Comment(commentStr);
-
- int genreID = (int) tagData[127] & 0xff; // unsigned byte
- genre = GENRES[Math.min(genreID, GENRES.length - 1)];
-
- // ID3v1.1 Track addition
- // If the last two bytes of the comment field are zero and
- // non-zero, then the last byte is the track number
- if (tagData[125] == 0 && tagData[126] != 0) {
- int trackNum = (int) tagData[126] & 0xff;
- trackNumber = Integer.toString(trackNum);
- }
- }
- }
-
-
- public boolean getTagsPresent() {
- return found;
- }
-
- public String getTitle() {
- return title;
- }
-
- public String getArtist() {
- return artist;
- }
-
- public String getAlbum() {
- return album;
- }
-
- public String getYear() {
- return year;
- }
-
- public List<ID3Comment> getComments() {
- return Arrays.asList(comment);
- }
-
- public String getGenre() {
- return genre;
- }
-
- public String getTrackNumber() {
- return trackNumber;
- }
-
- /**
- * ID3v1 doesn't have composers,
- * so returns null;
- */
- public String getComposer() {
- return null;
- }
-
- /**
- * ID3v1 doesn't have album-wide artists,
- * so returns null;
- */
- public String getAlbumArtist() {
- return null;
- }
-
- /**
- * ID3v1 doesn't have disc numbers,
- * so returns null;
- */
- public String getDisc() {
- return null;
- }
-
- /**
- * ID3v1 doesn't have compilations,
- * so returns null;
- */
- public String getCompilation() {
- return null;
- }
-
- /**
- * Returns the identified ISO-8859-1 substring from the given byte buffer.
- * The return value is the zero-terminated substring retrieved from
- * between the given start and end positions in the given byte buffer.
- * Extra whitespace (and control characters) from the beginning and the
- * end of the substring is removed.
- *
- * @param buffer byte buffer
- * @param start start index of the substring
- * @param end end index of the substring
- * @return the identified substring
- * @throws TikaException if the ISO-8859-1 encoding is not available
- */
- private static String getString(byte[] buffer, int start, int end)
- throws TikaException {
- // Find the zero byte that marks the end of the string
- int zero = start;
- while (zero < end && buffer[zero] != 0) {
- zero++;
- }
-
- // Skip trailing whitespace
- end = zero;
- while (start < end && buffer[end - 1] <= ' ') {
- end--;
- }
-
- // Skip leading whitespace
- while (start < end && buffer[start] <= ' ') {
- start++;
- }
-
- // Return the remaining substring
- return new String(buffer, start, end - start, ISO_8859_1);
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.parser.mp3;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.tika.exception.TikaException;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
+
+/**
+ * This is used to parse ID3 Version 1 Tag information from an MP3 file,
+ * if available.
+ *
+ * @see <a href="http://www.id3.org/ID3v1">MP3 ID3 Version 1 specification</a>
+ */
+public class ID3v1Handler implements ID3Tags {
+ private String title;
+ private String artist;
+ private String album;
+ private String year;
+ private ID3Comment comment;
+ private String genre;
+ private String trackNumber;
+
+ boolean found = false;
+
+ public ID3v1Handler(InputStream stream, ContentHandler handler)
+ throws IOException, SAXException, TikaException {
+ this(LyricsHandler.getSuffix(stream, 128));
+ }
+
+ /**
+ * Creates from the last 128 bytes of a stream.
+ * @param tagData Must be the last 128 bytes
+ */
+ protected ID3v1Handler(byte[] tagData)
+ throws IOException, SAXException, TikaException {
+ if (tagData.length == 128
+ && tagData[0] == 'T' && tagData[1] == 'A' && tagData[2] == 'G') {
+ found = true;
+
+ title = getString(tagData, 3, 33);
+ artist = getString(tagData, 33, 63);
+ album = getString(tagData, 63, 93);
+ year = getString(tagData, 93, 97);
+
+ String commentStr = getString(tagData, 97, 127);
+ comment = new ID3Comment(commentStr);
+
+ int genreID = (int) tagData[127] & 0xff; // unsigned byte
+ genre = GENRES[Math.min(genreID, GENRES.length - 1)];
+
+ // ID3v1.1 Track addition
+ // If the last two bytes of the comment field are zero and
+ // non-zero, then the last byte is the track number
+ if (tagData[125] == 0 && tagData[126] != 0) {
+ int trackNum = (int) tagData[126] & 0xff;
+ trackNumber = Integer.toString(trackNum);
+ }
+ }
+ }
+
+
+ public boolean getTagsPresent() {
+ return found;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public String getArtist() {
+ return artist;
+ }
+
+ public String getAlbum() {
+ return album;
+ }
+
+ public String getYear() {
+ return year;
+ }
+
+ public List<ID3Comment> getComments() {
+ return Arrays.asList(comment);
+ }
+
+ public String getGenre() {
+ return genre;
+ }
+
+ public String getTrackNumber() {
+ return trackNumber;
+ }
+
+ /**
+ * ID3v1 doesn't have composers,
+ * so returns null;
+ */
+ public String getComposer() {
+ return null;
+ }
+
+ /**
+ * ID3v1 doesn't have album-wide artists,
+ * so returns null;
+ */
+ public String getAlbumArtist() {
+ return null;
+ }
+
+ /**
+ * ID3v1 doesn't have disc numbers,
+ * so returns null;
+ */
+ public String getDisc() {
+ return null;
+ }
+
+ /**
+ * ID3v1 doesn't have compilations,
+ * so returns null;
+ */
+ public String getCompilation() {
+ return null;
+ }
+
+ /**
+ * Returns the identified ISO-8859-1 substring from the given byte buffer.
+ * The return value is the zero-terminated substring retrieved from
+ * between the given start and end positions in the given byte buffer.
+ * Extra whitespace (and control characters) from the beginning and the
+ * end of the substring is removed.
+ *
+ * @param buffer byte buffer
+ * @param start start index of the substring
+ * @param end end index of the substring
+ * @return the identified substring
+ * @throws TikaException if the ISO-8859-1 encoding is not available
+ */
+ private static String getString(byte[] buffer, int start, int end)
+ throws TikaException {
+ // Find the zero byte that marks the end of the string
+ int zero = start;
+ while (zero < end && buffer[zero] != 0) {
+ zero++;
+ }
+
+ // Skip trailing whitespace
+ end = zero;
+ while (start < end && buffer[end - 1] <= ' ') {
+ end--;
+ }
+
+ // Skip leading whitespace
+ while (start < end && buffer[start] <= ' ') {
+ start++;
+ }
+
+ // Return the remaining substring
+ return new String(buffer, start, end - start, ISO_8859_1);
+ }
+}