Permalink
Browse files

remove old svn files that were migrated over =P

  • Loading branch information...
1 parent 5f81d5c commit 742161e81124fbbed329df2c26901e8cfdc2b35c @arimus committed Mar 9, 2012
Showing with 0 additions and 12,348 deletions.
  1. +0 −5 lib/.svn/all-wcprops
  2. +0 −28 lib/.svn/entries
  3. +0 −5 src/.svn/all-wcprops
  4. +0 −34 src/.svn/entries
  5. +0 −5 src/main/java/.svn/all-wcprops
  6. +0 −31 src/main/java/.svn/entries
  7. +0 −5 src/main/java/net/.svn/all-wcprops
  8. +0 −31 src/main/java/net/.svn/entries
  9. +0 −5 src/main/java/net/sf/.svn/all-wcprops
  10. +0 −31 src/main/java/net/sf/.svn/entries
  11. +0 −65 src/main/java/net/sf/jmimemagic/.svn/all-wcprops
  12. +0 −371 src/main/java/net/sf/jmimemagic/.svn/entries
  13. +0 −516 src/main/java/net/sf/jmimemagic/.svn/text-base/Magic.java.svn-base
  14. +0 −111 src/main/java/net/sf/jmimemagic/.svn/text-base/MagicDetector.java.svn-base
  15. +0 −72 src/main/java/net/sf/jmimemagic/.svn/text-base/MagicException.java.svn-base
  16. +0 −423 src/main/java/net/sf/jmimemagic/.svn/text-base/MagicMatch.java.svn-base
  17. +0 −72 src/main/java/net/sf/jmimemagic/.svn/text-base/MagicMatchNotFoundException.java.svn-base
  18. +0 −816 src/main/java/net/sf/jmimemagic/.svn/text-base/MagicMatcher.java.svn-base
  19. +0 −72 src/main/java/net/sf/jmimemagic/.svn/text-base/MagicParseException.java.svn-base
  20. +0 −586 src/main/java/net/sf/jmimemagic/.svn/text-base/MagicParser.java.svn-base
  21. +0 −72 src/main/java/net/sf/jmimemagic/.svn/text-base/UnsupportedTypeException.java.svn-base
  22. +0 −6 src/main/java/net/sf/jmimemagic/.svn/text-base/package.html.svn-base
  23. +0 −17 src/main/java/net/sf/jmimemagic/detectors/.svn/all-wcprops
  24. +0 −96 src/main/java/net/sf/jmimemagic/detectors/.svn/entries
  25. +0 −160 src/main/java/net/sf/jmimemagic/detectors/.svn/text-base/TextFileDetector.java.svn-base
  26. +0 −6 src/main/java/net/sf/jmimemagic/detectors/.svn/text-base/package.html.svn-base
  27. +0 −47 src/main/resources/.svn/all-wcprops
  28. +0 −266 src/main/resources/.svn/entries
  29. +0 −16 src/main/resources/.svn/text-base/log4j.properties.svn-base
  30. +0 −17 src/main/resources/.svn/text-base/magic.dtd.svn-base
  31. +0 −47 src/main/resources/.svn/text-base/magic.xml.basic.svn-base
  32. +0 −3,498 src/main/resources/.svn/text-base/magic.xml.svn-base
  33. +0 −504 src/main/resources/.svn/text-base/magic.xml.verified.svn-base
  34. +0 −18 src/main/resources/.svn/text-base/magic_1_0.dtd.svn-base
  35. +0 −97 src/main/resources/.svn/text-base/template.xml.svn-base
  36. +0 −5 src/test/.svn/all-wcprops
  37. +0 −31 src/test/.svn/entries
  38. +0 −5 src/test/java/net/.svn/all-wcprops
  39. +0 −31 src/test/java/net/.svn/entries
  40. +0 −5 src/test/java/net/sf/.svn/all-wcprops
  41. +0 −31 src/test/java/net/sf/.svn/entries
  42. +0 −11 src/test/java/net/sf/jmimemagic/.svn/all-wcprops
  43. +0 −62 src/test/java/net/sf/jmimemagic/.svn/entries
  44. +0 −335 src/test/java/net/sf/jmimemagic/.svn/text-base/MagicTest.java.svn-base
  45. +0 −281 test_docs/.svn/all-wcprops
  46. +0 −1,592 test_docs/.svn/entries
  47. +0 −5 test_docs/.svn/prop-base/test.au.svn-base
  48. +0 −5 test_docs/.svn/prop-base/test.bin.svn-base
  49. +0 −5 test_docs/.svn/prop-base/test.bmp.svn-base
  50. +0 −5 test_docs/.svn/prop-base/test.emf.svn-base
  51. +0 −5 test_docs/.svn/prop-base/test.fli.svn-base
  52. +0 −5 test_docs/.svn/prop-base/test.gif.svn-base
  53. +0 −5 test_docs/.svn/prop-base/test.ico.svn-base
  54. +0 −5 test_docs/.svn/prop-base/test.jpg.svn-base
  55. +0 −5 test_docs/.svn/prop-base/test.mp3.svn-base
  56. +0 −5 test_docs/.svn/prop-base/test.ogg.svn-base
  57. +0 −5 test_docs/.svn/prop-base/test.pcx.svn-base
  58. +0 −5 test_docs/.svn/prop-base/test.png.svn-base
  59. +0 −5 test_docs/.svn/prop-base/test.pnm.svn-base
  60. +0 −5 test_docs/.svn/prop-base/test.ppm.svn-base
  61. +0 −5 test_docs/.svn/prop-base/test.ppt.svn-base
  62. +0 −5 test_docs/.svn/prop-base/test.psd.svn-base
  63. +0 −5 test_docs/.svn/prop-base/test.tar.gz.svn-base
  64. +0 −5 test_docs/.svn/prop-base/test.tar.svn-base
  65. +0 −5 test_docs/.svn/prop-base/test.tga.svn-base
  66. +0 −5 test_docs/.svn/prop-base/test.txt.gz.svn-base
  67. +0 −5 test_docs/.svn/prop-base/test.wav.svn-base
  68. +0 −5 test_docs/.svn/prop-base/test.wmf.svn-base
  69. +0 −5 test_docs/.svn/prop-base/test.xcf.svn-base
  70. +0 −5 test_docs/.svn/prop-base/test_1.2.class.svn-base
  71. +0 −5 test_docs/.svn/prop-base/test_1.3.class.svn-base
  72. +0 −5 test_docs/.svn/prop-base/test_1.4.class.svn-base
  73. +0 −5 test_docs/.svn/prop-base/test_1.5.class.svn-base
  74. +0 −5 test_docs/.svn/prop-base/test_128_44_jstereo.mp3.svn-base
  75. +0 −5 test_docs/.svn/prop-base/test_excel_2000.xls.svn-base
  76. +0 −5 test_docs/.svn/prop-base/test_nocompress.tif.svn-base
  77. +0 −5 test_docs/.svn/prop-base/test_word_2000.doc.svn-base
  78. +0 −5 test_docs/.svn/prop-base/test_word_6.0_95.doc.svn-base
  79. BIN test_docs/.svn/text-base/test.au.svn-base
  80. BIN test_docs/.svn/text-base/test.bin.svn-base
  81. BIN test_docs/.svn/text-base/test.bmp.svn-base
  82. +0 −18 test_docs/.svn/text-base/test.dtd.svn-base
  83. BIN test_docs/.svn/text-base/test.emf.svn-base
  84. +0 −338 test_docs/.svn/text-base/test.eps.svn-base
  85. BIN test_docs/.svn/text-base/test.fli.svn-base
  86. BIN test_docs/.svn/text-base/test.gif.svn-base
  87. BIN test_docs/.svn/text-base/test.ico.svn-base
  88. +0 −5 test_docs/.svn/text-base/test.java.svn-base
  89. BIN test_docs/.svn/text-base/test.jpg.svn-base
  90. BIN test_docs/.svn/text-base/test.mp3.svn-base
  91. BIN test_docs/.svn/text-base/test.ogg.svn-base
  92. BIN test_docs/.svn/text-base/test.pcx.svn-base
  93. +0 −84 test_docs/.svn/text-base/test.pdf.svn-base
  94. +0 −5 test_docs/.svn/text-base/test.pl.svn-base
  95. BIN test_docs/.svn/text-base/test.png.svn-base
  96. +0 −7 test_docs/.svn/text-base/test.pnm.svn-base
  97. +0 −7 test_docs/.svn/text-base/test.ppm.svn-base
  98. BIN test_docs/.svn/text-base/test.ppt.svn-base
  99. +0 −280 test_docs/.svn/text-base/test.ps.svn-base
  100. BIN test_docs/.svn/text-base/test.psd.svn-base
  101. +0 −365 test_docs/.svn/text-base/test.py.svn-base
  102. +0 −16 test_docs/.svn/text-base/test.rtf.svn-base
  103. +0 −3 test_docs/.svn/text-base/test.sh.svn-base
  104. BIN test_docs/.svn/text-base/test.tar.gz.svn-base
  105. BIN test_docs/.svn/text-base/test.tar.svn-base
  106. BIN test_docs/.svn/text-base/test.tga.svn-base
  107. BIN test_docs/.svn/text-base/test.txt.gz.svn-base
  108. +0 −1 test_docs/.svn/text-base/test.txt.svn-base
  109. BIN test_docs/.svn/text-base/test.wav.svn-base
  110. BIN test_docs/.svn/text-base/test.wmf.svn-base
  111. BIN test_docs/.svn/text-base/test.xcf.svn-base
  112. +0 −47 test_docs/.svn/text-base/test.xml.svn-base
  113. +0 −255 test_docs/.svn/text-base/test.xpm.svn-base
  114. BIN test_docs/.svn/text-base/test_1.2.class.svn-base
  115. BIN test_docs/.svn/text-base/test_1.3.class.svn-base
  116. BIN test_docs/.svn/text-base/test_1.4.class.svn-base
  117. BIN test_docs/.svn/text-base/test_1.5.class.svn-base
  118. BIN test_docs/.svn/text-base/test_128_44_jstereo.mp3.svn-base
  119. BIN test_docs/.svn/text-base/test_excel_2000.xls.svn-base
  120. +0 −62 test_docs/.svn/text-base/test_excel_spreadsheet.xml.svn-base
  121. +0 −155 test_docs/.svn/text-base/test_excel_web_archive.mht.svn-base
  122. BIN test_docs/.svn/text-base/test_nocompress.tif.svn-base
  123. BIN test_docs/.svn/text-base/test_word_2000.doc.svn-base
  124. BIN test_docs/.svn/text-base/test_word_6.0_95.doc.svn-base
