Repository: arimus/jmimemagic Branch: master Commit: d6dd3092cc2a Files: 71 Total size: 323.5 KB Directory structure: gitextract_a6vz6836/ ├── .gitignore ├── Changelog ├── INFO ├── LICENSE ├── LICENSE_HEADER ├── NOTICE ├── README ├── TODO ├── checkstyle.xml ├── maven.xml ├── pom.xml ├── project.properties ├── project.xml ├── src/ │ ├── main/ │ │ ├── filters/ │ │ │ └── filter.properties │ │ ├── java/ │ │ │ └── net/ │ │ │ └── sf/ │ │ │ └── jmimemagic/ │ │ │ ├── Magic.java │ │ │ ├── MagicDetector.java │ │ │ ├── MagicException.java │ │ │ ├── MagicMatch.java │ │ │ ├── MagicMatchNotFoundException.java │ │ │ ├── MagicMatcher.java │ │ │ ├── MagicParseException.java │ │ │ ├── MagicParser.java │ │ │ ├── UnsupportedTypeException.java │ │ │ ├── detectors/ │ │ │ │ ├── TextFileDetector.java │ │ │ │ └── package.html │ │ │ └── package.html │ │ └── resources/ │ │ ├── log4j.properties │ │ ├── magic.dtd │ │ ├── magic.xml │ │ ├── magic.xml.basic │ │ ├── magic.xml.verified │ │ ├── magic_1_0.dtd │ │ └── template.xml │ └── test/ │ └── java/ │ └── net/ │ └── sf/ │ └── jmimemagic/ │ └── MagicTest.java ├── test └── test_docs/ ├── test.au ├── test.dtd ├── test.emf ├── test.eps ├── test.fli ├── test.java ├── test.odt ├── test.ogg ├── test.pcx ├── test.pl ├── test.pnm ├── test.ppm ├── test.ppt ├── test.ps ├── test.psd ├── test.py ├── test.rtf ├── test.sh ├── test.tga ├── test.txt ├── test.wmf ├── test.xcf ├── test.xml ├── test.xpm ├── test_excel.xlsm ├── test_excel.xlsx ├── test_excel_2000.xls ├── test_excel_spreadsheet.xml ├── test_excel_web_archive.mht ├── test_nocompress.tif ├── test_powerpoint.pptm ├── test_powerpoint.pptx ├── test_word.docm ├── test_word.docx ├── test_word_2000.doc └── test_word_6.0_95.doc ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ build.properties target .project .classpath *.log log ================================================ FILE: Changelog ================================================ Changelog --------- Changes since 0.1.2 * changing license over to the Apache license, retro-active to 0.1.2, since I don't want anyone to have to fetch a new package for a simple license change. * sonatype fixes * TIFF additions Changes since 0.1.1 * remove log4j.properties from jar file Changes since 0.1.0 * changes for target source level * adjustment for maven 1.1 * project.xml cleanup * documentation fixes * various other types of cleanup Changes since 0.0.4a * migrated build system to maven 1.x * moved to subversion * added hinting flag for file extensions hints * ability to disable submatches for mime-only detection, which * which still needs work (e.g. submatch until a mime is found) * content detection plugins now supported * logging switched over to commons-logging * cleaned up javadoc and enabled site generation * misc other cleanup Changes since 0.0.3 * added more unit tests * fixed sub-matches, adjusted magic.xml DTD * new magic.xml file converted from unix magic file * created testByte and testString from testByteArray * testByte is now available and properly applies bitmask * api reworking Changes since 0.0.2 * added junit tests * removed UTF8 encoding from byte array to String conversions Changes since 0.0.1 * cleaned up a lot of the code * added some mime types to the magic file * have regexes available for magic detection * misc other fixes ================================================ FILE: INFO ================================================ http://sf.net/projects/jmimemagic/ ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed 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. ================================================ FILE: LICENSE_HEADER ================================================ /* jMimeMagic(TM) is a Java library for determining the content type of files or streams. For more information, please email arimus@users.sourceforge.net Copyright 2003-2012 David Castro Licensed 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. */ ================================================ FILE: NOTICE ================================================ jMimeMagic Copyright 2003-2017 David Castro Contributions: Thanks to the MMBase team (http://www.mmbase.org/) for doing the work of creating the original basis for the XML version of the magic file. To contribute code or other help, send an email to arimus@users.sourceforge.net or submit patches/bug reports/etc on the jMimeMagic project page: https://github.com/arimus/jmimemagic Developers: David Castro Nate Jones Problems/questions/suggestions: David Castro ================================================ FILE: README ================================================ jMimeMagic (TM) v0.1.5 Copyright (C) 2003-2017, David Castro Contact: David Castro jMimeMagic is a Java library for determining the MIME type of files or streams. Please see LICENSE in this directory for jMimeMagic licensing information. See LICENSE_log4j, LICENSE_oro, LICENSE_xerces, LICENSE_junit respectively for Log4j, ORO, Xerces2 and JUnit licensing information. Log4j, ORO, Xerces2 and JUnit are bundled with jMimeMagic for convenience. ** NOTE ** This API absolutely will change until there is a stable release! Relying on it to not change is probably NOT a safe bet. It is an initial release, given as a (hopefully) better than nothing option. The plan is for this library to become much cleaner and well-architected, but only time will tell. The more you show interest in this library/nudge me, the more likely that will be the case. Comments and feedback greatly welcome. Requirements: Java 2 SDK 1.3+ Apache Maven 1.0.2+ JUnit 3.8.x Jakarta ORO 2.0.x Commons Logging 1.0.x Log4j 1.2.x Xerces 2.4.0 (optional) Building: type 'mvn clean jar:jar' should have your jar file in ./target Testing: Log4j setting can be modified in resources/log4j.properties Run all unit tests ------------------ edit build.properties and create the line 'maven.test.skip=true' type 'maven clean test' Run test against a particular file ---------------------------------- type 'maven clean run -Dclass=net.sf.jmimemagic.Magic -Dargs=' - or - simply ./test in a unix shell (this is similar to the 'file' command in *nix) Maven: To add jMimeMagic as a dependency in a Maven project, you can use the following in the dependencies section of your pom.xml. net.sf.jmimemagic jmimemagic 0.1.3 Contributions: Thanks to the MMBase team (http://www.mmbase.org/) for doing the work of creating the original basis for the XML version of the magic file. To contribute code or other help, send an email to arimus@users.sourceforge.net or submit patches/bug reports/etc on the jMimeMagic project page: http://sf.net/projects/jmimemagic/ Notes: Remember that you will need the proper libraries (XML Parser/Xerces2, Log4j, Commons Logging, and ORO) in the classpath for any applications that use jMimeMagic. If you want to run any of the jUnit tests, then you will also need JUnit in the classpath. Developers: David Castro Nate Jones Problems/questions/suggestions: David Castro ================================================ FILE: TODO ================================================ document the new properties concept in getProperties() for MagicMatch, return all the submatch properties as well need to fix all matchers that are currently invalid for one reason or another, possibly spitting out to the logs why they are invalid, which would help the process and anyone who happens to misconfigure a match in the magic.xml file need to convert the old magic file to the new magic file, enable validation fix sub-match detection (partially fixed, cleanup and add unit tests!!!) need to add more unit tests need to audit code and ensure that a properly crafted file can't be used to cause some security issues and/or system degredation (will always be a prob) make the regular expression syntax pluggable, so those who would rather a regex style other than perl can have it their way files that have multiple matches based on the magic file we can take the first match in one mode and return a collection of matches in another. add in support for % variables in magic file, so that matched data can be used in the description, printf style? support a test token that is a placeholder for the data being able to be any value and can then be used in a description for subtype. Or find another way to do this...via plugins??? support for indirect offsets? support for &, ^ comparators support for multiple string encoding support which allows multiple matches at the same level to be combined for a full description Need to fix problems with some of the type detection. Dates haven't really been worked on. Create a tool for analyzing repositories of multiple file types, which will help determine a proper file "tag" that uniquely identifies a file type. Possibly flesh out the magic file format. Need support multiple tests to make a definitive determination of file type. Support some form of lexical parsing to determine valid source file from code snippets, etc? Lots of other stuff todo, just not listed yet. ==== DONE ==== flag to take hints from file extension as to which matches should be ran first? flag to run in MIME matching mode, no logic other than what is necessary to to determine MIME type switch to commons-logging support for additional info map, allowing additional information to not be displayed in the description, but be available. For instance, MP3 file ID3 tags could be made available for mp3 files * New properties now in matchers basic: now have properties in the style possible for any match. These will then be available in the returned MagicMatch as a java Map. This way, descriptions for a match can be freeform such as "ID3 Tag", but you end up with id3=true as a key/value pair in the map and don't have to do a silly string test or assign a new mime type to the submatch. This will also support plugins, allowing them to add new properties dynamically as needed for the match/submatch. add "plugin" match type by which data will be processed through a plugin for complicated matches and assistance of third-party tools. (detectors) ================================================ FILE: checkstyle.xml ================================================ ================================================ FILE: maven.xml ================================================ ================================================ FILE: pom.xml ================================================ 4.0.0 net.sf.jmimemagic jmimemagic 0.1.5 jar jMimeMagic http://github.com/arimus/jmimemagic/ jMimeMagic is a Java library for determining the content type of files or streams. Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.txt repo A business-friendly OSS license scm:git:git://github.com/arimus/jmimemagic.git scm:git:git://github.com/arimus/jmimemagic.git https://github.com/arimus/jmimemagic arimus David Castro arimus@users.sourceforge.net Developer jmimemagic -7 ndjones Nate Jones ndjones@users.sourceforge.net Developer jmimemagic -7 ossrh jMimeMagic Repo https://oss.sonatype.org/content/repositories/snapshots ossrh jMimeMagic Repo https://oss.sonatype.org/content/repositories/snapshots src/main/filters/filter.properties src/main/resources true *.properties *.xml *.dtd *.json log4j.properties src/test/resources true src/main/resources true org.apache.maven.plugins maven-compiler-plugin 2.3 1.6 1.6 org.apache.maven.plugins maven-resources-plugin 2.4 ${project.build.sourceEncoding} org.apache.maven.plugins maven-source-plugin 2.2.1 attach-sources jar-no-fork org.apache.maven.plugins maven-javadoc-plugin 2.9.1 attach-javadocs jar org.codehaus.mojo exec-maven-plugin 1.2.1 org.sonatype.plugins nexus-staging-maven-plugin 1.6.2 true ossrh https://oss.sonatype.org/ false org.apache.maven.plugins maven-gpg-plugin 1.5 sign-artifacts verify sign org.apache.maven.wagon wagon-ssh-external 1.0-alpha-5 commons-logging commons-logging 1.0.4 compile commons-io commons-io 2.1 compile log4j log4j 1.2.8 runtime junit junit 3.8.1 test UTF-8 UTF-8 ================================================ FILE: project.properties ================================================ # ------------------------------------------------------------------- # P R O J E C T P R O P E R T I E S # ------------------------------------------------------------------- # CVS project maven.scm.cvs.module=jmimemagic # User Interface maven.repo.remote=http://repo1.maven.org/maven maven.xdoc.date=left maven.xdoc.date.format=dd MMMM yyyy HH:mm maven.xdoc.version=${pom.currentVersion} maven.license.licenseFile=${basedir}/LICENSE maven.ui.body.background=white maven.ui.body.foreground=black maven.ui.banner.background=white # Overrides maven.jar.override=on #maven.jar.oro=${basedir}/lib/jakarta-oro-2.0.7.jar # FAQ maven.faq.src.file=${basedir}/xdocs/faq.fml maven.faq.dest.file=${basedir}/xdocs/faq.xml # Checkstyle maven.checkstyle.header.file=${basedir}/LICENSE_HEADER maven.checkstyle.properties=${basedir}/checkstyle.xml # Changelog maven.changelog.factory=org.apache.maven.svnlib.SvnChangeLogFactory maven.changelog.range=90 # Site generation maven.site.failonerror=false # Provided documentation maven.docs.src=${basedir}/xdocs # Remove non-needed links maven.xdoc.developmentProcessUrl= maven.xdoc.poweredby.image= maven.xdoc.poweredby.title= maven.xdoc.poweredby.url= # Maven compilation maven.compile.debug=on maven.compile.deprecation=off maven.compile.optimize=on #maven.compile.executable=jikes maven.compile.target=1.2 maven.compile.source=1.2 # Desired coding conventions for checkstyle maven.checkstyle.format=sun target.dir=target maven.test.skip=true #maven.junit.dir=${maven.test.dest} ================================================ FILE: project.xml ================================================ 3 jmimemagic Java Mime Magic Library 0.1.2 none 2003 net.sf.jmimemagic Determine the content type of files or streams. jMimeMagic is a Java library for determining the content type of files or streams. scm:svn:https://svn.sourceforge.net/svnroot/jmimemagic/trunk scm:svn:https://svn.sourceforge.net/svnroot/jmimemagic/trunk http://svn.sourceforge.net/viewvc/jmimemagic/ arimus@users.sourceforge.net ${basedir}/src/java jar ${basedir}/src/test **/*Test.java / resources true *.properties *.xml *.dtd src/test / resources true *.properties *.xml *.dtd log4j.properties David Castro arimus arimus@users.sourceforge.net jmimemagic Nate Jones ndjones ndjones@users.sourceforge.net jmimemagic junit junit 3.8.1 test oro oro 2.0.8 compile commons-logging commons-logging 1.0.4 compile log4j log4j 1.2.8 runtime xerces xerces 2.4.0 runtime xerces xercesImpl 2.7.1 runtime xml-apis xml-apis 2.0.2 compile xml-apis xmlParserAPIs 2.0.2 compile ================================================ FILE: src/main/filters/filter.properties ================================================ ================================================ FILE: src/main/java/net/sf/jmimemagic/Magic.java ================================================ /* jMimeMagic (TM) is a Java Library for determining the content type of files or streams Copyright (C) 2003-2017 David Castro */ package net.sf.jmimemagic; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import java.io.File; import java.io.IOException; import java.io.PrintStream; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; /** * This class is the primary class for jMimeMagic * * @author $Author: arimus $ * @version $Revision: 1.8 $ */ public class Magic { private static Log log = LogFactory.getLog(Magic.class); private static boolean initialized = false; private static MagicParser magicParser = null; private static Map> hintMap = new HashMap>(); /** * constructor */ public Magic() { log.debug("instantiated"); } /** * Add a hint to use the specified matcher for the given extension * * @param extension DOCUMENT ME! * @param matcher DOCUMENT ME! */ private static void addHint(String extension, MagicMatcher matcher) { if (hintMap.keySet().contains(extension)) { List a = hintMap.get(extension); a.add(matcher); } else { List a = new ArrayList(); a.add(matcher); hintMap.put(extension, a); } } /** * create a parser and initialize it * * @throws MagicParseException DOCUMENT ME! */ public static synchronized void initialize() throws MagicParseException { log.debug("initialize()"); if (!initialized) { log.debug("initializing"); magicParser = new MagicParser(); magicParser.initialize(); // build hint map Iterator i = magicParser.getMatchers().iterator(); while (i.hasNext()) { MagicMatcher matcher = i.next(); String ext = matcher.getMatch().getExtension(); if ((ext != null) && !ext.trim().equals("")) { if (log.isDebugEnabled()) { log.debug("adding hint mapping for extension '" + ext + "'"); } addHint(ext, matcher); } else if (matcher.getMatch().getType().equals("detector")) { String[] exts = matcher.getDetectorExtensions(); for (int j = 0; j < exts.length; j++) { if (log.isDebugEnabled()) { log.debug("adding hint mapping for extension '" + exts[j] + "'"); } addHint(exts[j], matcher); } } } initialized = true; } } /** * return the parsed MagicMatch objects that were created from the magic.xml * definitions * * @return the parsed MagicMatch objects * * @throws MagicParseException DOCUMENT ME! */ public static Collection getMatchers() throws MagicParseException { log.debug("getMatchers()"); if (!initialized) { initialize(); } Iterator i = magicParser.getMatchers().iterator(); List m = new ArrayList(); while (i.hasNext()) { MagicMatcher matcher = (MagicMatcher) i.next(); try { m.add(matcher.clone()); } catch (CloneNotSupportedException e) { log.error("failed to clone matchers"); throw new MagicParseException("failed to clone matchers"); } } return m; } /** * get a match from a stream of data * * @param data DOCUMENT ME! * * @return DOCUMENT ME! * * @throws MagicParseException DOCUMENT ME! * @throws MagicMatchNotFoundException DOCUMENT ME! * @throws MagicException DOCUMENT ME! */ public static MagicMatch getMagicMatch(byte[] data) throws MagicParseException, MagicMatchNotFoundException, MagicException { return getMagicMatch(data, false); } /** * get a match from a stream of data * * @param data DOCUMENT ME! * @param onlyMimeMatch DOCUMENT ME! * * @return DOCUMENT ME! * * @throws MagicParseException DOCUMENT ME! * @throws MagicMatchNotFoundException DOCUMENT ME! * @throws MagicException DOCUMENT ME! */ public static MagicMatch getMagicMatch(byte[] data, boolean onlyMimeMatch) throws MagicParseException, MagicMatchNotFoundException, MagicException { log.debug("getMagicMatch(byte[])"); if (!initialized) { initialize(); } Collection matchers = magicParser.getMatchers(); log.debug("getMagicMatch(byte[]): have " + matchers.size() + " matchers"); MagicMatcher matcher = null; MagicMatch match = null; Iterator i = matchers.iterator(); while (i.hasNext()) { matcher = i.next(); log.debug("getMagicMatch(byte[]): trying to match: " + matcher.getMatch().getMimeType()); try { if ((match = matcher.test(data, onlyMimeMatch)) != null) { log.debug("getMagicMatch(byte[]): matched " + matcher.getMatch().getMimeType()); return match; } } catch (IOException e) { log.error("getMagicMatch(byte[]): " + e); throw new MagicException(e); } catch (UnsupportedTypeException e) { log.error("getMagicMatch(byte[]): " + e); throw new MagicException(e); } } throw new MagicMatchNotFoundException(); } /** * get a match from a file * * @param file the file to match content in * @param extensionHints whether or not to use extension to optimize order of content tests * * @return the MagicMatch object representing a match in the file * * @throws MagicParseException DOCUMENT ME! * @throws MagicMatchNotFoundException DOCUMENT ME! * @throws MagicException DOCUMENT ME! */ public static MagicMatch getMagicMatch(File file, boolean extensionHints) throws MagicParseException, MagicMatchNotFoundException, MagicException { return getMagicMatch(file, extensionHints, false); } /** * get a match from a file * * @param file the file to match content in * @param extensionHints whether or not to use extension to optimize order of content tests * @param onlyMimeMatch only try to get mime type, no submatches are processed when true * * @return the MagicMatch object representing a match in the file * * @throws MagicParseException DOCUMENT ME! * @throws MagicMatchNotFoundException DOCUMENT ME! * @throws MagicException DOCUMENT ME! */ public static MagicMatch getMagicMatch(File file, boolean extensionHints, boolean onlyMimeMatch) throws MagicParseException, MagicMatchNotFoundException, MagicException { log.debug("getMagicMatch(File)"); if (!initialized) { initialize(); } long start = System.currentTimeMillis(); MagicMatcher matcher = null; MagicMatch match = null; // check for extension hints List checked = new ArrayList(); if (extensionHints) { log.debug("trying to use hints first"); String name = file.getName(); int pos = name.lastIndexOf('.'); if (pos > -1) { String ext = name.substring(pos + 1, name.length()); if ((ext != null) && !ext.equals("")) { if (log.isDebugEnabled()) { log.debug("using extension '" + ext + "' for hinting"); } Collection c = hintMap.get(ext); if (c != null) { Iterator i = c.iterator(); while (i.hasNext()) { matcher = (MagicMatcher) i.next(); log.debug("getMagicMatch(File): trying to match: " + matcher.getMatch().getDescription()); try { if ((match = matcher.test(file, onlyMimeMatch)) != null) { log.debug("getMagicMatch(File): matched " + matcher.getMatch().getDescription()); if (log.isDebugEnabled()) { long end = System.currentTimeMillis(); log.debug("found match in '" + (end - start) + "' milliseconds"); } return match; } } catch (UnsupportedTypeException e) { log.error("getMagicMatch(File): " + e); throw new MagicException(e); } catch (IOException e) { log.error("getMagicMatch(File): " + e); throw new MagicException(e); } // add to the already checked list checked.add(matcher); } } } else { log.debug("no file extension, ignoring hints"); } } else { log.debug("no file extension, ignoring hints"); } } Collection matchers = magicParser.getMatchers(); log.debug("getMagicMatch(File): have " + matchers.size() + " matches"); Iterator i = matchers.iterator(); while (i.hasNext()) { matcher = (MagicMatcher) i.next(); if (!checked.contains(matcher)) { log.debug("getMagicMatch(File): trying to match: " + matcher.getMatch().getDescription()); try { if ((match = matcher.test(file, onlyMimeMatch)) != null) { log.debug("getMagicMatch(File): matched " + matcher.getMatch().getDescription()); if (log.isDebugEnabled()) { long end = System.currentTimeMillis(); log.debug("found match in '" + (end - start) + "' milliseconds"); } return match; } } catch (UnsupportedTypeException e) { log.error("getMagicMatch(File): " + e); throw new MagicException(e); } catch (IOException e) { log.error("getMagicMatch(File): " + e); throw new MagicException(e); } } else { log.debug("getMagicMatch(File): already checked, skipping: " + matcher.getMatch().getDescription()); } } throw new MagicMatchNotFoundException(); } /** * print the contents of a magic file * * @param stream DOCUMENT ME! * * @throws MagicParseException DOCUMENT ME! */ public static void printMagicFile(PrintStream stream) throws MagicParseException { if (!initialized) { initialize(); } Collection matchers = Magic.getMatchers(); log.debug("have " + matchers.size() + " matches"); MagicMatcher matcher = null; Iterator i = matchers.iterator(); while (i.hasNext()) { matcher = (MagicMatcher) i.next(); log.debug("printing"); printMagicMatcher(stream, matcher, ""); } } /** * print a magic match * * @param stream DOCUMENT ME! * @param matcher DOCUMENT ME! * @param spacing DOCUMENT ME! */ private static void printMagicMatcher(PrintStream stream, MagicMatcher matcher, String spacing) { stream.println(spacing + "name: " + matcher.getMatch().getDescription()); stream.println(spacing + "children: "); Collection matchers = matcher.getSubMatchers(); Iterator i = matchers.iterator(); while (i.hasNext()) { printMagicMatcher(stream, (MagicMatcher) i.next(), spacing + " "); } } /** * print a magic match * * @param stream DOCUMENT ME! * @param match DOCUMENT ME! * @param spacing DOCUMENT ME! */ public static void printMagicMatch(PrintStream stream, MagicMatch match, String spacing) { stream.println(spacing + "============================="); stream.println(spacing + "mime type: " + match.getMimeType()); stream.println(spacing + "description: " + match.getDescription()); stream.println(spacing + "extension: " + match.getExtension()); stream.println(spacing + "test: " + new String(match.getTest().array())); stream.println(spacing + "bitmask: " + match.getBitmask()); stream.println(spacing + "offset: " + match.getOffset()); stream.println(spacing + "length: " + match.getLength()); stream.println(spacing + "type: " + match.getType()); stream.println(spacing + "comparator: " + match.getComparator()); stream.println(spacing + "============================="); Collection submatches = match.getSubMatches(); Iterator i = submatches.iterator(); while (i.hasNext()) { printMagicMatch(stream, (MagicMatch) i.next(), spacing + " "); } } /** * DOCUMENT ME! * * @param args DOCUMENT ME! */ public static void main(String[] args) { try { if (args.length == 0) { System.err.println("usage: test "); System.exit(1);; } File f = new File(args[0]); if (f.exists()) { MagicMatch match = Magic.getMagicMatch(f, true, false); System.out.println("filename: " + args[0]); printMagicMatch(System.out, match, ""); } else { System.err.println("file '" + f.getCanonicalPath() + "' not found"); } } catch (MagicMatchNotFoundException e) { System.out.println("no match found"); } catch (Exception e) { System.err.println("error: " + e); e.printStackTrace(System.err); } } } ================================================ FILE: src/main/java/net/sf/jmimemagic/MagicDetector.java ================================================ /* jMimeMagic (TM) is a Java Library for determining the content type of files or streams Copyright (C) 2003-2017 David Castro */ package net.sf.jmimemagic; import java.io.File; import java.util.Map; /** * DOCUMENT ME! * * @author $Author$ * @version $Revision$ */ public interface MagicDetector { // get the short name of this detector /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public String getName(); // get the display name of this detector /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public String getDisplayName(); // get the version of this plugin /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public String getVersion(); // get a list of types this detector handles /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public String[] getHandledTypes(); // get a list of file extensions this detector typically deals with /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public String[] getHandledExtensions(); // process the stream and return all matching content types /** * DOCUMENT ME! * * @param data DOCUMENT ME! * @param offset DOCUMENT ME! * @param length DOCUMENT ME! * @param bitmask DOCUMENT ME! * @param comparator DOCUMENT ME! * @param mimeType DOCUMENT ME! * @param params DOCUMENT ME! * * @return DOCUMENT ME! */ public String[] process(byte[] data, int offset, int length, long bitmask, char comparator, String mimeType, Map params); // process the file and return all matching content types /** * DOCUMENT ME! * * @param file DOCUMENT ME! * @param offset DOCUMENT ME! * @param length DOCUMENT ME! * @param bitmask DOCUMENT ME! * @param comparator DOCUMENT ME! * @param mimeType DOCUMENT ME! * @param params DOCUMENT ME! * * @return DOCUMENT ME! */ public String[] process(File file, int offset, int length, long bitmask, char comparator, String mimeType, Map params); } ================================================ FILE: src/main/java/net/sf/jmimemagic/MagicException.java ================================================ /* jMimeMagic (TM) is a Java Library for determining the content type of files or streams Copyright (C) 2003-2017 David Castro */ package net.sf.jmimemagic; /** * Basic JMimeMagic parse exception. This is simply a holder to identify a parsing problem. It * should be extended to identify more specific issues. * * @author $Author: arimus $ * @version $Revision: 1.1 $ */ public class MagicException extends Exception { /** * Default constructor */ public MagicException() { super(); } /** * Create exception with error message * * @param message The error message for this exception */ public MagicException(String message) { super(message); } /** * Create exception based on an existing Throwable * * @param cause The throwable on which we'll base this exception */ public MagicException(Throwable cause) { super(cause); } /** * Create an exception with custom message and throwable info * * @param message The message * @param cause The target Throwable */ public MagicException(String message, Throwable cause) { super(message, cause); } } ================================================ FILE: src/main/java/net/sf/jmimemagic/MagicMatch.java ================================================ /* jMimeMagic (TM) is a Java Library for determining the content type of files or streams Copyright (C) 2003-2017 David Castro */ package net.sf.jmimemagic; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; /** * This class represents a single match test * * @author $Author: arimus $ * @version $Revision: 1.10 $ */ public class MagicMatch implements Cloneable { private static Log log = LogFactory.getLog(MagicMatch.class); private String mimeType = null; private String extension = null; private String description = null; private ByteBuffer test = null; private int offset = 0; private int length = 0; // possible types: // byte, short, long, string, date, beshort, belong, bedate, leshort, // lelong, ledate, regex private String type = ""; private long bitmask = 0xFFFFFFFFL; private char comparator = '\0'; private List subMatches = new ArrayList(0); private Map properties; /** * constructor */ public MagicMatch() { log.debug("instantiated"); } /** * print information about this match * * @return DOCUMENT ME! */ public String print() { StringBuffer string = new StringBuffer(); string.append("\n"); string.append("mime type: ").append(mimeType).append("\n"); string.append("description: ").append(description).append("\n"); string.append("extension: ").append(extension).append("\n"); string.append("offset: ").append(offset).append("\n"); string.append("length: ").append(length).append("\n"); string.append("test: ").append(new String(test.array())).append("\n"); string.append("type: ").append(type).append("\n"); string.append("comparator: ").append(comparator).append("\n"); string.append("bitmask: ").append(bitmask); return string.toString(); } /** * set the mime type for this magic match * * @param value DOCUMENT ME! */ public void setMimeType(String value) { mimeType = value; } /** * get the magic match for this magic match * * @return the mime type for this magic match */ public String getMimeType() { return mimeType; } /** * set the extension for this magic match * * @param value DOCUMENT ME! */ public void setExtension(String value) { extension = value; } /** * get the extension for this magic match * * @return the extension for this magic match */ public String getExtension() { return extension; } /** * set the description for this magic match * * @param value DOCUMENT ME! */ public void setDescription(String value) { description = value; } /** * get the description for this magic match * * @return the description for thie magic match */ public String getDescription() { return description; } /** * set the test value for thie magic match * * @param value DOCUMENT ME! */ public void setTest(ByteBuffer value) { test = value; } /** * get the test value for this magic match * * @return DOCUMENT ME! */ public ByteBuffer getTest() { return test; } /** * set the offset in the stream we are comparing to the test value for this magic match * * @param value DOCUMENT ME! */ public void setOffset(int value) { this.offset = value; } /** * get the offset in the stream we are comparing to the test value for this magic match * * @return the offset for this magic match */ public int getOffset() { return offset; } /** * set the length we are restricting the comparison to for this magic match * * @param value DOCUMENT ME! */ public void setLength(int value) { this.length = value; } /** * get the length we are restricting the comparison to for this magic match * * @return DOCUMENT ME! */ public int getLength() { return length; } /** * set the type of match to perform for this magic match * * @param value DOCUMENT ME! */ public void setType(String value) { this.type = value; } /** * get the type of match for this magic match * * @return DOCUMENT ME! */ public String getType() { return type; } /** * set the bitmask that will be applied for this magic match * * @param value DOCUMENT ME! */ public void setBitmask(String value) { if (value != null) { this.bitmask = Long.decode(value).intValue(); } } /** * get the bitmask that will be applied for this magic match * * @return the bitmask for this magic match */ public long getBitmask() { return bitmask; } /** * set the comparator for this magic match * * @param value DOCUMENT ME! */ public void setComparator(String value) { this.comparator = value.charAt(0); } /** * get the comparator for this magic match * * @return the comparator for this magic match */ public char getComparator() { return comparator; } /** * set the properties for this magic match * * @param properties DOCUMENT ME! */ public void setProperties(Map properties) { this.properties = properties; } /** * get the properties for this magic match * * @return the properties for this magic match */ public Map getProperties() { return properties; } /** * add a submatch to this magic match * * @param m a magic match */ public void addSubMatch(MagicMatch m) { log.debug("adding submatch '" + m.getDescription() + "' to '" + getDescription() + "'"); subMatches.add(m); } /** * set all submatches * * @param a a collection of submatches */ public void setSubMatches(Collection a) { log.debug("setting submatches for '" + getDescription() + "'"); subMatches.clear(); subMatches.addAll(a); } /** * get all submatches for this magic match * * @return a collection of submatches */ public Collection getSubMatches() { return subMatches; } /** * determine if this match or any submatches has the description * * @param desc DOCUMENT ME! * * @return whether or not the description matches */ public boolean descriptionMatches(String desc) { if ((description != null) && description.equals(desc)) { return true; } Collection submatches = getSubMatches(); Iterator i = submatches.iterator(); MagicMatch m = null; while (i.hasNext()) { m = (MagicMatch) i.next(); if (m.descriptionMatches(desc)) { return true; } } return false; } /** * determine if this match or any submatches has the description * * @param desc DOCUMENT ME! * * @return whether or not the description matches */ public boolean mimeTypeMatches(String desc) { if ((mimeType != null) && mimeType.equals(desc)) { return true; } Collection submatches = getSubMatches(); Iterator i = submatches.iterator(); MagicMatch m = null; while (i.hasNext()) { m = (MagicMatch) i.next(); if (m.mimeTypeMatches(desc)) { return true; } } return false; } /** * DOCUMENT ME! * * @return DOCUMENT ME! * * @throws CloneNotSupportedException DOCUMENT ME! */ protected Object clone() throws CloneNotSupportedException { MagicMatch clone = new MagicMatch(); clone.setBitmask(Long.toString(bitmask, 8)); clone.setComparator("" + comparator); clone.setDescription(description); clone.setExtension(extension); clone.setLength(length); clone.setMimeType(mimeType); clone.setOffset(offset); // these properties should only be String types, so we shouldn't have to clone them if(properties!= null) { Map m = new HashMap(); m.putAll(properties); clone.setProperties(m); } Iterator i = subMatches.iterator(); List a = new ArrayList(); while (i.hasNext()) { MagicMatch mm = i.next(); a.add(mm); } clone.setSubMatches(a); clone.setTest(test); clone.setType(type); // TODO Auto-generated method stub return clone; } } ================================================ FILE: src/main/java/net/sf/jmimemagic/MagicMatchNotFoundException.java ================================================ /* jMimeMagic (TM) is a Java Library for determining the content type of files or streams Copyright (C) 2003-2017 David Castro */ package net.sf.jmimemagic; /** * Basic JMimeMagic parse exception. This is simply a holder to identify a parsing problem. It * should be extended to identify more specific issues. * * @author $Author: arimus $ * @version $Revision: 1.1 $ */ public class MagicMatchNotFoundException extends Exception { /** * constructor */ public MagicMatchNotFoundException() { super(); } /** * Create exception with error message * * @param message The error message for this exception */ public MagicMatchNotFoundException(String message) { super(message); } /** * Create exception based on an existing Throwable * * @param cause The throwable on which we'll base this exception */ public MagicMatchNotFoundException(Throwable cause) { super(cause); } /** * Create an exception with custom message and throwable info * * @param message The message * @param cause The target Throwable */ public MagicMatchNotFoundException(String message, Throwable cause) { super(message, cause); } } ================================================ FILE: src/main/java/net/sf/jmimemagic/MagicMatcher.java ================================================ /* jMimeMagic (TM) is a Java Library for determining the content type of files or streams Copyright (C) 2003-2017 David Castro */ package net.sf.jmimemagic; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.regex.Pattern; /** * This class represents a single match test * * @author $Author: arimus $ * @version $Revision: 1.1 $ */ public class MagicMatcher implements Cloneable { private static Log log = LogFactory.getLog(MagicMatcher.class); private List subMatchers = new ArrayList(0); private MagicMatch match = null; /** * constructor */ public MagicMatcher() { log.debug("instantiated"); } /** * DOCUMENT ME! * * @param match DOCUMENT ME! */ public void setMatch(MagicMatch match) { log.debug("setMatch()"); this.match = match; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public MagicMatch getMatch() { log.debug("getMatch()"); return this.match; } /** * test to see if everything is in order for this match * * @return whether or not this match has enough data to be valid */ public boolean isValid() { log.debug("isValid()"); if ((match == null) || (match.getTest() == null)) { return false; } String type = new String(match.getTest().array()); char comparator = match.getComparator(); String description = match.getDescription(); String test = new String(match.getTest().array()); if ((type != null) && !type.equals("") && (comparator != '\0') && ((comparator == '=') || (comparator == '!') || (comparator == '>') || (comparator == '<')) && (description != null) && !description.equals("") && (test != null) && !test.equals("")) { return true; } return false; } /** * add a submatch to this magic match * * @param m a magic match */ public void addSubMatcher(MagicMatcher m) { log.debug("addSubMatcher()"); subMatchers.add(m); } /** * set all submatches * * @param a a collection of submatches */ public void setSubMatchers(Collection a) { log.debug("setSubMatchers(): for match '" + match.getDescription() + "'"); subMatchers.clear(); subMatchers.addAll(a); } /** * get all submatches for this magic match * * @return a collection of submatches */ public Collection getSubMatchers() { log.debug("getSubMatchers()"); return subMatchers; } /** * test to see if this match or any submatches match * * @param f the file that should be used to test the match * @param onlyMimeMatch DOCUMENT ME! * * @return the deepest magic match object that matched * * @throws IOException DOCUMENT ME! * @throws UnsupportedTypeException DOCUMENT ME! */ public MagicMatch test(File f, boolean onlyMimeMatch) throws IOException, UnsupportedTypeException { log.debug("test(File)"); int offset = match.getOffset(); String description = match.getDescription(); String type = match.getType(); log.debug("test(File): testing '" + f.getName() + "' for '" + description + "'"); log.debug("test(File): \n=== BEGIN MATCH INFO =="); log.debug(match.print()); log.debug("test(File): \n=== END MATCH INFO ====\n"); RandomAccessFile file = null; file = new RandomAccessFile(f, "r"); try { int length = 0; if (type.equals("byte")) { length = 1; } else if (type.equals("short") || type.equals("leshort") || type.equals("beshort")) { length = 4; } else if (type.equals("long") || type.equals("lelong") || type.equals("belong")) { length = 8; } else if (type.equals("string")) { length = match.getTest().capacity(); } else if (type.equals("regex")) { final int matchLength = match.getLength(); length = (matchLength == 0) ? (int) file.length() - offset : matchLength; if (length < 0) { length = 0; } } else if (type.equals("detector")) { length = (int) file.length() - offset; if (length < 0) { length = 0; } } else { throw new UnsupportedTypeException("unsupported test type '" + type + "'"); } // we know this match won't work since there isn't enough data for the test if (length > (file.length() - offset)) { return null; } byte[] buf = new byte[length]; file.seek(offset); int bytesRead = 0; int size = 0; boolean gotAllBytes = false; boolean done = false; while (!done) { size = file.read(buf, 0, length - bytesRead); if (size == -1) { throw new IOException("reached end of file before all bytes were read"); } bytesRead += size; if (bytesRead == length) { gotAllBytes = true; done = true; } } log.debug("test(File): stream size is '" + buf.length + "'"); MagicMatch match = null; MagicMatch submatch = null; if (testInternal(buf)) { // set the top level match to this one try { match = getMatch() != null ? (MagicMatch) getMatch() .clone() : null; } catch (CloneNotSupportedException e) { // noop } log.debug("test(File): testing matched '" + description + "'"); // set the data on this match if ((onlyMimeMatch == false) && (subMatchers != null) && (subMatchers.size() > 0)) { log.debug("test(File): testing " + subMatchers.size() + " submatches for '" + description + "'"); for (int i = 0; i < subMatchers.size(); i++) { log.debug("test(File): testing submatch " + i); MagicMatcher m = (MagicMatcher) subMatchers.get(i); if ((submatch = m.test(f, false)) != null) { log.debug("test(File): submatch " + i + " matched with '" + submatch.getDescription() + "'"); match.addSubMatch(submatch); } else { log.debug("test(File): submatch " + i + " doesn't match"); } } } } return match; } finally { try { file.close(); } catch (Exception fce) { } } } /** * test to see if this match or any submatches match * * @param data the data that should be used to test the match * @param onlyMimeMatch DOCUMENT ME! * * @return the deepest magic match object that matched * * @throws IOException DOCUMENT ME! * @throws UnsupportedTypeException DOCUMENT ME! */ public MagicMatch test(byte[] data, boolean onlyMimeMatch) throws IOException, UnsupportedTypeException { log.debug("test(byte[])"); int offset = match.getOffset(); String description = match.getDescription(); String type = match.getType(); String test = new String(match.getTest().array()); String mimeType = match.getMimeType(); log.debug("test(byte[]): testing byte[] data for '" + description + "'"); log.debug("test(byte[]): \n=== BEGIN MATCH INFO =="); log.debug(match.print()); log.debug("test(byte[]): \n=== END MATCH INFO ====\n"); int length = 0; if (type.equals("byte")) { length = 1; } else if (type.equals("short") || type.equals("leshort") || type.equals("beshort")) { length = 4; } else if (type.equals("long") || type.equals("lelong") || type.equals("belong")) { length = 8; } else if (type.equals("string")) { length = match.getTest().capacity(); } else if (type.equals("regex")) { // FIXME - something wrong here, shouldn't have to subtract 1??? length = data.length - offset - 1; if (length < 0) { length = 0; } } else if (type.equals("detector")) { // FIXME - something wrong here, shouldn't have to subtract 1??? length = data.length - offset - 1; if (length < 0) { length = 0; } } else { throw new UnsupportedTypeException("unsupported test type " + type); } byte[] buf = new byte[length]; log.debug("test(byte[]): offset=" + offset + ",length=" + length + ",data length=" + data.length); if ((offset + length) < data.length) { System.arraycopy(data, offset, buf, 0, length); log.debug("test(byte[]): stream size is '" + buf.length + "'"); MagicMatch match = null; MagicMatch submatch = null; if (testInternal(buf)) { // set the top level match to this one try { match = getMatch() != null ? (MagicMatch) getMatch() .clone() : null; } catch (CloneNotSupportedException e) { // noop } log.debug("test(byte[]): testing matched '" + description + "'"); // set the data on this match if ((onlyMimeMatch == false) && (subMatchers != null) && (subMatchers.size() > 0)) { log.debug("test(byte[]): testing " + subMatchers.size() + " submatches for '" + description + "'"); for (int i = 0; i < subMatchers.size(); i++) { log.debug("test(byte[]): testing submatch " + i); MagicMatcher m = (MagicMatcher) subMatchers.get(i); if ((submatch = m.test(data, false)) != null) { log.debug("test(byte[]): submatch " + i + " matched with '" + submatch.getDescription() + "'"); match.addSubMatch(submatch); } else { log.debug("test(byte[]): submatch " + i + " doesn't match"); } } } } return match; } else { return null; } } /** * internal test switch * * @param data DOCUMENT ME! * @return DOCUMENT ME! */ private boolean testInternal(byte[] data) { log.debug("testInternal(byte[])"); if (data.length == 0) { return false; } String type = match.getType(); String test = new String(match.getTest().array()); String mimeType = match.getMimeType(); String description = match.getDescription(); ByteBuffer buffer = ByteBuffer.allocate(data.length); if ((type != null) && (test != null) && (test.length() > 0)) { if (type.equals("string")) { buffer = buffer.put(data); return testString(buffer); } else if (type.equals("byte")) { buffer = buffer.put(data); return testByte(buffer); } else if (type.equals("short")) { buffer = buffer.put(data); return testShort(buffer); } else if (type.equals("leshort")) { buffer = buffer.put(data); buffer.order(ByteOrder.LITTLE_ENDIAN); return testShort(buffer); } else if (type.equals("beshort")) { buffer = buffer.put(data); buffer.order(ByteOrder.BIG_ENDIAN); return testShort(buffer); } else if (type.equals("long")) { buffer = buffer.put(data); return testLong(buffer); } else if (type.equals("lelong")) { buffer = buffer.put(data); buffer.order(ByteOrder.LITTLE_ENDIAN); return testLong(buffer); } else if (type.equals("belong")) { buffer = buffer.put(data); buffer.order(ByteOrder.BIG_ENDIAN); return testLong(buffer); } else if (type.equals("regex")) { return testRegex(new String(data)); } else if (type.equals("detector")) { buffer = buffer.put(data); return testDetector(buffer); // } else if (type.equals("date")) { // return testDate(data, BIG_ENDIAN); // } else if (type.equals("ledate")) { // return testDate(data, LITTLE_ENDIAN); // } else if (type.equals("bedate")) { // return testDate(data, BIG_ENDIAN); } else { log.error("testInternal(byte[]): invalid test type '" + type + "'"); } } else { log.error("testInternal(byte[]): type or test is empty for '" + mimeType + " - " + description + "'"); } return false; } /** * test the data against the test byte * * @param data the data we are testing * * @return if we have a match */ private boolean testByte(ByteBuffer data) { log.debug("testByte()"); String test = new String(match.getTest().array()); char comparator = match.getComparator(); long bitmask = match.getBitmask(); String s = test; byte b = data.get(0); b = (byte) (b & bitmask); log.debug("testByte(): decoding '" + test + "' to byte"); int tst = Integer.decode(test).byteValue(); byte t = (byte) (tst & 0xff); log.debug("testByte(): applying bitmask '" + bitmask + "' to '" + tst + "', result is '" + t + "'"); log.debug("testByte(): comparing byte '" + b + "' to '" + t + "'"); switch (comparator) { case '=': return t == b; case '!': return t != b; case '>': return t > b; case '<': return t < b; } return false; } /** * test the data against the byte array * * @param data the data we are testing * * @return if we have a match */ private boolean testString(ByteBuffer data) { log.debug("testString()"); ByteBuffer test = match.getTest(); char comparator = match.getComparator(); byte[] b = data.array(); byte[] t = test.array(); boolean diff = false; int i = 0; for (i = 0; i < t.length; i++) { log.debug("testing byte '" + b[i] + "' from '" + new String(data.array()) + "' against byte '" + t[i] + "' from '" + new String(test.array()) + "'"); if (t[i] != b[i]) { diff = true; break; } } switch (comparator) { case '=': return !diff; case '!': return diff; case '>': return t[i] > b[i]; case '<': return t[i] < b[i]; } return false; } /** * test the data against a short * * @param data the data we are testing * * @return if we have a match */ private boolean testShort(ByteBuffer data) { log.debug("testShort()"); short val = 0; String test = new String(match.getTest().array()); char comparator = match.getComparator(); long bitmask = match.getBitmask(); val = byteArrayToShort(data); // apply bitmask before the comparison val = (short) (val & (short) bitmask); short tst = 0; try { tst = Integer.decode(test).shortValue(); } catch (NumberFormatException e) { log.error("testShort(): " + e); return false; //if (test.length() == 1) { // tst = new Integer(Character.getNumericValue(test.charAt(0))).shortValue(); //} } log.debug("testShort(): testing '" + Long.toHexString(val) + "' against '" + Long.toHexString(tst) + "'"); switch (comparator) { case '=': return val == tst; case '!': return val != tst; case '>': return val > tst; case '<': return val < tst; } return false; } /** * test the data against a long * * @param data the data we are testing * * @return if we have a match */ private boolean testLong(ByteBuffer data) { log.debug("testLong()"); long val = 0; String test = new String(match.getTest().array()); char comparator = match.getComparator(); long bitmask = match.getBitmask(); val = byteArrayToLong(data); // apply bitmask before the comparison val = val & bitmask; long tst = Long.decode(test).longValue(); log.debug("testLong(): testing '" + Long.toHexString(val) + "' against '" + test + "' => '" + Long.toHexString(tst) + "'"); switch (comparator) { case '=': return val == tst; case '!': return val != tst; case '>': return val > tst; case '<': return val < tst; } return false; } /** * test the data against a regex * * @param text the data we are testing * * @return if we have a match */ private boolean testRegex(String text) { log.debug("testRegex()"); String test = new String(match.getTest().array()); char comparator = match.getComparator(); log.debug("testRegex(): searching for '" + test + "'"); if (comparator == '=') { if (Pattern.matches(test, text)) { return true; } else { return false; } } else if (comparator == '!') { if (Pattern.matches(test, text)) { return false; } else { return true; } } return false; } /** * test the data using a detector * * @param data the data we are testing * * @return if we have a match */ private boolean testDetector(ByteBuffer data) { log.debug("testDetector()"); String detectorClass = new String(match.getTest().array()); try { log.debug("loading class: " + detectorClass); Class c = Class.forName(detectorClass); MagicDetector detector = (MagicDetector) c.newInstance(); String[] types = detector.process(data.array(), match.getOffset(), match.getLength(), match.getBitmask(), match.getComparator(), match.getMimeType(), match.getProperties()); if ((types != null) && (types.length > 0)) { // the match object has no mime type set, so set from the detector class processing match.setMimeType(types[0]); return true; } } catch (ClassNotFoundException e) { log.error("failed to load detector: " + detectorClass, e); } catch (InstantiationException e) { log.error("specified class is not a valid detector class: " + detectorClass, e); } catch (IllegalAccessException e) { log.error("specified class cannot be accessed: " + detectorClass, e); } return false; } /** * Get the extensions for the underlying detectory * * @return DOCUMENT ME! */ public String[] getDetectorExtensions() { log.debug("testDetector()"); String detectorClass = new String(match.getTest().array()); try { log.debug("loading class: " + detectorClass); Class c = Class.forName(detectorClass); MagicDetector detector = (MagicDetector) c.newInstance(); return detector.getHandledTypes(); } catch (ClassNotFoundException e) { log.error("failed to load detector: " + detectorClass, e); } catch (InstantiationException e) { log.error("specified class is not a valid detector class: " + detectorClass, e); } catch (IllegalAccessException e) { log.error("specified class cannot be accessed: " + detectorClass, e); } return new String[0]; } /** * encode a byte as an octal string * * @param b a byte of data * * @return an octal representation of the byte data */ private String byteToOctalString(byte b) { int n1; int n2; int n3; n1 = (b / 32) & 7; n2 = (b / 8) & 7; n3 = b & 7; return String.valueOf(n1) + String.valueOf(n2) + String.valueOf(n3); } /** * convert a byte array to a short * * @param data buffer of byte data * * @return byte array converted to a short */ private short byteArrayToShort(ByteBuffer data) { return data.getShort(0); } /** * convert a byte array to a long * * @param data buffer of byte data * * @return byte arrays (high and low bytes) converted to a long value */ private long byteArrayToLong(ByteBuffer data) { return (long) data.getInt(0); } /** * DOCUMENT ME! * * @return DOCUMENT ME! * * @throws CloneNotSupportedException DOCUMENT ME! */ protected MagicMatcher clone() throws CloneNotSupportedException { MagicMatcher clone = new MagicMatcher(); clone.setMatch((MagicMatch) match.clone()); Iterator i = subMatchers.iterator(); List sub = new ArrayList(); while (i.hasNext()) { MagicMatcher m = (MagicMatcher) i.next(); sub.add(m.clone()); } clone.setSubMatchers(sub); return clone; } } ================================================ FILE: src/main/java/net/sf/jmimemagic/MagicParseException.java ================================================ /* jMimeMagic (TM) is a Java Library for determining the content type of files or streams Copyright (C) 2003-2017 David Castro */ package net.sf.jmimemagic; /** * Basic JMimeMagic parse exception. This is simply a holder to identify a parsing problem. It * should be extended to identify more specific issues. * * @author $Author: arimus $ * @version $Revision: 1.1 $ */ public class MagicParseException extends Exception { /** * Default constructor */ public MagicParseException() { super(); } /** * Create exception with error message * * @param message The error message for this exception */ public MagicParseException(String message) { super(message); } /** * Create exception based on an existing Throwable * * @param cause The throwable on which we'll base this exception */ public MagicParseException(Throwable cause) { super(cause); } /** * Create an exception with custom message and throwable info * * @param message The message * @param cause The target Throwable */ public MagicParseException(String message, Throwable cause) { super(message, cause); } } ================================================ FILE: src/main/java/net/sf/jmimemagic/MagicParser.java ================================================ /* jMimeMagic (TM) is a Java Library for determining the content type of files or streams Copyright (C) 2003-2017 David Castro */ package net.sf.jmimemagic; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException; import org.xml.sax.SAXParseException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.XMLReaderFactory; import java.io.ByteArrayOutputStream; import java.net.URL; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; /** * DOCUMENT ME! * * @author $Author$ * @version $Revision$ */ public class MagicParser extends DefaultHandler implements ContentHandler, ErrorHandler { private static String magicFile = "/magic.xml"; private static Log log = LogFactory.getLog(MagicParser.class); // Namespaces feature id (http://xml.org/sax/features/namespaces). protected static final String NAMESPACES_FEATURE_ID = "http://xml.org/sax/features/namespaces"; // Validation feature id (http://xml.org/sax/features/validation). protected static final String VALIDATION_FEATURE_ID = "http://xml.org/sax/features/validation"; // Schema validation feature id (http://apache.org/xml/features/validation/schema). protected static final String SCHEMA_VALIDATION_FEATURE_ID = "http://apache.org/xml/features/validation/schema"; // Schema full checking feature id (http://apache.org/xml/features/validation/schema-full-checking). protected static final String SCHEMA_FULL_CHECKING_FEATURE_ID = "http://apache.org/xml/features/validation/schema-full-checking"; // Default parser name. protected static final String DEFAULT_PARSER_NAME = "org.apache.xerces.parsers.SAXParser"; // Default namespaces support (true). protected static final boolean DEFAULT_NAMESPACES = true; // Default validation support (false). protected static final boolean DEFAULT_VALIDATION = false; // Default Schema validation support (false). protected static final boolean DEFAULT_SCHEMA_VALIDATION = false; // Default Schema full checking support (false). protected static final boolean DEFAULT_SCHEMA_FULL_CHECKING = false; private boolean initialized = false; private XMLReader parser = null; private List stack = new ArrayList(); private Collection matchers = new ArrayList(); private MagicMatcher matcher = null; private MagicMatch match = null; private Map properties = null; private String finalValue = ""; private boolean isMimeType = false; private boolean isExtension = false; private boolean isDescription = false; private boolean isTest = false; /** * constructor */ public MagicParser() { log.debug("instantiated"); } /** * parse the xml file and create our MagicMatcher object list * * @throws MagicParseException DOCUMENT ME! */ public synchronized void initialize() throws MagicParseException { boolean namespaces = DEFAULT_NAMESPACES; boolean validation = DEFAULT_VALIDATION; boolean schemaValidation = DEFAULT_SCHEMA_VALIDATION; boolean schemaFullChecking = DEFAULT_SCHEMA_FULL_CHECKING; if (!initialized) { // use default parser try { parser = XMLReaderFactory.createXMLReader(); } catch (Exception e) { try { log.debug("falling back to default parser: " + DEFAULT_PARSER_NAME); parser = XMLReaderFactory.createXMLReader(DEFAULT_PARSER_NAME); } catch (Exception ee) { throw new MagicParseException("unable to instantiate parser"); } } // set parser features try { parser.setFeature(NAMESPACES_FEATURE_ID, namespaces); } catch (SAXException e) { log.debug("initialize(): warning: Parser does not support feature (" + NAMESPACES_FEATURE_ID + ")"); } try { parser.setFeature(VALIDATION_FEATURE_ID, validation); } catch (SAXException e) { log.debug("initialize(): warning: Parser does not support feature (" + VALIDATION_FEATURE_ID + ")"); } try { parser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, schemaValidation); } catch (SAXNotRecognizedException e) { // ignore } catch (SAXNotSupportedException e) { log.debug("initialize(): warning: Parser does not support feature (" + SCHEMA_VALIDATION_FEATURE_ID + ")"); } try { parser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, schemaFullChecking); } catch (SAXNotRecognizedException e) { // ignore } catch (SAXNotSupportedException e) { log.debug("initialize(): warning: Parser does not support feature (" + SCHEMA_FULL_CHECKING_FEATURE_ID + ")"); } // set handlers parser.setErrorHandler(this); parser.setContentHandler(this); // parse file try { // get the magic file URL URL resource = MagicParser.class.getResource(magicFile); String magicURL = resource.toString(); if (magicURL == null) { log.error("initialize(): couldn't load '" + magicURL + "'"); throw new MagicParseException("couldn't load '" + magicURL + "'"); } parser.parse(magicURL); } catch (SAXParseException e) { // ignore } catch (Exception e) { e.printStackTrace(); throw new MagicParseException("parse error occurred - " + e.getMessage()); } initialized = true; } } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public Collection getMatchers() { return matchers; } /** * DOCUMENT ME! * * @throws SAXException DOCUMENT ME! */ public void startDocument() throws SAXException { log.debug("startDocument()"); } /** * DOCUMENT ME! * * @throws SAXException DOCUMENT ME! */ public void endDocument() throws SAXException { log.debug("endDocument()"); } /** * DOCUMENT ME! * * @param target DOCUMENT ME! * @param data DOCUMENT ME! * * @throws SAXException DOCUMENT ME! */ public void processingInstruction(String target, String data) throws SAXException { // do nothing } /** * DOCUMENT ME! * * @param ch DOCUMENT ME! * @param offset DOCUMENT ME! * @param length DOCUMENT ME! * * @throws SAXException DOCUMENT ME! */ public void characters(char[] ch, int offset, int length) throws SAXException { String value = new String(ch, offset, length); log.debug("characters(): value is '" + value + "'"); finalValue += value; } /** * DOCUMENT ME! * * @param ch DOCUMENT ME! * @param offset DOCUMENT ME! * @param length DOCUMENT ME! * * @throws SAXException DOCUMENT ME! */ public void ignorableWhitespace(char[] ch, int offset, int length) throws SAXException { // do nothing } /** * DOCUMENT ME! * * @param uri DOCUMENT ME! * @param localName DOCUMENT ME! * @param qname DOCUMENT ME! * @param attributes DOCUMENT ME! * * @throws SAXException DOCUMENT ME! */ public void startElement(String uri, String localName, String qname, Attributes attributes) throws SAXException { log.debug("startElement()"); log.debug("startElement(): localName is '" + localName + "'"); // create a new matcher if (localName.equals("match")) { log.debug("startElement(): creating new matcher"); // match to hold data match = new MagicMatch(); // our matcher matcher = new MagicMatcher(); matcher.setMatch(match); } // these are subelements of matcher, but also occur elsewhere if (matcher != null) { if (localName.equals("mimetype")) { isMimeType = true; } else if (localName.equals("extension")) { isExtension = true; } else if (localName.equals("description")) { isDescription = true; } else if (localName.equals("test")) { isTest = true; int length = attributes.getLength(); for (int i = 0; i < length; i++) { String attrLocalName = attributes.getLocalName(i); String attrValue = attributes.getValue(i); if (attrLocalName.equals("offset")) { if (!attrValue.equals("")) { match.setOffset(new Integer(attrValue).intValue()); log.debug("startElement(): setting offset to '" + attrValue + "'"); } } else if (attrLocalName.equals("length")) { if (!attrValue.equals("")) { match.setLength(new Integer(attrValue).intValue()); log.debug("startElement(): setting length to '" + attrValue + "'"); } } else if (attrLocalName.equals("type")) { match.setType(attrValue); log.debug("startElement(): setting type to '" + attrValue + "'"); } else if (attrLocalName.equals("bitmask")) { if (!attrValue.equals("")) { match.setBitmask(attrValue); log.debug("startElement(): setting bitmask to '" + attrValue + "'"); } } else if (attrLocalName.equals("comparator")) { match.setComparator(attrValue); log.debug("startElement(): setting comparator to '" + attrValue + "'"); } } } else if (localName.equals("property")) { int length = attributes.getLength(); String name = null; String value = null; for (int i = 0; i < length; i++) { String attrLocalName = attributes.getLocalName(i); String attrValue = attributes.getValue(i); if (attrLocalName.equals("name")) { if (!attrValue.equals("")) { name = attrValue; } } else if (attrLocalName.equals("value")) { if (!attrValue.equals("")) { value = attrValue; } } } // save the property to our map if ((name != null) && (value != null)) { if (properties == null) { properties = new HashMap(); } if (!properties.containsKey(name)) { properties.put(name, value); log.debug("startElement(): setting property '" + name + "'='" + value + "'"); } else { log.debug("startElement(): not setting property '" + name + "', duplicate key"); } } } else if (localName.equals("match-list")) { log.debug("startElement(): found submatcher list"); // this means we are processing a child match, so we need to push // the existing match on the stack log.debug("startElement(): pushing current matcher to stack"); stack.add(matcher); } else { // we don't care about this type } } } /** * DOCUMENT ME! * * @param uri DOCUMENT ME! * @param localName DOCUMENT ME! * @param qname DOCUMENT ME! * * @throws SAXException DOCUMENT ME! */ public void endElement(String uri, String localName, String qname) throws SAXException { log.debug("endElement()"); log.debug("endElement(): localName is '" + localName + "'"); // determine which tag these chars are for and save them if (isMimeType) { isMimeType = false; match.setMimeType(finalValue); log.debug("characters(): setting mimetype to '" + finalValue + "'"); } else if (isExtension) { isExtension = false; match.setExtension(finalValue); log.debug("characters(): setting extension to '" + finalValue + "'"); } else if (isDescription) { isDescription = false; match.setDescription(finalValue); log.debug("characters(): setting description to '" + finalValue + "'"); } else if (isTest) { isTest = false; match.setTest(convertOctals(finalValue)); log.debug("characters(): setting test to '" + convertOctals(finalValue) + "'"); } else { // do nothing } finalValue = ""; // need to save the current matcher here if it is filled out enough and // we have an /matcher if (localName.equals("match")) { // FIXME - make sure the MagicMatcher isValid() test works if (matcher.isValid()) { // set the collected properties on this matcher match.setProperties(properties); // add root match if (stack.size() == 0) { log.debug("endElement(): adding root matcher"); matchers.add(matcher); } else { // we need to add the match to it's parent which is on the // stack log.debug("endElement(): adding sub matcher"); MagicMatcher m = (MagicMatcher) stack.get(stack.size() - 1); m.addSubMatcher(matcher); } } else { // don't add invalid matchers log.info("endElement(): not adding invalid matcher '" + match.getDescription() + "'"); } matcher = null; properties = null; // restore matcher from the stack if we have an /matcher-list } else if (localName.equals("match-list")) { if (stack.size() > 0) { log.debug("endElement(): popping from the stack"); matcher = (MagicMatcher) stack.get(stack.size() - 1); // pop from the stack stack.remove(matcher); } } else if (localName.equals("mimetype")) { isMimeType = false; } else if (localName.equals("extension")) { isExtension = false; } else if (localName.equals("description")) { isDescription = false; } else if (localName.equals("test")) { isTest = false; } } /** * DOCUMENT ME! * * @param ex DOCUMENT ME! * * @throws SAXException DOCUMENT ME! */ public void warning(SAXParseException ex) throws SAXException { // FIXME } /** * DOCUMENT ME! * * @param ex DOCUMENT ME! * * @throws SAXException DOCUMENT ME! */ public void error(SAXParseException ex) throws SAXException { // FIXME throw ex; } /** * DOCUMENT ME! * * @param ex DOCUMENT ME! * * @throws SAXException DOCUMENT ME! */ public void fatalError(SAXParseException ex) throws SAXException { // FIXME throw ex; } /** * replaces octal representations of bytes, written as \ddd to actual byte values. * * @param s a string with encoded octals * * @return string with all octals decoded */ private ByteBuffer convertOctals(String s) { int beg = 0; int end = 0; int chr; ByteArrayOutputStream buf = new ByteArrayOutputStream(); while ((end = s.indexOf('\\', beg)) != -1) { if (s.charAt(end + 1) != '\\') { //log.debug("appending chunk '"+s.substring(beg, end)+"'"); for (int z = beg; z < end; z++) { buf.write((int) s.charAt(z)); } //log.debug("found \\ at position "+end); //log.debug("converting octal '"+s.substring(end, end+4)+"'"); if ((end + 4) <= s.length()) { try { chr = Integer.parseInt(s.substring(end + 1, end + 4), 8); //log.debug("converted octal '"+s.substring(end+1,end+4)+"' to '"+chr); //log.debug("converted octal back to '"+Integer.toOctalString(chr)); //log.debug("converted '"+s.substring(end+1,end+4)+"' to "+chr+"/"+((char)chr)); buf.write(chr); beg = end + 4; end = beg; } catch (NumberFormatException nfe) { //log.debug("not an octal"); buf.write((int) '\\'); beg = end + 1; end = beg; } } else { //log.debug("not an octal, not enough chars left in string"); buf.write((int) '\\'); beg = end + 1; end = beg; } } else { //log.debug("appending \\"); buf.write((int) '\\'); beg = end + 1; end = beg; } } if (end < s.length()) { for (int z = beg; z < s.length(); z++) { buf.write((int) s.charAt(z)); } } try { log.debug("convertOctals(): returning buffer size '" + buf.size() + "'"); ByteBuffer b = ByteBuffer.allocate(buf.size()); return b.put(buf.toByteArray()); } catch (Exception e) { log.error("convertOctals(): error parsing string: " + e); return ByteBuffer.allocate(0); } } } ================================================ FILE: src/main/java/net/sf/jmimemagic/UnsupportedTypeException.java ================================================ /* jMimeMagic (TM) is a Java Library for determining the content type of files or streams Copyright (C) 2003-2017 David Castro */ package net.sf.jmimemagic; /** * JMimeMagic unsupported test type exception. This exception is thrown when an unsupported * test type is specified in a mime magic test * * @author $Author: arimus $ * @version $Revision: 1.1 $ */ public class UnsupportedTypeException extends Exception { /** * Default constructor */ public UnsupportedTypeException() { super(); } /** * Create exception with error message * * @param message The error message for this exception */ public UnsupportedTypeException(String message) { super(message); } /** * Create exception based on an existing Throwable * * @param cause The throwable on which we'll base this exception */ public UnsupportedTypeException(Throwable cause) { super(cause); } /** * Create an exception with custom message and throwable info * * @param message The message * @param cause The target Throwable */ public UnsupportedTypeException(String message, Throwable cause) { super(message, cause); } } ================================================ FILE: src/main/java/net/sf/jmimemagic/detectors/TextFileDetector.java ================================================ /* jMimeMagic (TM) is a Java Library for determining the content type of files or streams Copyright (C) 2003-2017 David Castro */ package net.sf.jmimemagic.detectors; import net.sf.jmimemagic.MagicDetector; import org.apache.commons.io.ByteOrderMark; import org.apache.commons.io.IOUtils; import org.apache.commons.io.input.BOMInputStream; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import java.io.*; import java.util.Map; import java.util.regex.Pattern; /** * DOCUMENT ME! * * @author $Author$ * @version $Revision$ */ public class TextFileDetector implements MagicDetector { private static Log log = LogFactory.getLog(TextFileDetector.class); /** * Creates a new TextFileDetector object. */ public TextFileDetector() { super(); } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public String getDisplayName() { return "Text File Detector"; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public String getVersion() { return "0.1"; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public String[] getHandledExtensions() { return new String[] { "txt", "text" }; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public String[] getHandledTypes() { return new String[] { "text/plain" }; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public String getName() { return "textfiledetector"; } /** * DOCUMENT ME! * * @param data DOCUMENT ME! * @param offset DOCUMENT ME! * @param length DOCUMENT ME! * @param bitmask DOCUMENT ME! * @param comparator DOCUMENT ME! * @param mimeType DOCUMENT ME! * @param params DOCUMENT ME! * * @return DOCUMENT ME! */ public String[] process(byte[] data, int offset, int length, long bitmask, char comparator, String mimeType, Map params) { log.debug("processing stream data"); BOMInputStream bomIn = null; try { bomIn = new BOMInputStream(new ByteArrayInputStream(data), ByteOrderMark.UTF_8, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE); if (bomIn.hasBOM()) { return new String[] { "text/plain" }; } } catch (IOException e) { log.error("TextFileDetector: error detecting byte order mark"); } finally { IOUtils.closeQuietly(bomIn); } try { String s = new String(data, "UTF-8"); if (!Pattern.matches("/[^[:ascii:][:space:]]/", s)) { return new String[] { "text/plain" }; } } catch (UnsupportedEncodingException e) { log.error("TextFileDetector: failed to process data"); } return null; } /** * DOCUMENT ME! * * @param file DOCUMENT ME! * @param offset DOCUMENT ME! * @param length DOCUMENT ME! * @param bitmask DOCUMENT ME! * @param comparator DOCUMENT ME! * @param mimeType DOCUMENT ME! * @param params DOCUMENT ME! * * @return DOCUMENT ME! */ public String[] process(File file, int offset, int length, long bitmask, char comparator, String mimeType, Map params) { log.debug("processing file data"); BufferedInputStream is =null; try { is = new BufferedInputStream(new FileInputStream(file)); byte[] b = new byte[length]; int n = is.read(b, offset, length); if (n > 0) { return process(b, offset, length, bitmask, comparator, mimeType, params); } } catch (IOException e) { log.error("TextFileDetector: error", e); } finally { IOUtils.closeQuietly(is); } return null; } } ================================================ FILE: src/main/java/net/sf/jmimemagic/detectors/package.html ================================================

