Class BinarySignatureDescriber

  • All Implemented Interfaces:
    IContentDescriber, IExecutableExtension

    public final class BinarySignatureDescriber
    extends Object
    implements IContentDescriber, IExecutableExtension
    A content describer for binary formats that present some simple signature at a known, fixed offset.

    This executable extension supports three parameters: "signature", "offset" and "required", the first one being mandatory. If the ":-" method is used, then the value is treated as the "signature".

    The "signature" parameter is a sequence of hex codes, one for each byte in the signature. For example, "CA FE BA BE" would be a signature for Java class files.

    The "offset" parameter is an integer indicating the offset where the signature's first byte is found.

    The "required" parameter is a boolean (default is " true") indicating whether the absence of a signature should deem the contents validity status as IContentDescriber.INVALID or IContentDescriber.INDETERMINATE.

    This class is not intended to be subclassed or instantiated by clients, only to be referenced by the "describer" configuration element in extensions to the org.eclipse.core.runtime.contentTypes extension point.

    Since:
    3.0
    • Constructor Detail

      • BinarySignatureDescriber

        public BinarySignatureDescriber()
    • Method Detail

      • describe

        public int describe​(InputStream contents,
                            IContentDescription description)
                     throws IOException
        Description copied from interface: IContentDescriber
        Tries to fill a description for the given contents. Returns an int indicating whether the given stream of bytes represents a valid sample for its corresponding content type. If no content description is provided, this method should perform content type validation.

        The input stream must be kept open, and any IOExceptions while reading the stream should flow to the caller.

        Specified by:
        describe in interface IContentDescriber
        Parameters:
        contents - the contents to be examined
        description - a description to be filled in, or null if only content type validation is to be performed
        Returns:
        one of the following:
        • VALID
        • INVALID
        • INDETERMINATE
        Throws:
        IOException - if an I/O error occurs
        See Also:
        IContentDescription, IContentDescriber.VALID, IContentDescriber.INVALID, IContentDescriber.INDETERMINATE
      • setInitializationData

        public void setInitializationData​(IConfigurationElement config,
                                          String propertyName,
                                          Object data)
                                   throws CoreException
        Description copied from interface: IExecutableExtension
        This method is called by the implementation of the method IConfigurationElement.createExecutableExtension on a newly constructed extension, passing it its relevant configuration information. Most executable extensions only make use of the first two call arguments.

        Regular executable extensions specify their Java implementation class name as an attribute of the configuration element for the extension. For example

             <action run="com.example.BaseAction"/>
         

        In the above example, this method would be called with a reference to the <action> element (first argument), and "run" as the name of the attribute that defined this executable extension (second argument).

        The last parameter is for the specific use of extension adapters and is typically not used by regular executable extensions.

        There are two supported ways of associating additional adapter-specific data with the configuration in a way that is transparent to the extension point implementor:

        (1) by specifying adapter data as part of the implementation class attribute value. The Java class name can be followed by a ":" separator, followed by any adapter data in string form. For example, if the extension point specifies an attribute "run" to contain the name of the extension implementation, an adapter can be configured as

             <action run="com.example.ExternalAdapter:./cmds/util.exe -opt 3"/>
         

        (2) by converting the attribute used to specify the executable extension to a child element of the original configuration element, and specifying the adapter data in the form of xml markup. Using this form, the example above would become

             <action>
                 <run class="com.xyz.ExternalAdapter">
                     <parameter name="exec" value="./cmds/util.exe"/>
                     <parameter name="opt"  value="3"/>
                 </run>
             </action>
         

        Form (2) will typically only be used for extension points that anticipate the majority of extensions configured into it will in fact be in the form of adapters.

        In either case, the specified adapter class is instantiated using its 0-argument public constructor. The adapter data is passed as the last argument of this method. The data argument is defined as Object. It can have the following values:

        • null, if no adapter data was supplied
        • in case (1), the initialization data string is passed as a String
        • in case (2), the initialization data is passed as a Hashtable containing the actual parameter names and values (both Strings)
        Specified by:
        setInitializationData in interface IExecutableExtension
        Parameters:
        config - the configuration element used to trigger this execution. It can be queried by the executable extension for specific configuration properties
        propertyName - the name of an attribute of the configuration element used on the createExecutableExtension(String) call. This argument can be used in the cases where a single configuration element is used to define multiple executable extensions.
        data - adapter data in the form of a String, a Hashtable, or null.
        Throws:
        CoreException - if error(s) detected during initialization processing
        See Also:
        IConfigurationElement.createExecutableExtension(String)