View
5 lib/.svn/all-wcprops
@@ -1,5 +0,0 @@
-K 25
-svn:wc:ra_dav:version-url
-V 40
-/svnroot/jmimemagic/!svn/ver/1/trunk/lib
-END
View
28 lib/.svn/entries
@@ -1,28 +0,0 @@
-10
-
-dir
-14
-https://jmimemagic.svn.sourceforge.net/svnroot/jmimemagic/trunk/lib
-https://jmimemagic.svn.sourceforge.net/svnroot/jmimemagic
-
-
-
-2006-09-06T04:15:48.563566Z
-1
-arimus
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-e6599ef2-c01c-0410-b8c8-fa748ffdab45
-
View
5 src/.svn/all-wcprops
@@ -1,5 +0,0 @@
-K 25
-svn:wc:ra_dav:version-url
-V 41
-/svnroot/jmimemagic/!svn/ver/10/trunk/src
-END
View
34 src/.svn/entries
@@ -1,34 +0,0 @@
-10
-
-dir
-14
-https://jmimemagic.svn.sourceforge.net/svnroot/jmimemagic/trunk/src
-https://jmimemagic.svn.sourceforge.net/svnroot/jmimemagic
-
-
-
-2006-09-21T20:43:41.948387Z
-10
-arimus
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-e6599ef2-c01c-0410-b8c8-fa748ffdab45
-
-test
-dir
-
-java
-dir
-
View
5 src/main/java/.svn/all-wcprops
@@ -1,5 +0,0 @@
-K 25
-svn:wc:ra_dav:version-url
-V 46
-/svnroot/jmimemagic/!svn/ver/10/trunk/src/java
-END
View
31 src/main/java/.svn/entries
@@ -1,31 +0,0 @@
-10
-
-dir
-14
-https://jmimemagic.svn.sourceforge.net/svnroot/jmimemagic/trunk/src/java
-https://jmimemagic.svn.sourceforge.net/svnroot/jmimemagic
-
-
-
-2006-09-21T20:43:41.948387Z
-10
-arimus
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-e6599ef2-c01c-0410-b8c8-fa748ffdab45
-
-net
-dir
-
View
5 src/main/java/net/.svn/all-wcprops
@@ -1,5 +0,0 @@
-K 25
-svn:wc:ra_dav:version-url
-V 50
-/svnroot/jmimemagic/!svn/ver/10/trunk/src/java/net
-END
View
31 src/main/java/net/.svn/entries
@@ -1,31 +0,0 @@
-10
-
-dir
-14
-https://jmimemagic.svn.sourceforge.net/svnroot/jmimemagic/trunk/src/java/net
-https://jmimemagic.svn.sourceforge.net/svnroot/jmimemagic
-
-
-
-2006-09-21T20:43:41.948387Z
-10
-arimus
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-e6599ef2-c01c-0410-b8c8-fa748ffdab45
-
-sf
-dir
-
View
5 src/main/java/net/sf/.svn/all-wcprops
@@ -1,5 +0,0 @@
-K 25
-svn:wc:ra_dav:version-url
-V 53
-/svnroot/jmimemagic/!svn/ver/10/trunk/src/java/net/sf
-END
View
31 src/main/java/net/sf/.svn/entries
@@ -1,31 +0,0 @@
-10
-
-dir
-14
-https://jmimemagic.svn.sourceforge.net/svnroot/jmimemagic/trunk/src/java/net/sf
-https://jmimemagic.svn.sourceforge.net/svnroot/jmimemagic
-
-
-
-2006-09-21T20:43:41.948387Z
-10
-arimus
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-e6599ef2-c01c-0410-b8c8-fa748ffdab45
-
-jmimemagic
-dir
-
View
65 src/main/java/net/sf/jmimemagic/.svn/all-wcprops
@@ -1,65 +0,0 @@
-K 25
-svn:wc:ra_dav:version-url
-V 64
-/svnroot/jmimemagic/!svn/ver/10/trunk/src/java/net/sf/jmimemagic
-END
-MagicException.java
-K 25
-svn:wc:ra_dav:version-url
-V 83
-/svnroot/jmimemagic/!svn/ver/5/trunk/src/java/net/sf/jmimemagic/MagicException.java
-END
-Magic.java
-K 25
-svn:wc:ra_dav:version-url
-V 74
-/svnroot/jmimemagic/!svn/ver/5/trunk/src/java/net/sf/jmimemagic/Magic.java
-END
-MagicMatcher.java
-K 25
-svn:wc:ra_dav:version-url
-V 81
-/svnroot/jmimemagic/!svn/ver/5/trunk/src/java/net/sf/jmimemagic/MagicMatcher.java
-END
-MagicMatchNotFoundException.java
-K 25
-svn:wc:ra_dav:version-url
-V 96
-/svnroot/jmimemagic/!svn/ver/5/trunk/src/java/net/sf/jmimemagic/MagicMatchNotFoundException.java
-END
-UnsupportedTypeException.java
-K 25
-svn:wc:ra_dav:version-url
-V 93
-/svnroot/jmimemagic/!svn/ver/5/trunk/src/java/net/sf/jmimemagic/UnsupportedTypeException.java
-END
-MagicDetector.java
-K 25
-svn:wc:ra_dav:version-url
-V 82
-/svnroot/jmimemagic/!svn/ver/5/trunk/src/java/net/sf/jmimemagic/MagicDetector.java
-END
-MagicParseException.java
-K 25
-svn:wc:ra_dav:version-url
-V 88
-/svnroot/jmimemagic/!svn/ver/5/trunk/src/java/net/sf/jmimemagic/MagicParseException.java
-END
-MagicMatch.java
-K 25
-svn:wc:ra_dav:version-url
-V 79
-/svnroot/jmimemagic/!svn/ver/5/trunk/src/java/net/sf/jmimemagic/MagicMatch.java
-END
-MagicParser.java
-K 25
-svn:wc:ra_dav:version-url
-V 80
-/svnroot/jmimemagic/!svn/ver/5/trunk/src/java/net/sf/jmimemagic/MagicParser.java
-END
-package.html
-K 25
-svn:wc:ra_dav:version-url
-V 77
-/svnroot/jmimemagic/!svn/ver/10/trunk/src/java/net/sf/jmimemagic/package.html
-END
View
371 src/main/java/net/sf/jmimemagic/.svn/entries
@@ -1,371 +0,0 @@
-10
-
-dir
-14
-https://jmimemagic.svn.sourceforge.net/svnroot/jmimemagic/trunk/src/java/net/sf/jmimemagic
-https://jmimemagic.svn.sourceforge.net/svnroot/jmimemagic
-
-
-
-2006-09-21T20:43:41.948387Z
-10
-arimus
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-e6599ef2-c01c-0410-b8c8-fa748ffdab45
-
-MagicException.java
-file
-
-
-
-
-2011-06-07T20:39:24.000000Z
-a2f19e3e15ade380f0d3e28f4c41d0fc
-2006-09-06T05:38:42.573029Z
-5
-arimus
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-2032
-
-Magic.java
-file
-
-
-
-
-2011-06-07T20:39:24.000000Z
-cba74d420a924d6fb02d7f0d2bc4351d
-2006-09-06T05:38:42.573029Z
-5
-arimus
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-18027
-
-MagicMatcher.java
-file
-
-
-
-
-2011-06-07T20:39:24.000000Z
-457f02fb38345163adfa3c9bddedd115
-2006-09-06T05:38:42.573029Z
-5
-arimus
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-23648
-
-MagicMatchNotFoundException.java
-file
-
-
-
-
-2011-06-07T20:39:24.000000Z
-054da7f2a423f973b516edce200c5785
-2006-09-06T05:38:42.573029Z
-5
-arimus
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-2047
-
-UnsupportedTypeException.java
-file
-
-
-
-
-2011-06-07T20:39:24.000000Z
-89c1026ef3803b8745db497564dec48b
-2006-09-06T05:38:42.573029Z
-5
-arimus
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-2026
-
-MagicDetector.java
-file
-
-
-
-
-2011-06-07T20:39:24.000000Z
-4d029d34d84508210b2a369d101a16e2
-2006-09-06T05:38:42.573029Z
-5
-arimus
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-2893
-
-MagicParseException.java
-file
-
-
-
-
-2011-06-07T20:39:24.000000Z
-2ab4a1a2b0b937dc52c44a05a4cb9e35
-2006-09-06T05:38:42.573029Z
-5
-arimus
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-2013
-
-detectors
-dir
-
-MagicMatch.java
-file
-
-
-
-
-2011-06-07T20:39:24.000000Z
-e216f1693e256d18765316d47788d06e
-2006-09-06T05:38:42.573029Z
-5
-arimus
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-10000
-
-MagicParser.java
-file
-
-
-
-
-2011-06-07T20:39:24.000000Z
-f277ba676a4f796c87e0329528925207
-2006-09-06T05:38:42.573029Z
-5
-arimus
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-19991
-
-package.html
-file
-
-
-
-
-2011-06-07T20:39:24.000000Z
-d37b5a14c7b39c9bb6e09c0bf4220214
-2006-09-21T20:43:41.948387Z
-10
-arimus
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-123
-
View
516 src/main/java/net/sf/jmimemagic/.svn/text-base/Magic.java.svn-base
@@ -1,516 +0,0 @@
-/*
-jMimeMagic(TM) is a Java library for determining the content type of files or
-streams.
-
-Copyright (C) 2004 David Castro
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
-License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-For more information, please email arimus@users.sourceforge.net
-*/
-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;
-
-
-/**
- * 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 HashMap 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)) {
- ArrayList a = (ArrayList) hintMap.get(extension);
- a.add(matcher);
- } else {
- ArrayList 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 = (MagicMatcher) 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();
- ArrayList 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 = (MagicMatcher) 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
- ArrayList 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 = (Collection) 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)
- {
- // Magic magic = new Magic();
- try {
- //Magic.initialize();
- 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, "");
-
- // Collection submatches = match.getSubMatches();
- // if (match == null) {
- // System.out.println(args[0]+": unknown");
- // } else {
- // System.out.println("=============================");
- // System.out.println("filename: "+args[0]);
- // System.out.println("mime type: "+match.getMimeType());
- // System.out.println("description: "+match.getDescription());
- // System.out.println("extension: "+match.getExtension());
- // System.out.println("test: "+new String(match.getTest().array()));
- // System.out.println("bitmask: "+match.getBitmask());
- // System.out.println("offset: "+match.getOffset());
- // System.out.println("length: "+match.getLength());
- // System.out.println("type: "+match.getType());
- // System.out.println("comparator: "+match.getComparator());
- // System.out.println("=============================");
- //
- // Iterator i = submatches.iterator();
- // while (i.hasNext()) {
- // System.out.println("== SUBMATCH =================");
- // MagicMatch m = (MagicMatch)i.next();
- // System.out.println(m.print());
- // System.out.println("=============================");
- // }
- // }
-
- // FileInputStream fis = new FileInputStream(f);
- // ByteBuffer buffer = ByteBuffer.allocate((int)f.length());
- // byte []buf = new byte[2048];
- // int size = 0;
- // while ((size = fis.read(buf, 0, 2048)) > 0) {
- // buffer.put(buf, 0, size);
- // }
- // byte []tmp = buffer.array();
- // match = parser.getMagicMatch(tmp);
- // if (match == null) {
- // System.out.println(args[0]+": unknown");
- // } else {
- // System.out.println(args[0]+": "+match.getDescription());
- // System.out.println(match.getMimeType());
- // }
- } 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);
- }
- }
-}
View
111 src/main/java/net/sf/jmimemagic/.svn/text-base/MagicDetector.java.svn-base
@@ -1,111 +0,0 @@
-/*
-jMimeMagic(TM) is a Java library for determining the content type of files or
-streams.
-
-Copyright (C) 2004 David Castro
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
-License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-For more information, please email arimus@users.sourceforge.net
-*/
-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);
-}
View
72 src/main/java/net/sf/jmimemagic/.svn/text-base/MagicException.java.svn-base
@@ -1,72 +0,0 @@
-/*
-jMimeMagic(TM) is a Java library for determining the content type of files or
-streams.
-
-Copyright (C) 2004 David Castro
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
-License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-For more information, please email arimus@users.sourceforge.net
-*/
-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);
- }
-}
View
423 src/main/java/net/sf/jmimemagic/.svn/text-base/MagicMatch.java.svn-base
@@ -1,423 +0,0 @@
-/*
-jMimeMagic(TM) is a Java library for determining the content type of files or
-streams.
-
-Copyright (C) 2004 David Castro
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
-License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-For more information, please email arimus@users.sourceforge.net
-*/
-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.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 ArrayList 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
- HashMap m = new HashMap();
- m.putAll(properties);
- clone.setProperties(m);
-
- Iterator i = subMatches.iterator();
- ArrayList a = new ArrayList();
-
- while (i.hasNext()) {
- MagicMatch mm = (MagicMatch) i.next();
- a.add(mm);
- }
-
- clone.setSubMatches(a);
-
- clone.setTest(test);
- clone.setType(type);
-
- // TODO Auto-generated method stub
- return clone;
- }
-}
View
72 src/main/java/net/sf/jmimemagic/.svn/text-base/MagicMatchNotFoundException.java.svn-base
@@ -1,72 +0,0 @@
-/*
-jMimeMagic(TM) is a Java library for determining the content type of files or
-streams.
-
-Copyright (C) 2004 David Castro
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
-License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-For more information, please email arimus@users.sourceforge.net
-*/
-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);
- }
-}
View
816 src/main/java/net/sf/jmimemagic/.svn/text-base/MagicMatcher.java.svn-base
@@ -1,816 +0,0 @@
-/*
-jMimeMagic(TM) is a Java library for determining the content type of files or
-streams.
-
-Copyright (C) 2004 David Castro
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
-License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-For more information, please email arimus@users.sourceforge.net
-*/
-package net.sf.jmimemagic;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.oro.text.perl.Perl5Util;
-
-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;
-
-
-/**
- * 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 ArrayList 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();
- String mimeType = match.getMimeType();
-
- 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")) {
- length = (int) file.length() - offset;
-
- 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
- match = getMatch();
-
- 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
- match = getMatch();
-
- 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();
-
- Perl5Util utility = new Perl5Util();
- log.debug("testRegex(): searching for '" + test + "'");
-
- if (comparator == '=') {
- if (utility.match(test, text)) {
- return true;
- } else {
- return false;
- }
- } else if (comparator == '!') {
- if (utility.match(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());
-