/lib/commons-io/apidocs/org/apache/commons/io/filefilter/MagicNumberFileFilter.html

https://bitbucket.org/arkban/somersault · HTML · 571 lines · 488 code · 59 blank · 24 comment · 0 complexity · 790213123a5fb179b5df33bcdeda8776 MD5 · raw file

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <!--NewPage-->
  3. <HTML>
  4. <HEAD>
  5. <!-- Generated by javadoc (build 1.6.0_20) on Tue Sep 28 21:40:06 EDT 2010 -->
  6. <TITLE>
  7. MagicNumberFileFilter (Commons IO 1.5-SNAPSHOT)
  8. </TITLE>
  9. <META NAME="date" CONTENT="2010-09-28">
  10. <LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../../stylesheet.css" TITLE="Style">
  11. <SCRIPT type="text/javascript">
  12. function windowTitle()
  13. {
  14. if (location.href.indexOf('is-external=true') == -1) {
  15. parent.document.title="MagicNumberFileFilter (Commons IO 1.5-SNAPSHOT)";
  16. }
  17. }
  18. </SCRIPT>
  19. <NOSCRIPT>
  20. </NOSCRIPT>
  21. </HEAD>
  22. <BODY BGCOLOR="white" onload="windowTitle();">
  23. <HR>
  24. <!-- ========= START OF TOP NAVBAR ======= -->
  25. <A NAME="navbar_top"><!-- --></A>
  26. <A HREF="#skip-navbar_top" title="Skip navigation links"></A>
  27. <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
  28. <TR>
  29. <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
  30. <A NAME="navbar_top_firstrow"><!-- --></A>
  31. <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
  32. <TR ALIGN="center" VALIGN="top">
  33. <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
  34. <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
  35. <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
  36. <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
  37. <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
  38. <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
  39. <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
  40. </TR>
  41. </TABLE>
  42. </TD>
  43. <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
  44. </EM>
  45. </TD>
  46. </TR>
  47. <TR>
  48. <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
  49. &nbsp;<A HREF="../../../../../org/apache/commons/io/filefilter/IOFileFilter.html" title="interface in org.apache.commons.io.filefilter"><B>PREV CLASS</B></A>&nbsp;
  50. &nbsp;<A HREF="../../../../../org/apache/commons/io/filefilter/NameFileFilter.html" title="class in org.apache.commons.io.filefilter"><B>NEXT CLASS</B></A></FONT></TD>
  51. <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
  52. <A HREF="../../../../../index.html?org/apache/commons/io/filefilter/MagicNumberFileFilter.html" target="_top"><B>FRAMES</B></A> &nbsp;
  53. &nbsp;<A HREF="MagicNumberFileFilter.html" target="_top"><B>NO FRAMES</B></A> &nbsp;
  54. &nbsp;<SCRIPT type="text/javascript">
  55. <!--
  56. if(window==top) {
  57. document.writeln('<A HREF="../../../../../allclasses-noframe.html"><B>All Classes</B></A>');
  58. }
  59. //-->
  60. </SCRIPT>
  61. <NOSCRIPT>
  62. <A HREF="../../../../../allclasses-noframe.html"><B>All Classes</B></A>
  63. </NOSCRIPT>
  64. </FONT></TD>
  65. </TR>
  66. <TR>
  67. <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
  68. SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;<A HREF="#field_summary">FIELD</A>&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
  69. <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
  70. DETAIL:&nbsp;<A HREF="#field_detail">FIELD</A>&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
  71. </TR>
  72. </TABLE>
  73. <A NAME="skip-navbar_top"></A>
  74. <!-- ========= END OF TOP NAVBAR ========= -->
  75. <HR>
  76. <!-- ======== START OF CLASS DATA ======== -->
  77. <H2>
  78. <FONT SIZE="-1">
  79. org.apache.commons.io.filefilter</FONT>
  80. <BR>
  81. Class MagicNumberFileFilter</H2>
  82. <PRE>
  83. <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</A>
  84. <IMG SRC="../../../../../resources/inherit.gif" ALT="extended by "><A HREF="../../../../../org/apache/commons/io/filefilter/AbstractFileFilter.html" title="class in org.apache.commons.io.filefilter">org.apache.commons.io.filefilter.AbstractFileFilter</A>
  85. <IMG SRC="../../../../../resources/inherit.gif" ALT="extended by "><B>org.apache.commons.io.filefilter.MagicNumberFileFilter</B>
  86. </PRE>
  87. <DL>
  88. <DT><B>All Implemented Interfaces:</B> <DD><A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileFilter.html?is-external=true" title="class or interface in java.io">FileFilter</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/FilenameFilter.html?is-external=true" title="class or interface in java.io">FilenameFilter</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html?is-external=true" title="class or interface in java.io">Serializable</A>, <A HREF="../../../../../org/apache/commons/io/filefilter/IOFileFilter.html" title="interface in org.apache.commons.io.filefilter">IOFileFilter</A></DD>
  89. </DL>
  90. <HR>
  91. <DL>
  92. <DT><PRE>public class <B>MagicNumberFileFilter</B><DT>extends <A HREF="../../../../../org/apache/commons/io/filefilter/AbstractFileFilter.html" title="class in org.apache.commons.io.filefilter">AbstractFileFilter</A><DT>implements <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html?is-external=true" title="class or interface in java.io">Serializable</A></DL>
  93. </PRE>
  94. <P>
  95. <p>
  96. File filter for matching files containing a "magic number". A magic number
  97. is a unique series of bytes common to all files of a specific file format.
  98. For instance, all Java class files begin with the bytes
  99. <code>0xCAFEBABE</code>.
  100. </p>
  101. <code><pre>
  102. File dir = new File(".");
  103. MagicNumberFileFilter javaClassFileFilter =
  104. MagicNumberFileFilter(new byte[] {(byte) 0xCA, (byte) 0xFE,
  105. (byte) 0xBA, (byte) 0xBE});
  106. String[] javaClassFiles = dir.list(javaClassFileFilter);
  107. for (String javaClassFile : javaClassFiles) {
  108. System.out.println(javaClassFile);
  109. }
  110. </pre></code>
  111. <p>
  112. Sometimes, such as in the case of TAR files, the
  113. magic number will be offset by a certain number of bytes in the file. In the
  114. case of TAR archive files, this offset is 257 bytes.
  115. </p>
  116. <code><pre>
  117. File dir = new File(".");
  118. MagicNumberFileFilter tarFileFilter =
  119. MagicNumberFileFilter("ustar", 257);
  120. String[] tarFiles = dir.list(tarFileFilter);
  121. for (String tarFile : tarFiles) {
  122. System.out.println(tarFile);
  123. }
  124. </pre></code>
  125. <P>
  126. <P>
  127. <DL>
  128. <DT><B>See Also:</B><DD><A HREF="../../../../../serialized-form.html#org.apache.commons.io.filefilter.MagicNumberFileFilter">Serialized Form</A></DL>
  129. <HR>
  130. <P>
  131. <!-- =========== FIELD SUMMARY =========== -->
  132. <A NAME="field_summary"><!-- --></A>
  133. <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
  134. <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
  135. <TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
  136. <B>Field Summary</B></FONT></TH>
  137. </TR>
  138. <TR BGCOLOR="white" CLASS="TableRowColor">
  139. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  140. <CODE>private &nbsp;long</CODE></FONT></TD>
  141. <TD><CODE><B><A HREF="../../../../../org/apache/commons/io/filefilter/MagicNumberFileFilter.html#byteOffset">byteOffset</A></B></CODE>
  142. <BR>
  143. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The offset (in bytes) within the files that the magic number's bytes
  144. should appear.</TD>
  145. </TR>
  146. <TR BGCOLOR="white" CLASS="TableRowColor">
  147. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  148. <CODE>private &nbsp;byte[]</CODE></FONT></TD>
  149. <TD><CODE><B><A HREF="../../../../../org/apache/commons/io/filefilter/MagicNumberFileFilter.html#magicNumbers">magicNumbers</A></B></CODE>
  150. <BR>
  151. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The magic number to compare against the file's bytes at the provided
  152. offset.</TD>
  153. </TR>
  154. <TR BGCOLOR="white" CLASS="TableRowColor">
  155. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  156. <CODE>private static&nbsp;long</CODE></FONT></TD>
  157. <TD><CODE><B><A HREF="../../../../../org/apache/commons/io/filefilter/MagicNumberFileFilter.html#serialVersionUID">serialVersionUID</A></B></CODE>
  158. <BR>
  159. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The serialization version unique identifier.</TD>
  160. </TR>
  161. </TABLE>
  162. &nbsp;
  163. <!-- ======== CONSTRUCTOR SUMMARY ======== -->
  164. <A NAME="constructor_summary"><!-- --></A>
  165. <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
  166. <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
  167. <TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
  168. <B>Constructor Summary</B></FONT></TH>
  169. </TR>
  170. <TR BGCOLOR="white" CLASS="TableRowColor">
  171. <TD><CODE><B><A HREF="../../../../../org/apache/commons/io/filefilter/MagicNumberFileFilter.html#MagicNumberFileFilter(byte[])">MagicNumberFileFilter</A></B>(byte[]&nbsp;magicNumber)</CODE>
  172. <BR>
  173. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  174. Constructs a new MagicNumberFileFilter and associates it with the magic
  175. number to test for in files.</TD>
  176. </TR>
  177. <TR BGCOLOR="white" CLASS="TableRowColor">
  178. <TD><CODE><B><A HREF="../../../../../org/apache/commons/io/filefilter/MagicNumberFileFilter.html#MagicNumberFileFilter(byte[], long)">MagicNumberFileFilter</A></B>(byte[]&nbsp;magicNumber,
  179. long&nbsp;offset)</CODE>
  180. <BR>
  181. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  182. Constructs a new MagicNumberFileFilter and associates it with the magic
  183. number to test for in files and the byte offset location in the file to
  184. to look for that magic number.</TD>
  185. </TR>
  186. <TR BGCOLOR="white" CLASS="TableRowColor">
  187. <TD><CODE><B><A HREF="../../../../../org/apache/commons/io/filefilter/MagicNumberFileFilter.html#MagicNumberFileFilter(java.lang.String)">MagicNumberFileFilter</A></B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;magicNumber)</CODE>
  188. <BR>
  189. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  190. Constructs a new MagicNumberFileFilter and associates it with the magic
  191. number to test for in files.</TD>
  192. </TR>
  193. <TR BGCOLOR="white" CLASS="TableRowColor">
  194. <TD><CODE><B><A HREF="../../../../../org/apache/commons/io/filefilter/MagicNumberFileFilter.html#MagicNumberFileFilter(java.lang.String, long)">MagicNumberFileFilter</A></B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;magicNumber,
  195. long&nbsp;offset)</CODE>
  196. <BR>
  197. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  198. Constructs a new MagicNumberFileFilter and associates it with the magic
  199. number to test for in files and the byte offset location in the file to
  200. to look for that magic number.</TD>
  201. </TR>
  202. </TABLE>
  203. &nbsp;
  204. <!-- ========== METHOD SUMMARY =========== -->
  205. <A NAME="method_summary"><!-- --></A>
  206. <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
  207. <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
  208. <TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
  209. <B>Method Summary</B></FONT></TH>
  210. </TR>
  211. <TR BGCOLOR="white" CLASS="TableRowColor">
  212. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  213. <CODE>&nbsp;boolean</CODE></FONT></TD>
  214. <TD><CODE><B><A HREF="../../../../../org/apache/commons/io/filefilter/MagicNumberFileFilter.html#accept(java.io.File)">accept</A></B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html?is-external=true" title="class or interface in java.io">File</A>&nbsp;file)</CODE>
  215. <BR>
  216. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  217. Accepts the provided file if the file contains the file filter's magic
  218. number at the specified offset.</TD>
  219. </TR>
  220. <TR BGCOLOR="white" CLASS="TableRowColor">
  221. <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
  222. <CODE>&nbsp;<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A></CODE></FONT></TD>
  223. <TD><CODE><B><A HREF="../../../../../org/apache/commons/io/filefilter/MagicNumberFileFilter.html#toString()">toString</A></B>()</CODE>
  224. <BR>
  225. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns a String representation of the file filter, which includes the
  226. magic number bytes and byte offset.</TD>
  227. </TR>
  228. </TABLE>
  229. &nbsp;<A NAME="methods_inherited_from_class_org.apache.commons.io.filefilter.AbstractFileFilter"><!-- --></A>
  230. <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
  231. <TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
  232. <TH ALIGN="left"><B>Methods inherited from class org.apache.commons.io.filefilter.<A HREF="../../../../../org/apache/commons/io/filefilter/AbstractFileFilter.html" title="class in org.apache.commons.io.filefilter">AbstractFileFilter</A></B></TH>
  233. </TR>
  234. <TR BGCOLOR="white" CLASS="TableRowColor">
  235. <TD><CODE><A HREF="../../../../../org/apache/commons/io/filefilter/AbstractFileFilter.html#accept(java.io.File, java.lang.String)">accept</A></CODE></TD>
  236. </TR>
  237. </TABLE>
  238. &nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
  239. <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
  240. <TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
  241. <TH ALIGN="left"><B>Methods inherited from class java.lang.<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A></B></TH>
  242. </TR>
  243. <TR BGCOLOR="white" CLASS="TableRowColor">
  244. <TD><CODE><A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#clone()" title="class or interface in java.lang">clone</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang">equals</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#finalize()" title="class or interface in java.lang">finalize</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#getClass()" title="class or interface in java.lang">getClass</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#hashCode()" title="class or interface in java.lang">hashCode</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#notify()" title="class or interface in java.lang">notify</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#notifyAll()" title="class or interface in java.lang">notifyAll</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#wait()" title="class or interface in java.lang">wait</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#wait(long)" title="class or interface in java.lang">wait</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#wait(long, int)" title="class or interface in java.lang">wait</A></CODE></TD>
  245. </TR>
  246. </TABLE>
  247. &nbsp;
  248. <P>
  249. <!-- ============ FIELD DETAIL =========== -->
  250. <A NAME="field_detail"><!-- --></A>
  251. <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
  252. <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
  253. <TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
  254. <B>Field Detail</B></FONT></TH>
  255. </TR>
  256. </TABLE>
  257. <A NAME="serialVersionUID"><!-- --></A><H3>
  258. serialVersionUID</H3>
  259. <PRE>
  260. private static final long <B>serialVersionUID</B></PRE>
  261. <DL>
  262. <DD>The serialization version unique identifier.
  263. <P>
  264. <DL>
  265. <DT><B>See Also:</B><DD><A HREF="../../../../../constant-values.html#org.apache.commons.io.filefilter.MagicNumberFileFilter.serialVersionUID">Constant Field Values</A></DL>
  266. </DL>
  267. <HR>
  268. <A NAME="magicNumbers"><!-- --></A><H3>
  269. magicNumbers</H3>
  270. <PRE>
  271. private final byte[] <B>magicNumbers</B></PRE>
  272. <DL>
  273. <DD>The magic number to compare against the file's bytes at the provided
  274. offset.
  275. <P>
  276. <DL>
  277. </DL>
  278. </DL>
  279. <HR>
  280. <A NAME="byteOffset"><!-- --></A><H3>
  281. byteOffset</H3>
  282. <PRE>
  283. private final long <B>byteOffset</B></PRE>
  284. <DL>
  285. <DD>The offset (in bytes) within the files that the magic number's bytes
  286. should appear.
  287. <P>
  288. <DL>
  289. </DL>
  290. </DL>
  291. <!-- ========= CONSTRUCTOR DETAIL ======== -->
  292. <A NAME="constructor_detail"><!-- --></A>
  293. <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
  294. <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
  295. <TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
  296. <B>Constructor Detail</B></FONT></TH>
  297. </TR>
  298. </TABLE>
  299. <A NAME="MagicNumberFileFilter(byte[])"><!-- --></A><H3>
  300. MagicNumberFileFilter</H3>
  301. <PRE>
  302. public <B>MagicNumberFileFilter</B>(byte[]&nbsp;magicNumber)</PRE>
  303. <DL>
  304. <DD><p>
  305. Constructs a new MagicNumberFileFilter and associates it with the magic
  306. number to test for in files. This constructor assumes a starting offset
  307. of <code>0</code>.
  308. </p>
  309. <p>
  310. It is important to note that <em>the array is not cloned</em> and that
  311. any changes to the magic number array after construction will affect the
  312. behavior of this file filter.
  313. </p>
  314. <code><pre>
  315. MagicNumberFileFilter javaClassFileFilter =
  316. MagicNumberFileFilter(new byte[] {(byte) 0xCA, (byte) 0xFE,
  317. (byte) 0xBA, (byte) 0xBE});
  318. </pre></code>
  319. <P>
  320. <DL>
  321. <DT><B>Parameters:</B><DD><CODE>magicNumber</CODE> - the magic number to look for in the file.
  322. <DT><B>Throws:</B>
  323. <DD><CODE><A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</A></CODE> - if <code>magicNumber</code> is
  324. <code>null</code>, or contains no bytes.</DL>
  325. </DL>
  326. <HR>
  327. <A NAME="MagicNumberFileFilter(java.lang.String)"><!-- --></A><H3>
  328. MagicNumberFileFilter</H3>
  329. <PRE>
  330. public <B>MagicNumberFileFilter</B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;magicNumber)</PRE>
  331. <DL>
  332. <DD><p>
  333. Constructs a new MagicNumberFileFilter and associates it with the magic
  334. number to test for in files. This constructor assumes a starting offset
  335. of <code>0</code>.
  336. </p>
  337. Example usage:
  338. <pre>
  339. <code>MagicNumberFileFilter xmlFileFilter =
  340. MagicNumberFileFilter("&lt;?xml");
  341. </code>
  342. </pre>
  343. <P>
  344. <DL>
  345. <DT><B>Parameters:</B><DD><CODE>magicNumber</CODE> - the magic number to look for in the file.
  346. The string is converted to bytes using the platform default charset.
  347. <DT><B>Throws:</B>
  348. <DD><CODE><A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</A></CODE> - if <code>magicNumber</code> is
  349. <code>null</code> or the empty String.</DL>
  350. </DL>
  351. <HR>
  352. <A NAME="MagicNumberFileFilter(java.lang.String, long)"><!-- --></A><H3>
  353. MagicNumberFileFilter</H3>
  354. <PRE>
  355. public <B>MagicNumberFileFilter</B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A>&nbsp;magicNumber,
  356. long&nbsp;offset)</PRE>
  357. <DL>
  358. <DD><p>
  359. Constructs a new MagicNumberFileFilter and associates it with the magic
  360. number to test for in files and the byte offset location in the file to
  361. to look for that magic number.
  362. </p>
  363. <code><pre>
  364. MagicNumberFileFilter tarFileFilter =
  365. MagicNumberFileFilter("ustar", 257);
  366. </pre></code>
  367. <P>
  368. <DL>
  369. <DT><B>Parameters:</B><DD><CODE>magicNumber</CODE> - the magic number to look for in the file.
  370. The string is converted to bytes using the platform default charset.<DD><CODE>offset</CODE> - the byte offset in the file to start comparing bytes.
  371. <DT><B>Throws:</B>
  372. <DD><CODE><A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</A></CODE> - if <code>magicNumber</code> is
  373. <code>null</code> or the empty String, or <code>offset</code> is
  374. a negative number.</DL>
  375. </DL>
  376. <HR>
  377. <A NAME="MagicNumberFileFilter(byte[], long)"><!-- --></A><H3>
  378. MagicNumberFileFilter</H3>
  379. <PRE>
  380. public <B>MagicNumberFileFilter</B>(byte[]&nbsp;magicNumber,
  381. long&nbsp;offset)</PRE>
  382. <DL>
  383. <DD><p>
  384. Constructs a new MagicNumberFileFilter and associates it with the magic
  385. number to test for in files and the byte offset location in the file to
  386. to look for that magic number.
  387. </p>
  388. <p>
  389. It is important to note that <em>the array is not cloned</em> and that
  390. any changes to the magic number array after construction will affect the
  391. behavior of this file filter.
  392. </p>
  393. <code><pre>
  394. MagicNumberFileFilter tarFileFilter =
  395. MagicNumberFileFilter(new byte[] {0x75, 0x73, 0x74, 0x61, 0x72}, 257);
  396. </pre></code>
  397. <code><pre>
  398. MagicNumberFileFilter javaClassFileFilter =
  399. MagicNumberFileFilter(new byte[] {0xCA, 0xFE, 0xBA, 0xBE}, 0);
  400. </pre></code>
  401. <P>
  402. <DL>
  403. <DT><B>Parameters:</B><DD><CODE>magicNumber</CODE> - the magic number to look for in the file.<DD><CODE>offset</CODE> - the byte offset in the file to start comparing bytes.
  404. <DT><B>Throws:</B>
  405. <DD><CODE><A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</A></CODE> - if <code>magicNumber</code> is
  406. <code>null</code>, or contains no bytes, or <code>offset</code>
  407. is a negative number.</DL>
  408. </DL>
  409. <!-- ============ METHOD DETAIL ========== -->
  410. <A NAME="method_detail"><!-- --></A>
  411. <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
  412. <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
  413. <TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
  414. <B>Method Detail</B></FONT></TH>
  415. </TR>
  416. </TABLE>
  417. <A NAME="accept(java.io.File)"><!-- --></A><H3>
  418. accept</H3>
  419. <PRE>
  420. public boolean <B>accept</B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html?is-external=true" title="class or interface in java.io">File</A>&nbsp;file)</PRE>
  421. <DL>
  422. <DD><p>
  423. Accepts the provided file if the file contains the file filter's magic
  424. number at the specified offset.
  425. </p>
  426. <p>
  427. If any <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/IOException.html?is-external=true" title="class or interface in java.io"><CODE>IOException</CODE></A>s occur while reading the file, the file will
  428. be rejected.
  429. </p>
  430. <P>
  431. <DD><DL>
  432. <DT><B>Specified by:</B><DD><CODE><A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileFilter.html?is-external=true#accept(java.io.File)" title="class or interface in java.io">accept</A></CODE> in interface <CODE><A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileFilter.html?is-external=true" title="class or interface in java.io">FileFilter</A></CODE><DT><B>Specified by:</B><DD><CODE><A HREF="../../../../../org/apache/commons/io/filefilter/IOFileFilter.html#accept(java.io.File)">accept</A></CODE> in interface <CODE><A HREF="../../../../../org/apache/commons/io/filefilter/IOFileFilter.html" title="interface in org.apache.commons.io.filefilter">IOFileFilter</A></CODE><DT><B>Overrides:</B><DD><CODE><A HREF="../../../../../org/apache/commons/io/filefilter/AbstractFileFilter.html#accept(java.io.File)">accept</A></CODE> in class <CODE><A HREF="../../../../../org/apache/commons/io/filefilter/AbstractFileFilter.html" title="class in org.apache.commons.io.filefilter">AbstractFileFilter</A></CODE></DL>
  433. </DD>
  434. <DD><DL>
  435. <DT><B>Parameters:</B><DD><CODE>file</CODE> - the file to accept or reject.
  436. <DT><B>Returns:</B><DD><code>true</code> if the file contains the filter's magic number
  437. at the specified offset, <code>false</code> otherwise.</DL>
  438. </DD>
  439. </DL>
  440. <HR>
  441. <A NAME="toString()"><!-- --></A><H3>
  442. toString</H3>
  443. <PRE>
  444. public <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> <B>toString</B>()</PRE>
  445. <DL>
  446. <DD>Returns a String representation of the file filter, which includes the
  447. magic number bytes and byte offset.
  448. <P>
  449. <DD><DL>
  450. <DT><B>Overrides:</B><DD><CODE><A HREF="../../../../../org/apache/commons/io/filefilter/AbstractFileFilter.html#toString()">toString</A></CODE> in class <CODE><A HREF="../../../../../org/apache/commons/io/filefilter/AbstractFileFilter.html" title="class in org.apache.commons.io.filefilter">AbstractFileFilter</A></CODE></DL>
  451. </DD>
  452. <DD><DL>
  453. <DT><B>Returns:</B><DD>a String representation of the file filter.</DL>
  454. </DD>
  455. </DL>
  456. <!-- ========= END OF CLASS DATA ========= -->
  457. <HR>
  458. <!-- ======= START OF BOTTOM NAVBAR ====== -->
  459. <A NAME="navbar_bottom"><!-- --></A>
  460. <A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
  461. <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
  462. <TR>
  463. <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
  464. <A NAME="navbar_bottom_firstrow"><!-- --></A>
  465. <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
  466. <TR ALIGN="center" VALIGN="top">
  467. <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
  468. <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
  469. <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
  470. <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
  471. <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
  472. <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
  473. <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
  474. </TR>
  475. </TABLE>
  476. </TD>
  477. <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
  478. </EM>
  479. </TD>
  480. </TR>
  481. <TR>
  482. <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
  483. &nbsp;<A HREF="../../../../../org/apache/commons/io/filefilter/IOFileFilter.html" title="interface in org.apache.commons.io.filefilter"><B>PREV CLASS</B></A>&nbsp;
  484. &nbsp;<A HREF="../../../../../org/apache/commons/io/filefilter/NameFileFilter.html" title="class in org.apache.commons.io.filefilter"><B>NEXT CLASS</B></A></FONT></TD>
  485. <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
  486. <A HREF="../../../../../index.html?org/apache/commons/io/filefilter/MagicNumberFileFilter.html" target="_top"><B>FRAMES</B></A> &nbsp;
  487. &nbsp;<A HREF="MagicNumberFileFilter.html" target="_top"><B>NO FRAMES</B></A> &nbsp;
  488. &nbsp;<SCRIPT type="text/javascript">
  489. <!--
  490. if(window==top) {
  491. document.writeln('<A HREF="../../../../../allclasses-noframe.html"><B>All Classes</B></A>');
  492. }
  493. //-->
  494. </SCRIPT>
  495. <NOSCRIPT>
  496. <A HREF="../../../../../allclasses-noframe.html"><B>All Classes</B></A>
  497. </NOSCRIPT>
  498. </FONT></TD>
  499. </TR>
  500. <TR>
  501. <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
  502. SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;<A HREF="#field_summary">FIELD</A>&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
  503. <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
  504. DETAIL:&nbsp;<A HREF="#field_detail">FIELD</A>&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
  505. </TR>
  506. </TABLE>
  507. <A NAME="skip-navbar_bottom"></A>
  508. <!-- ======== END OF BOTTOM NAVBAR ======= -->
  509. <HR>
  510. Copyright (c) 2002-2010 Apache Software Foundation
  511. </BODY>
  512. </HTML>