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 2023/05/24 21:03:19 UTC

[tika] 01/01: [TIKA-4003] -- add magic for application/vnd.isac.fcs

This is an automated email from the ASF dual-hosted git repository.

tallison pushed a commit to branch TIKA-4003
in repository https://gitbox.apache.org/repos/asf/tika.git

commit 12756febfdaf35ca79f5e014ca41c9cb81a22780
Author: tballison <ta...@apache.org>
AuthorDate: Wed May 24 17:03:08 2023 -0400

    [TIKA-4003] -- add magic for application/vnd.isac.fcs
---
 .../org/apache/tika/mime/tika-mimetypes.xml        |  8 ++-
 .../java/org/apache/tika/mime/OneOffMimeTest.java  | 64 ++++++++++++++++++++++
 2 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml b/tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml
index 888c28aa0..77b8ff4a9 100644
--- a/tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml
+++ b/tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml
@@ -3266,7 +3266,13 @@
       <match value="0x0606edf5d81d46e5bd31efe7fe74b71d" type="string" offset="0" />
     </magic>
   </mime-type>
-
+  <mime-type type="application/vnd.isac.fcs">
+    <_comment>Flow Cytometry Standard File</_comment>
+    <magic priority="50">
+      <match value="FCS[1-3]\\.[0-9] " type="regex" offset="0"/>
+    </magic>
+    <glob pattern="*.fcs"/>
+  </mime-type>
   <mime-type type="application/vnd.adobe.indesign-idml-package">
     <sub-class-of type="application/zip"/>
     <_comment>IDML</_comment>
diff --git a/tika-parsers/tika-parsers-standard/tika-parsers-standard-package/src/test/java/org/apache/tika/mime/OneOffMimeTest.java b/tika-parsers/tika-parsers-standard/tika-parsers-standard-package/src/test/java/org/apache/tika/mime/OneOffMimeTest.java
new file mode 100644
index 000000000..1c6284958
--- /dev/null
+++ b/tika-parsers/tika-parsers-standard/tika-parsers-standard-package/src/test/java/org/apache/tika/mime/OneOffMimeTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.mime;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+
+import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import org.apache.tika.TikaTest;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.metadata.TikaCoreProperties;
+import org.apache.tika.parser.ParseContext;
+
+public class OneOffMimeTest extends TikaTest {
+
+    @Disabled("use for development purposes on local files that " +
+            "cannot be added to Tika's repo.")
+    @Test
+    public void testOne() throws Exception {
+        Path p = Paths.get("/Users/allison/Desktop/mimes/Beckman_Coulter-Cyan.fcs");
+        String mime = "application/vnd.isac.fcs";
+        assertByData(mime, p);
+        assertByName("application/vnd.isac.fcs", p);
+    }
+
+    private void assertByName(String expected, Path p) throws Exception {
+        Metadata metadata = new Metadata();
+        metadata.set(TikaCoreProperties.RESOURCE_NAME_KEY, p.getFileName().toString());
+        assertEquals(expected,
+                getRecursiveMetadata(new UnsynchronizedByteArrayInputStream(new byte[0]),
+                        metadata,
+                        new ParseContext(), true).get(0).get(Metadata.CONTENT_TYPE));
+    }
+
+    private void assertByData(String expected, Path p) throws Exception {
+        try (InputStream is = Files.newInputStream(p)) {
+            List<Metadata> metadataList = getRecursiveMetadata(is, true);
+            assertEquals(expected, metadataList.get(0).get(Metadata.CONTENT_TYPE));
+        }
+    }
+
+}