net.sf.jmimemagic

This package contains detectors for jmimemagic ================================================ FILE: src/main/java/net/sf/jmimemagic/package.html ================================================

net.sf.jmimemagic.detectors

This package contains the main classes for jmimemagic ================================================ FILE: src/main/resources/log4j.properties ================================================ log4j.rootCategory=ERROR, file log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=jmimemagic.log log4j.appender.file.MaxFileSize=10000KB log4j.appender.file.MaxBackupIndex=1 log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d [%t] %-5p %c - %m%n # Print only messages of priority WARN or above in the package com.foo. log4j.category.net.sf.jmimemagic=ERROR ================================================ FILE: src/main/resources/magic.dtd ================================================ ================================================ FILE: src/main/resources/magic.xml ================================================ 0.2 dcastro magic file audio/mp3 MP3 0xfffa b, 32 kBits 0x10 b, 40 kBits 0x20 b, 48 kBits 0x30 b, 56 kBits 0x40 b, 64 kBits 0x50 b, 80 kBits 0x60 b, 96 kBits 0x70 b, 112 kBits 0x80 b, 128 kBits 0x90 b, 160 kBits 0xA0 b, 192 kBits 0xB0 b, 224 kBits 0xC0 b, 256 kBits 0xD0 b, 320 kBits 0xE0 b, 44.1 kHz 0x00 b, 48 kHz 0x04 b, 32 kHz 0x08 b, Stereo 0x00 b, JStereo 0x40 b, Dual-Ch 0x80 b, Mono 0xC0 image/gif GIF image data GIF8 b, version 8%s, b, version 8%s, 7a b, version 8%s, b, version 8%s, 9a video/mpeg mpg MPEG video stream data 0x1b3 video/mpeg mpg MPEG system stream data 0x1ba ??? ??? MP 0xfff0 ??? ??? \b 0x8 ??? ??? \b3 0x2 ??? ??? 32 kBits 0x10 ??? ??? 40 kBits 0x20 ??? ??? 48 kBits 0x30 ??? ??? 56 kBits 0x40 ??? ??? 64 kBits 0x50 ??? ??? 80 kBits 0x60 ??? ??? 96 kBits 0x70 ??? ??? 112 kBits 0x80 ??? ??? 128 kBits 0x90 ??? ??? 160 kBits 0xa0 ??? ??? 192 kBits 0xb0 ??? ??? 224 kBits 0xc0 ??? ??? 256 kBits 0xd0 ??? ??? 320 kBits 0xe0 ??? ??? \b2 0x4 ??? ??? 32 kBits 0x10 ??? ??? 48 kBits 0x20 ??? ??? 56 kBits 0x30 ??? ??? 64 kBits 0x40 ??? ??? 80 kBits 0x50 ??? ??? 96 kBits 0x60 ??? ??? 112 kBits 0x70 ??? ??? 128 kBits 0x80 ??? ??? 160 kBits 0x90 ??? ??? 192 kBits 0xa0 ??? ??? 224 kBits 0xb0 ??? ??? 256 kBits 0xc0 ??? ??? 320 kBits 0xd0 ??? ??? 384 kBits 0xe0 ??? ??? 44.1 kHz 0x0 ??? ??? 48 kHz 0x4 ??? ??? 32 kHz 0x8 ??? ??? \b 0x0 ??? ??? \b3 0x2 ??? ??? \b2 0x4 ??? ??? 8 kBits 0x10 ??? ??? 16 kBits 0x20 ??? ??? 24 kBits 0x30 ??? ??? 32 kBits 0x40 ??? ??? 40 kBits 0x50 ??? ??? 48 kBits 0x60 ??? ??? 56 kBits 0x70 ??? ??? 64 kBits 0x80 ??? ??? 80 kBits 0x90 ??? ??? 96 kBits 0xa0 ??? ??? 112 kBits 0xb0 ??? ??? 128 kBits 0xc0 ??? ??? 144 kBits 0xd0 ??? ??? 160 kBits 0xe0 ??? ??? 22.05 kHz 0x0 ??? ??? 24 kHz 0x4 ??? ??? 16 kHz 0x8 ??? ??? Stereo 0x0 ??? ??? JStereo 0x40 ??? ??? Dual-Ch 0x80 ??? ??? Mono 0xc0 ??? ??? FLI file 0xaf11 ??? ??? - %d frames, ??? ??? width=%d pixels, ??? ??? height=%d pixels, ??? ??? depth=%d, ??? ??? ticks/frame=%d ??? ??? FLC file 0xaf12 ??? ??? - %d frames ??? ??? width=%d pixels, ??? ??? height=%d pixels, ??? ??? depth=%d, ??? ??? ticks/frame=%d ??? ??? Silicon Graphics movie file MOVI video/quicktime mov Apple QuickTime movie file (moov) moov video/quicktime mov Apple QuickTime movie file (mdat) mdat ??? ??? Applixware *BEGIN ??? ??? Words Document WORDS ??? ??? Graphic GRAPHICS ??? ??? Bitmap RASTER ??? ??? Spreadsheet SPREADSHEETS ??? ??? Macro MACRO ??? ??? Builder Object BUILDER application/x-tar tar POSIX tar archive ustar application/x-tar tar tar archive ustar \000GNU application/vnd.openxmlformats-officedocument.wordprocessingml.document docx Microsoft Office Open XML Document PK\003\004 application/vnd.openxmlformats-officedocument.wordprocessingml.document docm Microsoft Office Open XML Document PK\003\004 application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx Microsoft Office Open XML Workbook PK\003\004 application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsm Microsoft Office Open XML Workbook PK\003\004 application/vnd.openxmlformats-officedocument.presentationml.presentation pptx Microsoft Office Open XML Workbook PK\003\004 application/vnd.openxmlformats-officedocument.presentationml.presentation pptm Microsoft Office Open XML Workbook PK\003\004 application/zip zip Zip archive data PK\003\004 application/zip zip at least v0.9 to extract 0x9 application/zip zip at least v1.0 to extract 0xa application/zip zip at least v1.1 to extract 0xb application/zip zip at least v2.0 to extract 0x14 ??? ??? Standard MIDI data MThd ??? ??? (format %d) 0x0 ??? ??? using %d tracks 0x1 ??? ??? Creative Music (CMF) data CTMF ??? ??? SoundBlaster instrument data SBI ??? ??? Creative Labs voice data Creative Voice File ??? ??? 0x1a ??? ??? - version %d 0x0 ??? ??? \b.%d 0x0 ??? ??? Extended MOD sound data, EMOD ??? ??? version %d ??? ??? \b.%d, ??? ??? %d instruments ??? ??? (module) 0x0 ??? ??? (song) 0x1 ??? ??? realaudio sound file 0x2e7261fd ??? ??? file .RMF\000\000\000realmedia ??? ??? data \037\235compress'd ??? ??? block compressed 0x0 ??? ??? %d bits application/x-gzip gz gzip compressed data \037\213 application/x-gzip gz reserved method, 0x8 application/x-gzip gz deflated, 0x8 application/x-gzip gz ASCII, 0x1 application/x-gzip gz continuation, 0x2 application/x-gzip gz extra field, 0x4 application/x-gzip gz original filename, 0x8 application/x-gzip gz comment, 0x10 application/x-gzip gz encrypted, 0x20 application/x-gzip gz last modified: %s, application/x-gzip gz max compression, 0x2 application/x-gzip gz max speed, 0x4 application/x-gzip gz os: MS-DOS 0x0 application/x-gzip gz os: Amiga 0x1 application/x-gzip gz os: VMS 0x2 application/x-gzip gz os: Unix 0x3 application/x-gzip gz os: Atari 0x5 application/x-gzip gz os: OS/2 0x6 application/x-gzip gz os: MacOS 0x7 application/x-gzip gz os: Tops/20 0xa application/x-gzip gz os: Win/32 0xb application/x-bzip2 bz2 bzip2 compressed data BZh application/x-bzip2 bz2 block size = %c00k 0x2f application/x-shockwave-flash swf Macromedia Flash data, FWS application/x-shockwave-flash swf version %d ??? ??? PostScript Type 1 font text %!PS-AdobeFont-1. ??? ??? (%s) \000 ??? ??? PostScript Type 1 font program data %!PS-AdobeFont-1.0 application/postscript ps PostScript Level 2 program data %!PS-Adobe-2.0 application/vnd.framemaker ??? FrameMaker document <MakerFile application/vnd.framemaker ??? (5.5 5.5 application/vnd.framemaker ??? (5.0 5.0 application/vnd.framemaker ??? (4.0 4.0 application/vnd.framemaker ??? (3.0 3.0 application/vnd.framemaker ??? (2.0 2.0 application/vnd.framemaker ??? (1.0 1.0 application/vnd.framemaker ??? %c) ??? ??? FrameMaker MIF (ASCII) file <MIFFile ??? ??? (4.0) 4.0 ??? ??? (3.0) 3.0 ??? ??? (2.0) 2.0 ??? ??? (1.x) 1.0 ??? ??? FrameMaker Dictionary text <MakerDictionary ??? ??? (3.0) 3.0 ??? ??? (2.0) 2.0 ??? ??? (1.x) 1.0 ??? ??? FrameMaker Font file <MakerScreenFont ??? ??? (%s) 1.01 ??? ??? FrameMaker MML file <MML ??? ??? FrameMaker Book file <BookFile ??? ??? (3.0 3.0 ??? ??? (2.0 2.0 ??? ??? (1.0 1.0 ??? ??? %c) ??? ??? Intermediate Print File FrameMaker IPL file <Maker ??? ??? GIMP gradient data GIMP Gradient ??? ??? GIMP XCF image data, gimp xcf file ??? ??? %ld x ??? ??? %ld, ??? ??? RGB Color 0x0 ??? ??? Greyscale 0x1 ??? ??? Indexed Color 0x2 ??? ??? GIMP pattern data, GPAT ??? ??? %s ??? ??? GIMP brush data GIMP ??? ??? PBM image text P1 ??? ??? PGM image text P2 ??? ??? PPM image text P3 image/x-portable-bitmap pbm PBM "rawbits" image data P4 ??? ??? PGM "rawbits" image data P5 image/x-portable-graymap ??? PPM "rawbits" image data P6 ??? ??? NIFF image data IIN1 image/tiff tif TIFF image data, big-endian MM\000\052 image/tiff tif TIFF image data, little-endian II\052\000 image/tiff tiff TIFF image data, big-endian MM\000\052 image/tiff tiff TIFF image data, little-endian II\052\000 image/png png PNG image data, \211NG image/png png CORRUPTED, 0xd0a1a0a image/png png 0xd0a1a0a image/png png %ld x image/png png %ld, image/png png %d-bit image/png png grayscale, 0x0 image/png png \b/color RGB, 0x2 image/png png colormap, 0x3 image/png png gray+alpha, 0x4 image/png png \b/color RGBA, 0x6 image/png png non-interlaced 0x0 image/png png interlaced 0x1 image/png png PNG image data, CORRUPTED PNG image/gif gif GIF image data GIF8 image/gif gif version 8%s, 7a image/gif gif version 8%s, 9a image/gif gif %hd x 0x0 image/gif gif %hd, 0x0 ??? ??? window manager raster image data \361\000@\273CMU ??? ??? %d x 0x0 ??? ??? %d, 0x0 ??? ??? %d-bit 0x0 application/x-miff miff MIFF image data id=ImageMagick image/g3fax fax group 3 fax data PC Research, Inc image/g3fax fax normal resolution (204x98 DPI) 0x0 image/g3fax fax fine resolution (204x196 DPI) 0x1 image/jpeg jpg JPEG image data 0xffd8 image/jpeg jpg JFIF standard JFIF image/jpeg jpg JPEG image data, HSI proprietary hsi1 ??? ??? PC icon data IC ??? ??? PC pointer image data PI ??? ??? PC color icon data CI ??? ??? PC color pointer image data CP ??? ??? X pixmap image text /* XPM */ ??? ??? iff image data Imagefile version- ??? ??? %s \000 ??? ??? Kodak Photo CD image pack file PCD_IPI ??? ??? Kodak Photo CD overview pack file PCD_OPA ??? ??? %s Visio (TM) Drawing application/java class Compiled Java Class Data 0xcafebabe ??? ??? Java Class Version 1.2 0x0000002e ??? ??? Java Class Version 1.3 0x0000002f ??? ??? Java Class Version 1.4 0x00000030 ??? ??? Java Class Version 1.5 0x00000031 ??? ??? Java serialization data 0xaced ??? ??? version %d 0x4 application/mac-binhex40 ??? BinHex binary text must be converted with BinHex application/mac-binhex40 ??? version %.3s ??? ??? StuffIt Archive (data) SIT! ??? ??? : %s ??? ??? StuffIt Archive (rsrc + data) SIT! ??? ??? : %s ??? ??? StuffIt Deluxe (data) SITD ??? ??? : %s ??? ??? StuffIt Deluxe (rsrc + data) SITD ??? ??? : %s ??? ??? StuffIt Deluxe Segment (data) Seg ??? ??? : %s ??? ??? StuffIt Deluxe Segment (rsrc + data) Seg ??? ??? : %s application/pdf pdf Macintosh PDF File (data) PDF application/pdf pdf : %s application/pdf pdf Macintosh PDF File(rsrc + data) PDF application/pdf pdf : %s ??? ??? MIME entity text MIME-Version: ??? ??? Content-Type: ??? ??? %s \000 ??? ??? Content-Type ??? ??? %s \000 ??? ??? MS-DOS batch file text @echo off ??? ??? Windows PE PE\000\000MS ??? ??? 32-bit 0x0 ??? ??? unknown processor 0x0 ??? ??? Intel 80386 0x14c ??? ??? MIPS R4000 0x166 ??? ??? Alpha 0x184 ??? ??? Motorola 68000 0x268 ??? ??? PowerPC 0x1f0 ??? ??? PA-RISC 0x290 ??? ??? 0x1b ??? ??? unknown subsystem 0x0 ??? ??? native 0x1 ??? ??? GUI 0x2 ??? ??? console 0x3 ??? ??? POSIX 0x7 ??? ??? executable 0x0 ??? ??? not relocatable 0x0 ??? ??? system file 0x0 ??? ??? DLL 0x0 ??? ??? not relocatable 0x0 ??? ??? system file 0x0 ??? ??? MS Windows COFF Intel 80386 object file 0x14c ??? ??? MS-DOS executable (EXE) MZ ??? ??? OS/2 or MS Windows @ ??? ??? %s LH/2 Self-Extract ??? ??? %s PKSFX2 ??? ??? %s Windows self-extracting ZIP ??? ??? ARJ SFX RJSX\377\377b, ??? ??? diet compressed diet\371\234b, ??? ??? PKSFX Copyright 1989-1990 PKWARE Inc. ??? ??? %.6s compressed PKLITE Copr. ??? ??? %.15s LHa's SFX ??? ??? %.15s LHA's SFX ??? ??? LHa SFX archive v2.13S -lh5- ??? ??? RAR self-extracting archive Rar! ??? ??? PKZIP SFX archive v1.1 PK\003\004b, ??? ??? PKZIP SFX archive v1.93a PK\003\004b, ??? ??? PKZIP2 SFX archive v1.09 PK\003\004b, ??? ??? PKZIP SFX archive v2.04g PK\003\004b, ??? ??? PKZIP2 SFX archive v1.02 PK\003\004b, ??? ??? Info-ZIP SFX archive v5.12 PK\003\004b, ??? ??? Info-ZIP SFX archive v5.12 w/decryption PK\003\004b, ??? ??? Info-ZIP SFX archive v5.12 PK\003\004b, ??? ??? Info-ZIP SFX archive v5.12 w/decryption PK\003\004b, ??? ??? Info-ZIP NT SFX archive v5.12 w/decryption PK\003\004b, ??? ??? CODEC archive v3.21 y\377\200\377v\377b, ??? ??? 1 file 0x1 ??? ??? %u files 0x1 ??? ??? MS-DOS executable (built-in) LZ ??? ??? Windows NT Registry file regf application/msword doc %s Microsoft Word 6.0 Document application/msword doc Spanish Microsoft Word 6 document data Documento Microsoft Word 6 application/msword doc Microsoft Word document data MSWordDoc application/msword doc Microsoft Word Document 0x31be0000 application/msword doc Microsoft Word 6.0 Document PO^Q` application/msword doc Microsoft Office Document \376\067\000\043 application/msword doc Microsoft Office Document \320\317\021\340\241\261 application/msword doc Microsoft Office Document \333\245-\000\000\000 application/msexcel ??? %s Microsoft Excel 5.0 Worksheet ??? ??? Microsoft Excel 5.0 Worksheet Biff5 text/xml ??? XML 1.0 Document <?xml version="1.0"?> application/msexcel ??? Microsoft Excel Spreadsheet <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" ??? ??? Lotus 1-2-3 0x1a00 ??? ??? wk3 document data 0x100400 ??? ??? wk4 document data 0x2100400 ??? ??? fm3 or fmb document data 0x7800100 ??? ??? fm3 or fmb document data 0x7800000 ??? ??? Lotus 1-2-3 0x200 ??? ??? wk1 document data 0x6040600 ??? ??? fmt document data 0x6800200 ??? ??? WordPerfect document WPC ??? ??? MS Windows Help Data ?_\003\000 application/pdf pdf PDF document %PDF- application/pdf pdf version %c application/pdf pdf \b.%c ??? ??? DOS EPS Binary File 0xc5d0d3c6 ??? ??? Postscript starts at byte %d ??? ??? length %d ??? ??? Metafile starts at byte %d ??? ??? length %d ??? ??? TIFF starts at byte %d ??? ??? length %d ??? ??? PPD file *PPD-Adobe: ??? ??? ve ??? ??? RIFF (little-endian) data RIFF ??? ??? palette PAL ??? ??? version %d ??? ??? %d entries ??? ??? device-independent bitmap RDIB ??? ??? BM ??? ??? OS/2 1.x format 0xc ??? ??? %d x ??? ??? %d ??? ??? OS/2 2.x format 0x40 ??? ??? %d x ??? ??? %d ??? ??? Windows 3.x format 0x28 ??? ??? %d x ??? ??? %d x ??? ??? %d ??? ??? MIDI RMID ??? ??? multimedia movie RMMP application/x-wav wav WAVE audio WAVE ??? ??? Microsoft PCM 0x1 ??? ??? %d bit 0x0 ??? ??? mono 0x1 ??? ??? stereo 0x2 ??? ??? %d channels 0x2 ??? ??? %d Hz 0x0 ??? ??? AVI AVI ??? ??? animated cursor ACON ??? ??? RIFF (big-endian) data RIFX ??? ??? palette PAL ??? ??? version %d ??? ??? %d entries ??? ??? device-independent bitmap RDIB ??? ??? BM ??? ??? OS/2 1.x format 0xc ??? ??? %d x ??? ??? %d ??? ??? OS/2 2.x format 0x40 ??? ??? %d x ??? ??? %d ??? ??? Windows 3.x format 0x28 ??? ??? %d x ??? ??? %d x ??? ??? %d ??? ??? MIDI RMID ??? ??? multimedia movie RMMP ??? ??? WAVE audio WAVE ??? ??? Microsoft PCM 0x1 ??? ??? %d bit 0x0 ??? ??? mono 0x1 ??? ??? stereo 0x2 ??? ??? %d channels 0x2 ??? ??? %d Hz 0x0 ??? ??? AVI AVI ??? ??? animated cursor ACON ??? ??? Notation Interchange File Format NIFF ??? ??? 0xedab ??? ??? RPM 0xeedb ??? ??? v%d ??? ??? bin 0x0 ??? ??? src 0x1 ??? ??? i386 0x1 ??? ??? Alpha 0x2 ??? ??? Sparc 0x3 ??? ??? MIPS 0x4 ??? ??? PowerPC 0x5 ??? ??? 68000 0x6 ??? ??? SGI 0x7 ??? ??? %s text/rtf rtf Rich Text Format data, {\rtf text/rtf rtf version %c, text/rtf rtf ANSI \ansi text/rtf rtf Apple Macintosh \mac text/rtf rtf IBM PC, code page 437 \pc text/rtf rtf IBM PS/2, code page 850 \pca text/html html HTML document text <!DOCTYPE HTML text/html html HTML document text <!doctype html text/html html HTML document text <HEAD text/html html HTML document text <head text/html html HTML document text <TITLE text/html html HTML document text <title text/html html HTML document text <html text/html html HTML document text <HTML text/sgml sgml exported SGML document text <!DOCTYPE text/sgml sgml exported SGML document text <!doctype text/sgml sgml exported SGML subdocument text <!SUBDOC text/sgml sgml exported SGML subdocument text <!subdoc text/sgml sgml exported SGML document text <!-- ??? ??? (Corel/WP) WPC ??? ??? WordPerfect macro ??? ??? WordPerfect help file ??? ??? WordPerfect keyboard file ??? ??? WordPerfect document ??? ??? WordPerfect dictionary ??? ??? WordPerfect thesaurus ??? ??? WordPerfect block ??? ??? WordPerfect rectangular block ??? ??? WordPerfect column block ??? ??? WordPerfect printer data ??? ??? WordPerfect printer data ??? ??? WordPerfect driver resource data ??? ??? WordPerfect hyphenation code ??? ??? WordPerfect hyphenation data ??? ??? WordPerfect macro resource data ??? ??? WordPerfect hyphenation lex ??? ??? WordPerfect wordlist ??? ??? WordPerfect equation resource data ??? ??? WordPerfect spell rules ??? ??? WordPerfect dictionary rules ??? ??? WordPerfect spell rules (Microlytics) ??? ??? WordPerfect settings file ??? ??? WordPerfect 4.2 document ??? ??? WordPerfect dialog file ??? ??? WordPerfect button bar ??? ??? Shell macro ??? ??? Shell definition ??? ??? Notebook macro ??? ??? Notebook help file ??? ??? Notebook keyboard file ??? ??? Notebook definition ??? ??? Calculator help file ??? ??? Calendar help file ??? ??? Calendar data file ??? ??? Editor macro ??? ??? Editor help file ??? ??? Editor keyboard file ??? ??? Editor macro resource file ??? ??? Macro editor macro ??? ??? Macro editor help file ??? ??? Macro editor keyboard file ??? ??? PlanPerfect macro ??? ??? PlanPerfect help file ??? ??? PlanPerfect keyboard file ??? ??? PlanPerfect worksheet ??? ??? PlanPerfect printer definition ??? ??? PlanPerfect graphic definition ??? ??? PlanPerfect data ??? ??? PlanPerfect temporary printer ??? ??? PlanPerfect macro resource data ??? ??? Mail 0xb ??? ??? help file ??? ??? distribution list ??? ??? out box ??? ??? in box ??? ??? users archived mailbox ??? ??? archived message database ??? ??? archived attachments ??? ??? Printer temporary file ??? ??? Scheduler help file ??? ??? Scheduler in file ??? ??? Scheduler out file ??? ??? GroupWise settings file ??? ??? GroupWise directory services ??? ??? GroupWise settings file ??? ??? Terminal resource data ??? ??? Terminal resource data ??? ??? Terminal resource data ??? ??? GUI loadable text ??? ??? graphics resource data ??? ??? printer settings file ??? ??? port definition file ??? ??? print queue parameters ??? ??? compressed file ??? ??? Network service msg file ??? ??? Network service msg file ??? ??? Async gateway login msg ??? ??? GroupWise message file ??? ??? GroupWise admin domain database ??? ??? GroupWise admin host database ??? ??? GroupWise admin remote host database ??? ??? GroupWise admin ADS deferment data file ??? ??? IntelliTAG (SGML) compiled DTD ??? ??? WordPerfect graphic image (1.0) ??? ??? WordPerfect graphic image (2.0) text/x-java java Java source file /^\s*package/ text/x-perl pl Perl source file /^#!\/usr\/bin\/perl/ text/x-c c C source file /^#include/m application/x-sh sh sh script /^#!\/bin\/sh/ application/x-bash sh bash script /^#!\/bin\/bash/ application/x-csh sh csh script /^#!\/bin\/csh/ application/x-ksh sh ksh script /^#!\/bin\/ksh/ text/html html HTML Document /^\s*<!DOCTYPE HTML PUBLIC/ text/html html HTML Document /^\s*<html>/ text/plain net.sf.jmimemagic.detectors.TextFileDetector net.sf.jmimemagic.detectors.TextFileDetector application/vnd.oasis.opendocument.text odt Open Document Text PK\003\004 ================================================ FILE: src/main/resources/magic.xml.basic ================================================ 0.1 arimus@users.sourceforge.net XML magic file application/x-tar tar POSIX tar archive ustar\000 application/x-tar tar tar archive ustar \000GNU application/zip zip archive data PK\003\004 application/x-gzip gz gzip compressed data \037\213 application/x-bzip2 bz2 bzip2 compressed data BZh ??? bat MS-DOS batch file text @echo off ================================================ FILE: src/main/resources/magic.xml.verified ================================================ 0.2 dcastro magic file audio/mp3 MP3 0xfffa b, 32 kBits 0x10 b, 40 kBits 0x20 b, 48 kBits 0x30 b, 56 kBits 0x40 b, 64 kBits 0x50 b, 80 kBits 0x60 b, 96 kBits 0x70 b, 112 kBits 0x80 b, 128 kBits 0x90 b, 160 kBits 0xA0 b, 192 kBits 0xB0 b, 224 kBits 0xC0 b, 256 kBits 0xD0 b, 320 kBits 0xE0 b, 44.1 kHz 0x00 b, 48 kHz 0x04 b, 32 kHz 0x08 b, Stereo 0x00 b, JStereo 0x40 b, Dual-Ch 0x80 b, Mono 0xC0 image/gif GIF image data GIF8 b, version 8%s, b, version 8%s, 7a b, version 8%s, b, version 8%s, 9a image/png PNG image data PNG CORRUPTED, CORRUPTED, 0x0d0a1a0a X X 0x0d0a1a0a bcolor RGB, bcolor RGB, 2 colormap, colormap, 3 grayalpha, grayalpha, 4 bcolor RGBA, bcolor RGBA, 6 interlaced interlaced 1 image/jpeg JPEG image data 0xffd8 b, JFIF standard b, JFIF standard JFIF b, EXIF standard b, EXIF standard Exif b, resolution (DPI) b, resolution (DPI) 1 b, resolution (DPCM) b, resolution (DPCM) 2 JPEG image data, HSI proprietary JPEG image data, HSI proprietary hsi1 application/msword doc %s Microsoft Word 6.0 Document application/msword doc Spanish Microsoft Word 6 document data Documento Microsoft Word 6 application/msword doc Microsoft Word document data MSWordDoc application/msword doc Microsoft Word Document 0x31be0000 application/msword doc Microsoft Word 6.0 Document PO^Q` application/msword doc Microsoft Office Document \376\067\000\043 application/msword doc Microsoft Office Document \320\317\021\340\241\261 application/msword doc Microsoft Office Document \333\245-\000\000\000 text/rtf Rich Text Format data {\rtf version %c, version %c, ANSI ANSI \ansi Apple Macintosh Apple Macintosh \mac IBM PC, code page 437 IBM PC, code page 437 \pc IBM PS2, code page 850 IBM PS2, code page 850 \pca application/postscript ps PostScript Level 2 program data %!PS-Adobe-2.0 text/plain .txt ASCII Text Document /[^[:ascii:][:space:]]/ application/vnd.oasis.opendocument.text odt Open Document Format ================================================ FILE: src/main/resources/magic_1_0.dtd ================================================ ================================================ FILE: src/main/resources/template.xml ================================================ file ================================================ FILE: src/test/java/net/sf/jmimemagic/MagicTest.java ================================================ package net.sf.jmimemagic; import junit.framework.*; import java.io.File; public class MagicTest extends TestCase { private static String gifFile = "test_docs/test.gif"; private static String pngFile = "test_docs/test.png"; private static String tifFile = "test_docs/test_nocompress.tif"; private static String jpgFile = "test_docs/test.jpg"; private static String textFile = "test_docs/test.txt"; private static String officeOpenXmlDocumentFile = "test_docs/test_word.docx"; private static String officeOpenXmlDocumentFile2 = "test_docs/test_word.docm"; private static String word2KFile = "test_docs/test_word_2000.doc"; private static String word95File = "test_docs/test_word_6.0_95.doc"; private static String rtfFile = "test_docs/test.rtf"; private static String officeOpenXmlWorkbookFile = "test_docs/test_excel.xlsx"; private static String officeOpenXmlWorkbookFile2 = "test_docs/test_excel.xlsm"; private static String officeOpenXmlPresentationFile = "test_docs/test_powerpoint.pptx"; private static String officeOpenXmlPresentationFile2 = "test_docs/test_powerpoint.pptm"; private static String excel2KFile = "test_docs/test_excel_2000.xls"; private static String pdfFile = "test_docs/test.pdf"; private static String psFile = "test_docs/test.ps"; private static String javaClass12File = "test_docs/test_1.2.class"; private static String javaClass13File = "test_docs/test_1.3.class"; private static String javaClass14File = "test_docs/test_1.4.class"; private static String mp3_128_44_jstereoFile = "test_docs/test_128_44_jstereo.mp3"; private static String wavFile = "test_docs/test.wav"; private static String odtFile = "test_docs/test.odt"; private static String zipFile = "test_docs/test.zip"; public static void main(String args[]) { junit.textui.TestRunner.run(MagicTest.class); } // IMAGE TESTS public void testGIF() { System.out.print("\ntesting GIF image..."); try { MagicMatch match = Magic.getMagicMatch(new File(gifFile), true, false); if (match != null) { assertEquals("image/gif", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testGIF()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testGIF(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testGIF(). message: " + e.getMessage()); } } public void testPNG() { System.out.print("\ntesting PNG image..."); try { MagicMatch match = Magic.getMagicMatch(new File(pngFile), true, false); if (match != null) { assertEquals("image/png", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testPNG()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testPNG(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testPNG(). message: " + e.getMessage()); } } public void testTIF() { System.out.print("\ntesting TIF image..."); try { MagicMatch match = Magic.getMagicMatch(new File(tifFile), true, false); if (match != null) { assertEquals("image/tiff", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testTIF()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testTIF(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testTIF(). message: " + e.getMessage()); } } public void testJPEG() { System.out.print("\ntesting JPEG image..."); try { MagicMatch match = Magic.getMagicMatch(new File(jpgFile), true, false); if (match != null) { assertEquals("image/jpeg", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testJPEG()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testJPEG(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testJPEG(). message: " + e.getMessage()); } } // DOCUMENT TESTS public void testText() { System.out.print("\ntesting Plain Text Document..."); try { MagicMatch match = Magic.getMagicMatch(new File(textFile), true, false); if (match != null) { assertEquals("text/plain", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testText()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testText(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testText(). message: " + e.getMessage()); } } public void testOfficeOpenXmlDocument() { System.out.print("\ntesting Word Office Open XML Document..."); try { MagicMatch match = Magic.getMagicMatch(new File(officeOpenXmlDocumentFile), true, false); if (match != null) { assertEquals("application/vnd.openxmlformats-officedocument.wordprocessingml.document", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testOfficeOpenXmlDocument()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testOfficeOpenXmlDocument(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testOfficeOpenXmlDocument(). message: " + e.getMessage()); } } public void testOfficeOpenXmlDocument2() { System.out.print("\ntesting Word Office Open XML Document..."); try { MagicMatch match = Magic.getMagicMatch(new File(officeOpenXmlDocumentFile2), true, false); if (match != null) { assertEquals("application/vnd.openxmlformats-officedocument.wordprocessingml.document", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testOfficeOpenXmlDocument2()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testOfficeOpenXmlDocument2(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testOfficeOpenXmlDocument2(). message: " + e.getMessage()); } } public void testWord2K() { System.out.print("\ntesting Word 2000 Document..."); try { MagicMatch match = Magic.getMagicMatch(new File(word2KFile), true, false); if (match != null) { assertEquals("application/msword", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testWord2K()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testWord2K(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testWord2K(). message: " + e.getMessage()); } } public void testWord95() { System.out.print("\ntesting Word 95 Document..."); try { MagicMatch match = Magic.getMagicMatch(new File(word95File), true, false); if (match != null) { assertEquals("application/msword", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testWord95()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testWord95(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testWord95(). message: " + e.getMessage()); } } public void testRTF() { System.out.print("\ntesting RTF Document..."); try { MagicMatch match = Magic.getMagicMatch(new File(rtfFile), true, false); if (match != null) { assertEquals("text/rtf", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testRTF()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testRTF(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testRTF(). message: " + e.getMessage()); } } public void testOfficeOpenXmlWorkbook() { System.out.print("\ntesting Word Office Open XML Workbook..."); try { MagicMatch match = Magic.getMagicMatch(new File(officeOpenXmlWorkbookFile), true, false); if (match != null) { assertEquals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testOfficeOpenXmlWorkbook()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testOfficeOpenXmlWorkbook(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testOfficeOpenXmlWorkbook(). message: " + e.getMessage()); } } public void testOfficeOpenXmlWorkbook2() { System.out.print("\ntesting Word Office Open XML Workbook..."); try { MagicMatch match = Magic.getMagicMatch(new File(officeOpenXmlWorkbookFile2), true, false); if (match != null) { assertEquals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testOfficeOpenXmlWorkbook2()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testOfficeOpenXmlWorkbook2(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testOfficeOpenXmlWorkbook2(). message: " + e.getMessage()); } } public void testExcel2K() { System.out.print("\ntesting Excel 2000 Document..."); try { MagicMatch match = Magic.getMagicMatch(new File(excel2KFile), true, false); if (match != null) { assertEquals("application/msword", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testExcel2K()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testExcel2K(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testExcel2K(). message: " + e.getMessage()); } } public void testOfficeOpenXmlPresentation() { System.out.print("\ntesting Word Office Open XML Presentation..."); try { MagicMatch match = Magic.getMagicMatch(new File(officeOpenXmlPresentationFile), true, false); if (match != null) { assertEquals("application/vnd.openxmlformats-officedocument.presentationml.presentation", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testOfficeOpenXmlPresentation()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testOfficeOpenXmlPresentation(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testOfficeOpenXmlPresentation(). message: " + e.getMessage()); } } public void testOfficeOpenXmlPresentation2() { System.out.print("\ntesting Word Office Open XML Presentation..."); try { MagicMatch match = Magic.getMagicMatch(new File(officeOpenXmlPresentationFile2), true, false); if (match != null) { assertEquals("application/vnd.openxmlformats-officedocument.presentationml.presentation", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testOfficeOpenXmlPresentation2()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testOfficeOpenXmlPresentation2(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testOfficeOpenXmlPresentation2(). message: " + e.getMessage()); } } // OTHER public void testPDF() { System.out.print("\ntesting PDF Document..."); try { MagicMatch match = Magic.getMagicMatch(new File(pdfFile), true, false); if (match != null) { assertEquals("application/pdf", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testPDF()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testPDF(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testPDF(). message: " + e.getMessage()); } } public void testPostscript() { System.out.print("\ntesting Postscript Document..."); try { MagicMatch match = Magic.getMagicMatch(new File(psFile), true, false); if (match != null) { assertEquals("application/postscript", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testPostscript()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testPostscript(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testPostscript(). message: " + e.getMessage()); } } public void testJavaClass12() { System.out.print("\ntesting Java Class File (v1.2)..."); try { MagicMatch match = Magic.getMagicMatch(new File(javaClass12File), true, false); if (match != null) { assertEquals("application/java", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testJavaClass12()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testJavaClass12(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testJavaClass12(). message: " + e.getMessage()); } } public void testJavaClass13() { System.out.print("\ntesting Java Class File (v1.3)..."); try { MagicMatch match = Magic.getMagicMatch(new File(javaClass13File), true, false); if (match != null) { assertEquals("application/java", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testJavaClass13()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testJavaClass13(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testJavaClass13(). message: " + e.getMessage()); } } public void testJavaClass14() { System.out.print("\ntesting Java Class File (v1.4)..."); try { MagicMatch match = Magic.getMagicMatch(new File(javaClass14File), true, false); if (match != null) { assertEquals("application/java", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testJavaClass14()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testJavaClass14(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testJavaClass14(). message: " + e.getMessage()); } } public void testMP3() { System.out.print("\ntesting MPEG Layer 3..."); try { MagicMatch match = Magic.getMagicMatch(new File(mp3_128_44_jstereoFile), true, false); if (match != null) { assertEquals("audio/mp3", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testMP3()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testMP3(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testMP3(). message: " + e.getMessage()); } } public void testWave() { System.out.print("\ntesting WAVE..."); try { MagicMatch match = Magic.getMagicMatch(new File(wavFile), true, false); if (match != null) { assertEquals("RIFF (little-endian) data", match.getDescription()); } else { System.out.print("failed"); fail("no match in testWave()"); } assertTrue(match.descriptionMatches("Microsoft PCM")); assertTrue(match.descriptionMatches("stereo")); assertTrue(match.mimeTypeMatches("application/x-wav")); System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testWave(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testWave(). message: " + e.getMessage()); } } public void testOdt(){ System.out.print("\ntesting ODT Document..."); try { MagicMatch match = Magic.getMagicMatch(new File(odtFile), true, false); if (match != null) { assertEquals("application/vnd.oasis.opendocument.text", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testOdt()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testOdt(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testOdt(). message: " + e.getMessage()); } } public void testZip(){ System.out.print("\ntesting Zip File..."); try { MagicMatch match = Magic.getMagicMatch(new File(zipFile), true, false); if (match != null) { assertEquals("application/zip", match.getMimeType()); } else { System.out.print("failed"); fail("no match in testOdt()"); } System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testZip(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testZip(). message: " + e.getMessage()); } } public void testSubMatches(){ System.out.print("\ntesting Submatches..."); try { MagicMatch match = Magic.getMagicMatch(new File(gifFile), true, false); Assert.assertEquals(3, match.getSubMatches().size()); match = Magic.getMagicMatch(new File(gifFile), true, false); Assert.assertEquals(3, match.getSubMatches().size()); System.out.print("ok"); } catch (Exception e) { e.printStackTrace(); fail("exception in testSubMatches(). message: " + e); } catch (Error e) { e.printStackTrace(); fail("error in testSubMatches(). message: " + e.getMessage()); } } } ================================================ FILE: test ================================================ #!/bin/sh mvn exec:java -Dexec.mainClass="net.sf.jmimemagic.Magic" -Dexec.args="$1" ================================================ FILE: test_docs/test.dtd ================================================ ================================================ FILE: test_docs/test.eps ================================================ %!PS-Adobe-3.0 EPSF-3.0 %%Creator: GIMP PostScript file plugin V 1.16 by Peter Kirchgessner %%Title: /home/arimus/test.eps %%CreationDate: Tue Jun 15 19:43:49 2004 %%DocumentData: Clean7Bit %%LanguageLevel: 2 %%Pages: 1 %%BoundingBox: 14 14 115 115 %%EndComments %%BeginProlog % Use own dictionary to avoid conflicts 10 dict begin %%EndProlog %%Page: 1 1 % Translate for offset 14.173228346456694 14.173228346456694 translate % Translate to begin of first scanline 0 99.999999999999986 translate 99.999999999999986 -99.999999999999986 scale % Image geometry 100 100 8 % Transformation matrix [ 100 0 0 100 0 0 ] % Strings to hold RGB-samples per scanline /rstr 100 string def /gstr 100 string def /bstr 100 string def {currentfile /ASCII85Decode filter /RunLengthDecode filter rstr readstring pop} {currentfile /ASCII85Decode filter /RunLengthDecode filter gstr readstring pop} {currentfile /ASCII85Decode filter /RunLengthDecode filter bstr readstring pop} true 3 %%BeginData: 4976 ASCII Bytes colorimage Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> p]'IX^]/f~> p]'IX^]/f~> p]'IX^]/f~> p]'IXf`1mMm/MS~> p]'IXf`1mMm/MS~> p]'IXf`1mMm/MS~> p]'IXf`1mMm/MS~> p]'IXf`1mMm/MS~> p]'IXf`1mMm/MS~> mJm+bcN!hCm/MS~> mJm+bcN!hCm/MS~> mJm+bcN!hCm/MS~> mJm+bcN!hCm/MS~> mJm+bcN!hCm/MS~> mJm+bcN!hCm/MS~> mJm+bcN!hCm/MS~> mJm+bcN!hCm/MS~> mJm+bcN!hCm/MS~> mJm+bp\tTsX'R7b!t-Pd[f6"#$/9nr)@?QZ2/^>,s8;ras*t~> mJm+bp\tTsX'R7b!t-Pd[f6"#$/9nr)@?QZ2/^>,s8;ras*t~> mJm+bp\tTsX'R7b!t-Pd[f6"#$/9nr)@?QZ2/^>,s8;ras*t~> mJm+bq#:Aq*V]U81t2:#!qp@1p](=F[f-6t!;$5@~> mJm+bq#:Aq*V]U81t2:#!qp@1p](=F[f-6t!;$5@~> mJm+bq#:Aq*V]U81t2:#!qp@1p](=F[f-6t!;$5@~> mJm+bqYpTqE:j23%)Dc?!W5@X!<)rh!;$5@~> mJm+bqYpTqE:j23%)Dc?!W5@X!<)rh!;$5@~> mJm+bqYpTqE:j23%)Dc?!W5@X!<)rh!;$5@~> mJm+bqYpP=rW!0*?b5S"jeOC*!!*Yfr;Qbbr;[.#[HID]h5*jJ!<)rh!;$5@~> mJm+bqYpP=rW!0*?b5S"jeOC*!!*Yfr;Qbbr;[.#[HID]h5*jJ!<)rh!;$5@~> mJm+bqYpP=rW!0*?b5S"jeOC*!!*Yfr;Qbbr;[.#[HID]h5*jJ!<)rh!;$5@~> mJm+bqu6Z-rVus1_Ya?6pJ(Ve!(m+g!'1#Y!-.i7!SgBFs8;ras*t~> mJm+bqu6Z-rVus1_Ya?6pJ(Ve!(m+g!'1#Y!-.i7!SgBFs8;ras*t~> mJm+bqu6Z-rVus1_Ya?6pJ(Ve!(m+g!'1#Y!-.i7!SgBFs8;ras*t~> mJm+bqu6XJrVur,q>UKd*<#p mJm+bqu6XJrVur,q>UKd*<#p mJm+bqu6XJrVur,q>UKd*<#p mJm+br;Qc5rVupdp\t5OrVuqDrVlj$rVurpnGiFem/MS~> mJm+br;Qc5rVupdp\t5OrVuqDrVlj$rVurpnGiFem/MS~> mJm+br;Qc5rVupdp\t5OrVuqDrVlj$rVurpnGiFem/MS~> mJm+br;Qb:rVuqhp\t6ArVup]rVlj@rVur6nGiFem/MS~> mJm+br;Qb:rVuqhp\t6ArVup]rVlj@rVur6nGiFem/MS~> mJm+br;Qb:rVuqhp\t6ArVup]rVlj@rVur6nGiFem/MS~> mJm+br;QaXrVurEp\t6brVup8rVlk5rVus?\af^u!:9`9~> mJm+br;QaXrVurEp\t6brVup8rVlk5rVus?\af^u!:9`9~> mJm+br;QaXrVurEp\t6brVup8rVlk5rVus?\af^u!:9`9~> mJm+br;Qa5rW)m!rW<'"qu?^$rVloZ(&\+7+DIk?p&Fsjm/MS~> mJm+br;Qa5rW)m!rW<'"qu?^$rVloZ(&\+7+DIk?p&Fsjm/MS~> mJm+br;Qa5rW)m!rW<'"qu?^$rVloZ(&\+7+DIk?p&Fsjm/MS~> mJm+br;Qa#mK!1b!RiOp!!4Zth"^pJ!:9`9~> mJm+br;Qa#mK!1b!RiOp!!4Zth"^pJ!:9`9~> mJm+br;Qa#mK!1b!RiOp!!4Zth"^pJ!:9`9~> mJm+br;Q`umK!.a"8nua#5\B%!b1]rs8;ras*t~> mJm+br;Q`umK!.a"8nua#5\B%!b1]rs8;ras*t~> mJm+br;Q`umK!.a"8nua#5\B%!b1]rs8;ras*t~> mJm+br;Qa-rVurdl2Ln[^4&-Gr;ZjSp&"df!:9`9~> mJm+br;Qa-rVurdl2Ln[^4&-Gr;ZjSp&"df!:9`9~> mJm+br;Qa-rVurdl2Ln[^4&-Gr;ZjSp&"df!:9`9~> mJm+br;QaMrVur?jo5DHJdD>U!/(1Kr;c3aJ,~> mJm+br;QaMrVur?jo5DHJdD>U!/(1Kr;c3aJ,~> mJm+br;QaMrVur?jo5DHJdD>U!/(1Kr;c3aJ,~> mJm+br;Qb-rVuqOj8T+NrVupKqu?Tpm/MS~> mJm+br;Qb-rVuqOj8T+NrVupKqu?Tpm/MS~> mJm+br;Qb-rVuqOj8T+NrVupKqu?Tpm/MS~> mJm+br;Qc'rVusAq;hPUoDS^i#lFW%"o\K%r9aN7~> mJm+br;Qc'rVusAq;hPUoDS^i#lFW%"o\K%r9aN7~> mJm+br;Qc'rVusAq;hPUoDS^i#lFW%"o\K%r9aN7~> mJm+br;Qfq,5qQBHK>)+l2CY_%/^&)'E.t3lL"V%~> mJm+br;Qfq,5qQBHK>)+l2CY_%/^&)'E.t3lL"V%~> mJm+br;Qfq,5qQBHK>)+l2CY_%/^&)'E.t3lL"V%~> mJm+bqu6Z#r;ZkIr:p9m]L)Pr!^XEsq>UG:rVup]qu6XTrVur+mJh\~> mJm+bqu6Z#r;ZkIr:p9m]L)Pr!^XEsq>UG:rVup]qu6XTrVur+mJh\~> mJm+bqu6Z#r;ZkIr:p9m]L)Pr!^XEsq>UG:rVup]qu6XTrVur+mJh\~> mJm+bqYpP8r;[3PNR%"in(Ojb,6.`As8N'),':6Oq>BHb:]17nW;HSpFoD@C-bJmInGe"~> mJm+bqYpP8r;[3PNR%"in(Ojb,6.`As8N'),':6Oq>BHb:]17nW;HSpFoD@C-bJmInGe"~> mJm+bqYpP8r;[3PNR%"in(Ojb,6.`As8N'),':6Oq>BHb:]17nW;HSpFoD@C-bJmInGe"~> mJm+bqYpTqFn,P1s763j@J^!)g'7 mJm+bqYpTqFn,P1s763j@J^!)g'7 mJm+bqYpTqFn,P1s763j@J^!)g'7 mJm+bq#:B(.e`oE"B!/9s7H?n%Z^ParrJo%q#L$dJ,~> mJm+bq#:B(.e`oE"B!/9s7H?n%Z^ParrJo%q#L$dJ,~> mJm+bq#:B(.e`oE"B!/9s7H?n%Z^ParrJo%q#L$dJ,~> mJm+bp\tX#]l#bD"9T5g>b:46Q6C6rW)QiJ,~> mJm+bp\tX#]l#bD"9T5g>b:46Q6C6rW)QiJ,~> mJm+bp\tX#]l#bD"9T5g>b:46Q6C6rW)QiJ,~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> Sc=3~> %%EndData showpage %%Trailer end %%EOF ================================================ FILE: test_docs/test.java ================================================ public class test { public static void main(String[] args) { System.out.println("this is a test java source file"); } } ================================================ FILE: test_docs/test.pl ================================================ #!/usr/bin/perl -w use strict; print "this is a test perl script\n"; ================================================ FILE: test_docs/test.pnm ================================================ P6 100 100 255 ^^^***  )))aaa~~~CCC 555nnn444jjj+++ppp DDDvvv___夤***PPPݥNNNMMMIII999qqqLLL--- DDDyyyqqq===!!!:::kkk iii***+++{{{EEEbbb~~~;;;333///邂ddd+++ """zzz ~~~BBBAAAttt===777qqq&&&ڬttt###"""ttt趶OOOuuu'''uuuaaa***QQQ nnn777...\\\㪪xxxNNN---&&&TTTCCC  ================================================ FILE: test_docs/test.ppm ================================================ P6 100 100 255 ^^^***  )))aaa~~~CCC 555nnn444jjj+++ppp DDDvvv___夤***PPPݥNNNMMMIII999qqqLLL--- DDDyyyqqq===!!!:::kkk iii***+++{{{EEEbbb~~~;;;333///邂ddd+++ """zzz ~~~BBBAAAttt===777qqq&&&ڬttt###"""ttt趶OOOuuu'''uuuaaa***QQQ nnn777...\\\㪪xxxNNN---&&&TTTCCC  ================================================ FILE: test_docs/test.ps ================================================ %!PS-Adobe-2.0 %%DocumentFonts: Courier Times-Bold %%Title: (mpage) %%Creator: mpage 2.5.1pre2 March 1998 %%CreationDate: Tue Jun 15 20:04:08 2004 %%Orientation: Portrait %%DocumentMedia: A4 596 842 %%BoundingBox: 20 20 576 822 %%Pages: (atend) %%EndComments %%BeginProlog /mp_stm usertime def /mp_pgc statusdict begin pagecount end def statusdict begin /jobname () def end /reencsmalldict 12 dict def /ReEncodeSmall { reencsmalldict begin /newcodesandnames exch def /newfontname exch def /basefontname exch def /basefontdict basefontname findfont def /newfont basefontdict maxlength dict def basefontdict { exch dup /FID ne { dup /Encoding eq { exch dup length array copy newfont 3 1 roll put } { exch newfont 3 1 roll put } ifelse } { pop pop } ifelse } forall newfont /FontName newfontname put newcodesandnames aload pop newcodesandnames length 2 idiv { newfont /Encoding get 3 1 roll put } repeat newfontname newfont definefont pop end } def /charvec [ 026 /Scaron 027 /Ydieresis 028 /Zcaron 029 /scaron 030 /trademark 031 /zcaron 032 /space 033 /exclam 034 /quotedbl 035 /numbersign 036 /dollar 037 /percent 038 /ampersand 039 /quoteright 040 /parenleft 041 /parenright 042 /asterisk 043 /plus 044 /comma 045 /minus 046 /period 047 /slash 048 /zero 049 /one 050 /two 051 /three 052 /four 053 /five 054 /six 055 /seven 056 /eight 057 /nine 058 /colon 059 /semicolon 060 /less 061 /equal 062 /greater 063 /question 064 /at 065 /A 066 /B 067 /C 068 /D 069 /E 070 /F 071 /G 072 /H 073 /I 074 /J 075 /K 076 /L 077 /M 078 /N 079 /O 080 /P 081 /Q 082 /R 083 /S 084 /T 085 /U 086 /V 087 /W 088 /X 089 /Y 090 /Z 091 /bracketleft 092 /backslash 093 /bracketright 094 /asciicircum 095 /underscore 096 /quoteleft 097 /a 098 /b 099 /c 100 /d 101 /e 102 /f 103 /g 104 /h 105 /i 106 /j 107 /k 108 /l 109 /m 110 /n 111 /o 112 /p 113 /q 114 /r 115 /s 116 /t 117 /u 118 /v 119 /w 120 /x 121 /y 122 /z 123 /braceleft 124 /bar 125 /braceright 126 /asciitilde 127 /.notdef 128 /fraction 129 /florin 130 /quotesingle 131 /quotedblleft 132 /guilsinglleft 133 /guilsinglright 134 /fi 135 /fl 136 /endash 137 /dagger 138 /daggerdbl 139 /bullet 140 /quotesinglbase 141 /quotedblbase 142 /quotedblright 143 /ellipsis 144 /dotlessi 145 /grave 146 /acute 147 /circumflex 148 /tilde 149 /oe 150 /breve 151 /dotaccent 152 /perthousand 153 /emdash 154 /ring 155 /Lslash 156 /OE 157 /hungarumlaut 158 /ogonek 159 /caron 160 /lslash 161 /exclamdown 162 /cent 163 /sterling 164 /currency 165 /yen 166 /brokenbar 167 /section 168 /dieresis 169 /copyright 170 /ordfeminine 171 /guillemotleft 172 /logicalnot 173 /hyphen 174 /registered 175 /macron 176 /degree 177 /plusminus 178 /twosuperior 179 /threesuperior 180 /acute 181 /mu 182 /paragraph 183 /periodcentered 184 /cedilla 185 /onesuperior 186 /ordmasculine 187 /guillemotright 188 /onequarter 189 /onehalf 190 /threequarters 191 /questiondown 192 /Agrave 193 /Aacute 194 /Acircumflex 195 /Atilde 196 /Adieresis 197 /Aring 198 /AE 199 /Ccedilla 200 /Egrave 201 /Eacute 202 /Ecircumflex 203 /Edieresis 204 /Igrave 205 /Iacute 206 /Icircumflex 207 /Idieresis 208 /Eth 209 /Ntilde 210 /Ograve 211 /Oacute 212 /Ocircumflex 213 /Otilde 214 /Odieresis 215 /multiply 216 /Oslash 217 /Ugrave 218 /Uacute 219 /Ucircumflex 220 /Udieresis 221 /Yacute 222 /Thorn 223 /germandbls 224 /agrave 225 /aacute 226 /acircumflex 227 /atilde 228 /adieresis 229 /aring 230 /ae 231 /ccedilla 232 /egrave 233 /eacute 234 /ecircumflex 235 /edieresis 236 /igrave 237 /iacute 238 /icircumflex 239 /idieresis 240 /eth 241 /ntilde 242 /ograve 243 /oacute 244 /ocircumflex 245 /otilde 246 /odieresis 247 /divide 248 /oslash 249 /ugrave 250 /uacute 251 /ucircumflex 252 /udieresis 253 /yacute 254 /thorn 255 /ydieresis ] def /Courier /OurCharSet charvec ReEncodeSmall /textfont /OurCharSet findfont 11 scalefont def /fnamefont /Times-Bold findfont 14 scalefont def /headerfont /Times-Bold findfont 12 scalefont def textfont setfont (a) stringwidth pop /mp_a_x exch def %%EndProlog %%Page: 1 1 save gsave 20 421 translate 0 0 moveto 0 401 rlineto 278 0 rlineto 0 -401 rlineto closepath clip 278 80 mp_a_x mul div 401 792 div scale 4 7 translate 270 278 div 784 792 div scale textfont setfont 0 780 moveto (This is a plain text file) show grestore restore showpage %%Trailer %%Pages: 1 ================================================ FILE: test_docs/test.py ================================================ """Append module search paths for third-party packages to sys.path. **************************************************************** * This module is automatically imported during initialization. * **************************************************************** In earlier versions of Python (up to 1.5a3), scripts or modules that needed to use site-specific modules would place ``import site'' somewhere near the top of their code. Because of the automatic import, this is no longer necessary (but code that does it still works). This will append site-specific paths to to the module search path. On Unix, it starts with sys.prefix and sys.exec_prefix (if different) and appends lib/python/site-packages as well as lib/site-python. On other platforms (mainly Mac and Windows), it uses just sys.prefix (and sys.exec_prefix, if different, but this is unlikely). The resulting directories, if they exist, are appended to sys.path, and also inspected for path configuration files. FOR DEBIAN, this sys.path is augmented with directories in /usr/local. Local addons go into /usr/local/lib/python/site-packages (resp. /usr/local/lib/site-python), Debian addons install into /usr/{lib,share}/python/site-packages. A path configuration file is a file whose name has the form .pth; its contents are additional directories (one per line) to be added to sys.path. Non-existing directories (or non-directories) are never added to sys.path; no directory is added to sys.path more than once. Blank lines and lines beginning with '#' are skipped. Lines starting with 'import' are executed. For example, suppose sys.prefix and sys.exec_prefix are set to /usr/local and there is a directory /usr/local/lib/python2.3/site-packages with three subdirectories, foo, bar and spam, and two path configuration files, foo.pth and bar.pth. Assume foo.pth contains the following: # foo package configuration foo bar bletch and bar.pth contains: # bar package configuration bar Then the following directories are added to sys.path, in this order: /usr/local/lib/python2.3/site-packages/bar /usr/local/lib/python2.3/site-packages/foo Note that bletch is omitted because it doesn't exist; bar precedes foo because bar.pth comes alphabetically before foo.pth; and spam is omitted because it is not mentioned in either path configuration file. After these path manipulations, an attempt is made to import a module named sitecustomize, which can perform arbitrary additional site-specific customizations. If this import fails with an ImportError exception, it is silently ignored. """ import sys, os def makepath(*paths): dir = os.path.abspath(os.path.join(*paths)) return dir, os.path.normcase(dir) for m in sys.modules.values(): if hasattr(m, "__file__") and m.__file__: m.__file__ = os.path.abspath(m.__file__) del m # This ensures that the initial path provided by the interpreter contains # only absolute pathnames, even if we're running from the build directory. L = [] _dirs_in_sys_path = {} dir = dircase = None # sys.path may be empty at this point for dir in sys.path: # Filter out duplicate paths (on case-insensitive file systems also # if they only differ in case); turn relative paths into absolute # paths. dir, dircase = makepath(dir) if not dircase in _dirs_in_sys_path: L.append(dir) _dirs_in_sys_path[dircase] = 1 sys.path[:] = L del dir, dircase, L # Append ./build/lib. in case we're running in the build dir # (especially for Guido :-) # XXX This should not be part of site.py, since it is needed even when # using the -S option for Python. See http://www.python.org/sf/586680 if (os.name == "posix" and sys.path and os.path.basename(sys.path[-1]) == "Modules"): from distutils.util import get_platform s = "build/lib.%s-%.3s" % (get_platform(), sys.version) s = os.path.join(os.path.dirname(sys.path[-1]), s) sys.path.append(s) del get_platform, s def _init_pathinfo(): global _dirs_in_sys_path _dirs_in_sys_path = d = {} for dir in sys.path: if dir and not os.path.isdir(dir): continue dir, dircase = makepath(dir) d[dircase] = 1 def addsitedir(sitedir): global _dirs_in_sys_path if _dirs_in_sys_path is None: _init_pathinfo() reset = 1 else: reset = 0 sitedir, sitedircase = makepath(sitedir) if not sitedircase in _dirs_in_sys_path: sys.path.append(sitedir) # Add path component try: names = os.listdir(sitedir) except os.error: return names.sort() for name in names: if name[-4:] == os.extsep + "pth": addpackage(sitedir, name) if reset: _dirs_in_sys_path = None def addpackage(sitedir, name): global _dirs_in_sys_path if _dirs_in_sys_path is None: _init_pathinfo() reset = 1 else: reset = 0 fullname = os.path.join(sitedir, name) try: f = open(fullname) except IOError: return while 1: dir = f.readline() if not dir: break if dir[0] == '#': continue if dir.startswith("import"): exec dir continue if dir[-1] == '\n': dir = dir[:-1] dir, dircase = makepath(sitedir, dir) if not dircase in _dirs_in_sys_path and os.path.exists(dir): sys.path.append(dir) _dirs_in_sys_path[dircase] = 1 if reset: _dirs_in_sys_path = None prefixes = [os.path.join(sys.prefix, "local"), sys.prefix] sitedir = None # make sure sitedir is initialized because of later 'del' if sys.exec_prefix != sys.prefix: prefixes.append(os.path.join(sys.exec_prefix, "local")) for prefix in prefixes: if prefix: if sys.platform in ('os2emx', 'riscos'): sitedirs = [os.path.join(prefix, "Lib", "site-packages")] elif os.sep == '/': sitedirs = [os.path.join(prefix, "lib", "python" + sys.version[:3], "site-packages"), os.path.join(prefix, "lib", "site-python")] else: sitedirs = [prefix, os.path.join(prefix, "lib", "site-packages")] if sys.platform == 'darwin': # for framework builds *only* we add the standard Apple # locations. Currently only per-user, but /Library and # /Network/Library could be added too if 'Python.framework' in prefix: home = os.environ.get('HOME') if home: sitedirs.append( os.path.join(home, 'Library', 'Python', sys.version[:3], 'site-packages')) for sitedir in sitedirs: if os.path.isdir(sitedir): addsitedir(sitedir) del prefix, sitedir _dirs_in_sys_path = None # Define new built-ins 'quit' and 'exit'. # These are simply strings that display a hint on how to exit. if os.sep == ':': exit = 'Use Cmd-Q to quit.' elif os.sep == '\\': exit = 'Use Ctrl-Z plus Return to exit.' else: exit = 'Use Ctrl-D (i.e. EOF) to exit.' import __builtin__ __builtin__.quit = __builtin__.exit = exit del exit # interactive prompt objects for printing the license text, a list of # contributors and the copyright notice. class _Printer: MAXLINES = 23 def __init__(self, name, data, files=(), dirs=()): self.__name = name self.__data = data self.__files = files self.__dirs = dirs self.__lines = None def __setup(self): if self.__lines: return data = None for dir in self.__dirs: for file in self.__files: file = os.path.join(dir, file) try: fp = open(file) data = fp.read() fp.close() break except IOError: pass if data: break if not data: data = self.__data self.__lines = data.split('\n') self.__linecnt = len(self.__lines) def __repr__(self): self.__setup() if len(self.__lines) <= self.MAXLINES: return "\n".join(self.__lines) else: return "Type %s() to see the full %s text" % ((self.__name,)*2) def __call__(self): self.__setup() prompt = 'Hit Return for more, or q (and Return) to quit: ' lineno = 0 while 1: try: for i in range(lineno, lineno + self.MAXLINES): print self.__lines[i] except IndexError: break else: lineno += self.MAXLINES key = None while key is None: key = raw_input(prompt) if key not in ('', 'q'): key = None if key == 'q': break __builtin__.copyright = _Printer("copyright", sys.copyright) if sys.platform[:4] == 'java': __builtin__.credits = _Printer( "credits", "Jython is maintained by the Jython developers (www.jython.org).") else: __builtin__.credits = _Printer("credits", """\ Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands for supporting Python development. See www.python.org for more information.""") here = os.path.dirname(os.__file__) __builtin__.license = _Printer( "license", "See http://www.python.org/%.3s/license.html" % sys.version, ["LICENSE.txt", "LICENSE"], [os.path.join(here, os.pardir), here, os.curdir]) # Define new built-in 'help'. # This is a wrapper around pydoc.help (with a twist). class _Helper: def __repr__(self): return "Type help() for interactive help, " \ "or help(object) for help about object." def __call__(self, *args, **kwds): import pydoc return pydoc.help(*args, **kwds) __builtin__.help = _Helper() # On Windows, some default encodings are not provided # by Python (e.g. "cp932" in Japanese locale), while they # are always available as "mbcs" in each locale. # Make them usable by aliasing to "mbcs" in such a case. if sys.platform == 'win32': import locale, codecs enc = locale.getdefaultlocale()[1] if enc.startswith('cp'): # "cp***" ? try: codecs.lookup(enc) except LookupError: import encodings encodings._cache[enc] = encodings._unknown encodings.aliases.aliases[enc] = 'mbcs' # Set the string encoding used by the Unicode implementation. The # default is 'ascii', but if you're willing to experiment, you can # change this. encoding = "ascii" # Default value set by _PyUnicode_Init() if 0: # Enable to support locale aware default string encodings. import locale loc = locale.getdefaultlocale() if loc[1]: encoding = loc[1] if 0: # Enable to switch off string to Unicode coercion and implicit # Unicode to string conversion. encoding = "undefined" if encoding != "ascii": # On Non-Unicode builds this will raise an AttributeError... sys.setdefaultencoding(encoding) # Needs Python Unicode build ! # # Run custom site specific code, if available. # try: import sitecustomize except ImportError: pass # # Remove sys.setdefaultencoding() so that users cannot change the # encoding after initialization. The test for presence is needed when # this module is run as a script, because this code is executed twice. # if hasattr(sys, "setdefaultencoding"): del sys.setdefaultencoding def _test(): print "sys.path = [" for dir in sys.path: print " %s," % `dir` print "]" if __name__ == '__main__': _test() ================================================ FILE: test_docs/test.rtf ================================================ {\rtf1\ansi\ansicpg1252\uc1\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f36\froman\fcharset238\fprq2 Times New Roman CE;} {\f37\froman\fcharset204\fprq2 Times New Roman Cyr;}{\f39\froman\fcharset161\fprq2 Times New Roman Greek;}{\f40\froman\fcharset162\fprq2 Times New Roman Tur;}{\f41\froman\fcharset177\fprq2 Times New Roman (Hebrew);} {\f42\froman\fcharset178\fprq2 Times New Roman (Arabic);}{\f43\froman\fcharset186\fprq2 Times New Roman Baltic;}{\f44\froman\fcharset163\fprq2 Times New Roman (Vietnamese);}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255; \red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0; \red128\green128\blue128;\red192\green192\blue192;}{\stylesheet{\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \snext0 Normal;}{\*\cs10 \additive \ssemihidden Default Paragraph Font;}{\*\ts11\tsrowd\trftsWidthB3\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\trcbpat1\trcfpat1\tscellwidthfts0\tsvertalt\tsbrdrt\tsbrdrl\tsbrdrb\tsbrdrr\tsbrdrdgl\tsbrdrdgr\tsbrdrh\tsbrdrv \ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs20\lang1024\langfe1024\cgrid\langnp1024\langfenp1024 \snext11 \ssemihidden Normal Table;}}{\*\rsidtbl \rsid5531693}{\*\generator Microsoft Word 10.0.2627;}{\info {\title This is a test RTF document}{\author David Castro}{\operator David Castro}{\creatim\yr2004\mo6\dy17\hr19\min29}{\revtim\yr2004\mo6\dy17\hr19\min30}{\version1}{\edmins1}{\nofpages1}{\nofwords4}{\nofchars25}{\*\company Azusa Pacific University} {\nofcharsws28}{\vern16437}}\widowctrl\ftnbj\aenddoc\noxlattoyen\expshrtn\noultrlspc\dntblnsbdb\nospaceforul\formshade\horzdoc\dgmargin\dghspace180\dgvspace180\dghorigin1800\dgvorigin1440\dghshow1\dgvshow1 \jexpand\viewkind1\viewscale100\pgbrdrhead\pgbrdrfoot\splytwnine\ftnlytwnine\htmautsp\nolnhtadjtbl\useltbaln\alntblind\lytcalctblwd\lyttblrtgr\lnbrkrule\nobrkwrptbl\snaptogridincell\allowfieldendsel\wrppunct\asianbrkrule\rsidroot5531693 \fet0\sectd \linex0\endnhere\sectlinegrid360\sectdefaultcl\sftnbj {\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl4 \pnlcltr\pnstart1\pnindent720\pnhang {\pntxta )}}{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (} {\pntxta )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}\pard\plain \ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\insrsid5531693 This is a test RTF document \par \par }} ================================================ FILE: test_docs/test.sh ================================================ #!/bin/bash echo "this is a test bash script" ================================================ FILE: test_docs/test.txt ================================================ This is a plain text file ================================================ FILE: test_docs/test.xml ================================================ 0.1 arimus@users.sourceforge.net XML magic file application/x-tar tar POSIX tar archive ustar\000 application/x-tar tar tar archive ustar \000GNU application/zip zip archive data PK\003\004 application/x-gzip gz gzip compressed data \037\213 application/x-bzip2 bz2 bzip2 compressed data BZh ??? bat MS-DOS batch file text @echo off ================================================ FILE: test_docs/test.xpm ================================================ /* XPM */ static char * test_xpm[] = { "100 100 152 2", " c #FFFFFF", ". c #000000", "+ c #FAFAFA", "@ c #ABABAB", "# c #5E5E5E", "$ c #2A2A2A", "% c #0D0D0D", "& c #030303", "* c #0B0B0B", "= c #292929", "- c #616161", "; c #B6B6B6", "> c #FEFEFE", ", c #DBDBDB", "' c #7E7E7E", ") c #434343", "! c #1A1A1A", "~ c #0A0A0A", "{ c #121212", "] c #353535", "^ c #6E6E6E", "/ c #C3C3C3", "( c #1D1D1D", "_ c #343434", ": c #D3D3D3", "< c #F6F6F6", "[ c #6A6A6A", "} c #020202", "| c #2B2B2B", "1 c #707070", "2 c #0C0C0C", "3 c #C0C0C0", "4 c #FCFCFC", "5 c #444444", "6 c #767676", "7 c #5F5F5F", "8 c #BABABA", "9 c #EBEBEB", "0 c #E5E5E5", "a c #A4A4A4", "b c #101010", "c c #DEDEDE", "d c #999999", "e c #505050", "f c #B5B5B5", "g c #E7E7E7", "h c #F8F8F8", "i c #DDDDDD", "j c #A5A5A5", "k c #4E4E4E", "l c #C2C2C2", "m c #F7F7F7", "n c #4D4D4D", "o c #494949", "p c #393939", "q c #717171", "r c #DCDCDC", "s c #4C4C4C", "t c #2D2D2D", "u c #F2F2F2", "v c #1C1C1C", "w c #D0D0D0", "x c #C1C1C1", "y c #8B8B8B", "z c #797979", "A c #050505", "B c #9D9D9D", "C c #D2D2D2", "D c #3D3D3D", "E c #212121", "F c #3A3A3A", "G c #CFCFCF", "H c #F3F3F3", "I c #181818", "J c #6B6B6B", "K c #1E1E1E", "L c #B9B9B9", "M c #171717", "N c #010101", "O c #060606", "P c #E4E4E4", "Q c #151515", "R c #202020", "S c #696969", "T c #AAAAAA", "U c #E9E9E9", "V c #7B7B7B", "W c #454545", "X c #626262", "Y c #F1F1F1", "Z c #0F0F0F", "` c #EEEEEE", " . c #BEBEBE", ".. c #3B3B3B", "+. c #333333", "@. c #F5F5F5", "#. c #2F2F2F", "$. c #C9C9C9", "%. c #828282", "&. c #080808", "*. c #838383", "=. c #646464", "-. c #848484", ";. c #9E9E9E", ">. c #B3B3B3", ",. c #F9F9F9", "'. c #222222", "). c #7A7A7A", "!. c #131313", "~. c #EAEAEA", "{. c #B0B0B0", "]. c #BCBCBC", "^. c #424242", "/. c #414141", "(. c #747474", "_. c #373737", ":. c #262626", "<. c #8D8D8D", "[. c #CECECE", "}. c #EFEFEF", "|. c #FBFBFB", "1. c #DADADA", "2. c #ACACAC", "3. c #232323", "4. c #E1E1E1", "5. c #E8E8E8", "6. c #4F4F4F", "7. c #A8A8A8", "8. c #757575", "9. c #272727", "0. c #BBBBBB", "a. c #F0F0F0", "b. c #B7B7B7", "c. c #040404", "d. c #515151", "e. c #C5C5C5", "f. c #0E0E0E", "g. c #8E8E8E", "h. c #090909", "i. c #BDBDBD", "j. c #111111", "k. c #2E2E2E", "l. c #5C5C5C", "m. c #ECECEC", "n. c #E3E3E3", "o. c #787878", "p. c #141414", "q. c #070707", "r. c #545454", "s. c #9A9A9A", "t. c #E0E0E0", "u. c #1B1B1B", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " . . . . . . . . . . . . . . . . . . . . . . . . ", " . . . . . . . . . . . . . . . . . . . . . . . . . . . . ", " . . . . . . . . . . . . . . . . . . . . . . . . . . . . ", " . . . . . . . . ", " . . . . . . . . ", " . . . . . . . . ", " . . . . + @ # $ % & * = - ; > , ' ) ! ~ & { ] ^ / . . . . ", " . . . . @ ( . . . . . . . . . _ : < [ } . . . . . . . . . | ; . . . . . . . . . . . . . . ", " . . . . > 1 . . . . . . . . . . . . 2 3 4 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . ", " . . . . 6 . . . & 7 8 9 + 0 a $ . . . b c d . . . . e f g + h i j k } . . . . . . . . . . . . . . . ", " . . . . 8 . . . b l m n . . . o p . . . q r s . . . . ", " . . . . t . . . ; u v . . . w * . . . 0 . . . . ", " . . . . x . . . 5 y . . . z A . . . + . . . . ", " . . . . q . . . B C . . . D E . . . 3 . . . . ", " . . . . F . . . G H . . . I J . . . K L . . . . ", " . . . . M . . . & & & & } } } N N N . . . . . O P Q . . . . R S T U . . . . ", " . . . . A . . . . . . . . . . . . . . . . . . . : $ . . . . . . . | V r . . . . ", " . . . . } . . . . . . . . . . . . . . . . . . . 4 j W O . . . . . . } X Y . . . . ", " . . . . Z . . . ` < .' ..& . . . . +.@. . . . . ", " . . . . #.. . . $. U %.&.. . . *. . . . . ", " . . . . =.. . . -. ;.. . . | . . . . ", " . . . . >.. . . R ,. H . . . &. A . . . 4 ", " . . . . 4 '.. . . ). U . . . 2 !.. . . ~. ", " . . . . {.. . . . ' 4 ].^. /.8 > (.. . . D _.. . . f ", " . . . . q . . . . :.<.[.}.|.}.1.2.(.3.. . . . '.(.f 4.,.4 5.; 6.. . . . 7. 8.. . . 9.0.a.> ", " . . . . > 8.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . - 1.O . . . . . . . . . ", " . . . . b.$ . . . . . . . . . . c.d.e. . . . . . . . . . . . . f.g.> a h.. . . . . . . . ", " . . . . > i.^ _.Q c.& j.k.l.;.m. n.T o.k t p.q.& f.:.r.s.` t.%.) u.* N . . . ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}; ================================================ FILE: test_docs/test_excel_spreadsheet.xml ================================================ David Castro David Castro 2004-06-16T02:29:05Z 2004-06-16T02:29:24Z Azusa Pacific University 10.2625 12660 17100 360 60 False False Test excel 2000 spreadsheet
False False
False False False False
================================================ FILE: test_docs/test_excel_web_archive.mht ================================================ MIME-Version: 1.0 X-Document-Type: Worksheet Content-Location: file:///C:/2A65B325/test_excel_web_archive.htm Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii"
Test excel 2000 spreadsheet