/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
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <!--NewPage-->
- <HTML>
- <HEAD>
- <!-- Generated by javadoc (build 1.6.0_20) on Tue Sep 28 21:40:06 EDT 2010 -->
- <TITLE>
- MagicNumberFileFilter (Commons IO 1.5-SNAPSHOT)
- </TITLE>
- <META NAME="date" CONTENT="2010-09-28">
- <LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../../stylesheet.css" TITLE="Style">
- <SCRIPT type="text/javascript">
- function windowTitle()
- {
- if (location.href.indexOf('is-external=true') == -1) {
- parent.document.title="MagicNumberFileFilter (Commons IO 1.5-SNAPSHOT)";
- }
- }
- </SCRIPT>
- <NOSCRIPT>
- </NOSCRIPT>
- </HEAD>
- <BODY BGCOLOR="white" onload="windowTitle();">
- <HR>
- <!-- ========= START OF TOP NAVBAR ======= -->
- <A NAME="navbar_top"><!-- --></A>
- <A HREF="#skip-navbar_top" title="Skip navigation links"></A>
- <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
- <TR>
- <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
- <A NAME="navbar_top_firstrow"><!-- --></A>
- <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
- <TR ALIGN="center" VALIGN="top">
- <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
- <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
- <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
- <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
- <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
- <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
- <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
- </TR>
- </TABLE>
- </TD>
- <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
- </EM>
- </TD>
- </TR>
- <TR>
- <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
- <A HREF="../../../../../org/apache/commons/io/filefilter/IOFileFilter.html" title="interface in org.apache.commons.io.filefilter"><B>PREV CLASS</B></A>
- <A HREF="../../../../../org/apache/commons/io/filefilter/NameFileFilter.html" title="class in org.apache.commons.io.filefilter"><B>NEXT CLASS</B></A></FONT></TD>
- <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
- <A HREF="../../../../../index.html?org/apache/commons/io/filefilter/MagicNumberFileFilter.html" target="_top"><B>FRAMES</B></A>
- <A HREF="MagicNumberFileFilter.html" target="_top"><B>NO FRAMES</B></A>
- <SCRIPT type="text/javascript">
- <!--
- if(window==top) {
- document.writeln('<A HREF="../../../../../allclasses-noframe.html"><B>All Classes</B></A>');
- }
- //-->
- </SCRIPT>
- <NOSCRIPT>
- <A HREF="../../../../../allclasses-noframe.html"><B>All Classes</B></A>
- </NOSCRIPT>
- </FONT></TD>
- </TR>
- <TR>
- <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
- SUMMARY: NESTED | <A HREF="#field_summary">FIELD</A> | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD>
- <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
- DETAIL: <A HREF="#field_detail">FIELD</A> | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD>
- </TR>
- </TABLE>
- <A NAME="skip-navbar_top"></A>
- <!-- ========= END OF TOP NAVBAR ========= -->
- <HR>
- <!-- ======== START OF CLASS DATA ======== -->
- <H2>
- <FONT SIZE="-1">
- org.apache.commons.io.filefilter</FONT>
- <BR>
- Class MagicNumberFileFilter</H2>
- <PRE>
- <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>
- <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>
- <IMG SRC="../../../../../resources/inherit.gif" ALT="extended by "><B>org.apache.commons.io.filefilter.MagicNumberFileFilter</B>
- </PRE>
- <DL>
- <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>
- </DL>
- <HR>
- <DL>
- <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>
- </PRE>
- <P>
- <p>
- File filter for matching files containing a "magic number". A magic number
- is a unique series of bytes common to all files of a specific file format.
- For instance, all Java class files begin with the bytes
- <code>0xCAFEBABE</code>.
- </p>
-
- <code><pre>
- File dir = new File(".");
- MagicNumberFileFilter javaClassFileFilter =
- MagicNumberFileFilter(new byte[] {(byte) 0xCA, (byte) 0xFE,
- (byte) 0xBA, (byte) 0xBE});
- String[] javaClassFiles = dir.list(javaClassFileFilter);
- for (String javaClassFile : javaClassFiles) {
- System.out.println(javaClassFile);
- }
- </pre></code>
-
- <p>
- Sometimes, such as in the case of TAR files, the
- magic number will be offset by a certain number of bytes in the file. In the
- case of TAR archive files, this offset is 257 bytes.
- </p>
-
- <code><pre>
- File dir = new File(".");
- MagicNumberFileFilter tarFileFilter =
- MagicNumberFileFilter("ustar", 257);
- String[] tarFiles = dir.list(tarFileFilter);
- for (String tarFile : tarFiles) {
- System.out.println(tarFile);
- }
- </pre></code>
- <P>
- <P>
- <DL>
- <DT><B>See Also:</B><DD><A HREF="../../../../../serialized-form.html#org.apache.commons.io.filefilter.MagicNumberFileFilter">Serialized Form</A></DL>
- <HR>
- <P>
- <!-- =========== FIELD SUMMARY =========== -->
- <A NAME="field_summary"><!-- --></A>
- <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
- <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
- <TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
- <B>Field Summary</B></FONT></TH>
- </TR>
- <TR BGCOLOR="white" CLASS="TableRowColor">
- <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
- <CODE>private long</CODE></FONT></TD>
- <TD><CODE><B><A HREF="../../../../../org/apache/commons/io/filefilter/MagicNumberFileFilter.html#byteOffset">byteOffset</A></B></CODE>
- <BR>
- The offset (in bytes) within the files that the magic number's bytes
- should appear.</TD>
- </TR>
- <TR BGCOLOR="white" CLASS="TableRowColor">
- <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
- <CODE>private byte[]</CODE></FONT></TD>
- <TD><CODE><B><A HREF="../../../../../org/apache/commons/io/filefilter/MagicNumberFileFilter.html#magicNumbers">magicNumbers</A></B></CODE>
- <BR>
- The magic number to compare against the file's bytes at the provided
- offset.</TD>
- </TR>
- <TR BGCOLOR="white" CLASS="TableRowColor">
- <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
- <CODE>private static long</CODE></FONT></TD>
- <TD><CODE><B><A HREF="../../../../../org/apache/commons/io/filefilter/MagicNumberFileFilter.html#serialVersionUID">serialVersionUID</A></B></CODE>
- <BR>
- The serialization version unique identifier.</TD>
- </TR>
- </TABLE>
-
- <!-- ======== CONSTRUCTOR SUMMARY ======== -->
- <A NAME="constructor_summary"><!-- --></A>
- <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
- <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
- <TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
- <B>Constructor Summary</B></FONT></TH>
- </TR>
- <TR BGCOLOR="white" CLASS="TableRowColor">
- <TD><CODE><B><A HREF="../../../../../org/apache/commons/io/filefilter/MagicNumberFileFilter.html#MagicNumberFileFilter(byte[])">MagicNumberFileFilter</A></B>(byte[] magicNumber)</CODE>
- <BR>
-
- Constructs a new MagicNumberFileFilter and associates it with the magic
- number to test for in files.</TD>
- </TR>
- <TR BGCOLOR="white" CLASS="TableRowColor">
- <TD><CODE><B><A HREF="../../../../../org/apache/commons/io/filefilter/MagicNumberFileFilter.html#MagicNumberFileFilter(byte[], long)">MagicNumberFileFilter</A></B>(byte[] magicNumber,
- long offset)</CODE>
- <BR>
-
- Constructs a new MagicNumberFileFilter and associates it with the magic
- number to test for in files and the byte offset location in the file to
- to look for that magic number.</TD>
- </TR>
- <TR BGCOLOR="white" CLASS="TableRowColor">
- <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> magicNumber)</CODE>
- <BR>
-
- Constructs a new MagicNumberFileFilter and associates it with the magic
- number to test for in files.</TD>
- </TR>
- <TR BGCOLOR="white" CLASS="TableRowColor">
- <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> magicNumber,
- long offset)</CODE>
- <BR>
-
- Constructs a new MagicNumberFileFilter and associates it with the magic
- number to test for in files and the byte offset location in the file to
- to look for that magic number.</TD>
- </TR>
- </TABLE>
-
- <!-- ========== METHOD SUMMARY =========== -->
- <A NAME="method_summary"><!-- --></A>
- <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
- <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
- <TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
- <B>Method Summary</B></FONT></TH>
- </TR>
- <TR BGCOLOR="white" CLASS="TableRowColor">
- <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
- <CODE> boolean</CODE></FONT></TD>
- <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> file)</CODE>
- <BR>
-
- Accepts the provided file if the file contains the file filter's magic
- number at the specified offset.</TD>
- </TR>
- <TR BGCOLOR="white" CLASS="TableRowColor">
- <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
- <CODE> <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>
- <TD><CODE><B><A HREF="../../../../../org/apache/commons/io/filefilter/MagicNumberFileFilter.html#toString()">toString</A></B>()</CODE>
- <BR>
- Returns a String representation of the file filter, which includes the
- magic number bytes and byte offset.</TD>
- </TR>
- </TABLE>
- <A NAME="methods_inherited_from_class_org.apache.commons.io.filefilter.AbstractFileFilter"><!-- --></A>
- <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
- <TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
- <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>
- </TR>
- <TR BGCOLOR="white" CLASS="TableRowColor">
- <TD><CODE><A HREF="../../../../../org/apache/commons/io/filefilter/AbstractFileFilter.html#accept(java.io.File, java.lang.String)">accept</A></CODE></TD>
- </TR>
- </TABLE>
- <A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
- <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
- <TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
- <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>
- </TR>
- <TR BGCOLOR="white" CLASS="TableRowColor">
- <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>
- </TR>
- </TABLE>
-
- <P>
- <!-- ============ FIELD DETAIL =========== -->
- <A NAME="field_detail"><!-- --></A>
- <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
- <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
- <TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
- <B>Field Detail</B></FONT></TH>
- </TR>
- </TABLE>
- <A NAME="serialVersionUID"><!-- --></A><H3>
- serialVersionUID</H3>
- <PRE>
- private static final long <B>serialVersionUID</B></PRE>
- <DL>
- <DD>The serialization version unique identifier.
- <P>
- <DL>
- <DT><B>See Also:</B><DD><A HREF="../../../../../constant-values.html#org.apache.commons.io.filefilter.MagicNumberFileFilter.serialVersionUID">Constant Field Values</A></DL>
- </DL>
- <HR>
- <A NAME="magicNumbers"><!-- --></A><H3>
- magicNumbers</H3>
- <PRE>
- private final byte[] <B>magicNumbers</B></PRE>
- <DL>
- <DD>The magic number to compare against the file's bytes at the provided
- offset.
- <P>
- <DL>
- </DL>
- </DL>
- <HR>
- <A NAME="byteOffset"><!-- --></A><H3>
- byteOffset</H3>
- <PRE>
- private final long <B>byteOffset</B></PRE>
- <DL>
- <DD>The offset (in bytes) within the files that the magic number's bytes
- should appear.
- <P>
- <DL>
- </DL>
- </DL>
- <!-- ========= CONSTRUCTOR DETAIL ======== -->
- <A NAME="constructor_detail"><!-- --></A>
- <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
- <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
- <TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
- <B>Constructor Detail</B></FONT></TH>
- </TR>
- </TABLE>
- <A NAME="MagicNumberFileFilter(byte[])"><!-- --></A><H3>
- MagicNumberFileFilter</H3>
- <PRE>
- public <B>MagicNumberFileFilter</B>(byte[] magicNumber)</PRE>
- <DL>
- <DD><p>
- Constructs a new MagicNumberFileFilter and associates it with the magic
- number to test for in files. This constructor assumes a starting offset
- of <code>0</code>.
- </p>
-
- <p>
- It is important to note that <em>the array is not cloned</em> and that
- any changes to the magic number array after construction will affect the
- behavior of this file filter.
- </p>
-
- <code><pre>
- MagicNumberFileFilter javaClassFileFilter =
- MagicNumberFileFilter(new byte[] {(byte) 0xCA, (byte) 0xFE,
- (byte) 0xBA, (byte) 0xBE});
- </pre></code>
- <P>
- <DL>
- <DT><B>Parameters:</B><DD><CODE>magicNumber</CODE> - the magic number to look for in the file.
- <DT><B>Throws:</B>
- <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
- <code>null</code>, or contains no bytes.</DL>
- </DL>
- <HR>
- <A NAME="MagicNumberFileFilter(java.lang.String)"><!-- --></A><H3>
- MagicNumberFileFilter</H3>
- <PRE>
- 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> magicNumber)</PRE>
- <DL>
- <DD><p>
- Constructs a new MagicNumberFileFilter and associates it with the magic
- number to test for in files. This constructor assumes a starting offset
- of <code>0</code>.
- </p>
-
- Example usage:
- <pre>
- <code>MagicNumberFileFilter xmlFileFilter =
- MagicNumberFileFilter("<?xml");
- </code>
- </pre>
- <P>
- <DL>
- <DT><B>Parameters:</B><DD><CODE>magicNumber</CODE> - the magic number to look for in the file.
- The string is converted to bytes using the platform default charset.
- <DT><B>Throws:</B>
- <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
- <code>null</code> or the empty String.</DL>
- </DL>
- <HR>
- <A NAME="MagicNumberFileFilter(java.lang.String, long)"><!-- --></A><H3>
- MagicNumberFileFilter</H3>
- <PRE>
- 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> magicNumber,
- long offset)</PRE>
- <DL>
- <DD><p>
- Constructs a new MagicNumberFileFilter and associates it with the magic
- number to test for in files and the byte offset location in the file to
- to look for that magic number.
- </p>
-
- <code><pre>
- MagicNumberFileFilter tarFileFilter =
- MagicNumberFileFilter("ustar", 257);
- </pre></code>
- <P>
- <DL>
- <DT><B>Parameters:</B><DD><CODE>magicNumber</CODE> - the magic number to look for in the file.
- 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.
- <DT><B>Throws:</B>
- <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
- <code>null</code> or the empty String, or <code>offset</code> is
- a negative number.</DL>
- </DL>
- <HR>
- <A NAME="MagicNumberFileFilter(byte[], long)"><!-- --></A><H3>
- MagicNumberFileFilter</H3>
- <PRE>
- public <B>MagicNumberFileFilter</B>(byte[] magicNumber,
- long offset)</PRE>
- <DL>
- <DD><p>
- Constructs a new MagicNumberFileFilter and associates it with the magic
- number to test for in files and the byte offset location in the file to
- to look for that magic number.
- </p>
-
- <p>
- It is important to note that <em>the array is not cloned</em> and that
- any changes to the magic number array after construction will affect the
- behavior of this file filter.
- </p>
-
- <code><pre>
- MagicNumberFileFilter tarFileFilter =
- MagicNumberFileFilter(new byte[] {0x75, 0x73, 0x74, 0x61, 0x72}, 257);
- </pre></code>
-
- <code><pre>
- MagicNumberFileFilter javaClassFileFilter =
- MagicNumberFileFilter(new byte[] {0xCA, 0xFE, 0xBA, 0xBE}, 0);
- </pre></code>
- <P>
- <DL>
- <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.
- <DT><B>Throws:</B>
- <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
- <code>null</code>, or contains no bytes, or <code>offset</code>
- is a negative number.</DL>
- </DL>
- <!-- ============ METHOD DETAIL ========== -->
- <A NAME="method_detail"><!-- --></A>
- <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
- <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
- <TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
- <B>Method Detail</B></FONT></TH>
- </TR>
- </TABLE>
- <A NAME="accept(java.io.File)"><!-- --></A><H3>
- accept</H3>
- <PRE>
- 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> file)</PRE>
- <DL>
- <DD><p>
- Accepts the provided file if the file contains the file filter's magic
- number at the specified offset.
- </p>
-
- <p>
- 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
- be rejected.
- </p>
- <P>
- <DD><DL>
- <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>
- </DD>
- <DD><DL>
- <DT><B>Parameters:</B><DD><CODE>file</CODE> - the file to accept or reject.
- <DT><B>Returns:</B><DD><code>true</code> if the file contains the filter's magic number
- at the specified offset, <code>false</code> otherwise.</DL>
- </DD>
- </DL>
- <HR>
- <A NAME="toString()"><!-- --></A><H3>
- toString</H3>
- <PRE>
- 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>
- <DL>
- <DD>Returns a String representation of the file filter, which includes the
- magic number bytes and byte offset.
- <P>
- <DD><DL>
- <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>
- </DD>
- <DD><DL>
- <DT><B>Returns:</B><DD>a String representation of the file filter.</DL>
- </DD>
- </DL>
- <!-- ========= END OF CLASS DATA ========= -->
- <HR>
- <!-- ======= START OF BOTTOM NAVBAR ====== -->
- <A NAME="navbar_bottom"><!-- --></A>
- <A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
- <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
- <TR>
- <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
- <A NAME="navbar_bottom_firstrow"><!-- --></A>
- <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
- <TR ALIGN="center" VALIGN="top">
- <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
- <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
- <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
- <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
- <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
- <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
- <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
- </TR>
- </TABLE>
- </TD>
- <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
- </EM>
- </TD>
- </TR>
- <TR>
- <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
- <A HREF="../../../../../org/apache/commons/io/filefilter/IOFileFilter.html" title="interface in org.apache.commons.io.filefilter"><B>PREV CLASS</B></A>
- <A HREF="../../../../../org/apache/commons/io/filefilter/NameFileFilter.html" title="class in org.apache.commons.io.filefilter"><B>NEXT CLASS</B></A></FONT></TD>
- <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
- <A HREF="../../../../../index.html?org/apache/commons/io/filefilter/MagicNumberFileFilter.html" target="_top"><B>FRAMES</B></A>
- <A HREF="MagicNumberFileFilter.html" target="_top"><B>NO FRAMES</B></A>
- <SCRIPT type="text/javascript">
- <!--
- if(window==top) {
- document.writeln('<A HREF="../../../../../allclasses-noframe.html"><B>All Classes</B></A>');
- }
- //-->
- </SCRIPT>
- <NOSCRIPT>
- <A HREF="../../../../../allclasses-noframe.html"><B>All Classes</B></A>
- </NOSCRIPT>
- </FONT></TD>
- </TR>
- <TR>
- <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
- SUMMARY: NESTED | <A HREF="#field_summary">FIELD</A> | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD>
- <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
- DETAIL: <A HREF="#field_detail">FIELD</A> | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD>
- </TR>
- </TABLE>
- <A NAME="skip-navbar_bottom"></A>
- <!-- ======== END OF BOTTOM NAVBAR ======= -->
- <HR>
- Copyright (c) 2002-2010 Apache Software Foundation
- </BODY>
- </HTML>