com.j256.simplemagic.types
Class RegexType

java.lang.Object
  extended by com.j256.simplemagic.types.RegexType
All Implemented Interfaces:
MagicMatcher

public class RegexType
extends Object
implements MagicMatcher

From the magic(5) man page: A regular expression match in extended POSIX regular expression syntax (like egrep). Regular expressions can take exponential time to process, and their performance is hard to predict, so their use is discouraged. When used in production environments, their performance should be carefully checked. The type specification can be optionally followed by /[c][s]. The 'c' flag makes the match case insensitive, while the 's' flag update the offset to the start offset of the match, rather than the end. The regular expression is tested against line N + 1 onwards, where N is the given offset. Line endings are assumed to be in the machine's native format. ^ and $ match the beginning and end of individual lines, respectively, not beginning and end of file.

Author:
graywatson

Constructor Summary
RegexType()
           
 
Method Summary
 Object convertTestString(String typeStr, String testStr, int offset)
          Converts the test-string from the magic line to be an object to be passed into #isMatch(Object, int, byte[]).
 Object extractValueFromBytes(int offset, byte[] bytes)
          Extract the value from the bytes.
 Object isMatch(Object testValue, Long andValue, boolean unsignedType, Object extractedValue, int offset, byte[] bytes)
          Matches if the bytes match at a certain offset.
 void renderValue(StringBuilder sb, Object extractedValue, Formatter formatter)
          Returns the string version of the extracted value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegexType

public RegexType()
Method Detail

convertTestString

public Object convertTestString(String typeStr,
                                String testStr,
                                int offset)
Description copied from interface: MagicMatcher
Converts the test-string from the magic line to be an object to be passed into #isMatch(Object, int, byte[]).

Specified by:
convertTestString in interface MagicMatcher

extractValueFromBytes

public Object extractValueFromBytes(int offset,
                                    byte[] bytes)
Description copied from interface: MagicMatcher
Extract the value from the bytes.

Specified by:
extractValueFromBytes in interface MagicMatcher
Returns:
The object to be passed to MagicMatcher.isMatch(Object, Long, boolean, Object, int, byte[]) or null if not enough bytes.

isMatch

public Object isMatch(Object testValue,
                      Long andValue,
                      boolean unsignedType,
                      Object extractedValue,
                      int offset,
                      byte[] bytes)
Description copied from interface: MagicMatcher
Matches if the bytes match at a certain offset. Returns the extracted-value object, or null if no match.

Specified by:
isMatch in interface MagicMatcher

renderValue

public void renderValue(StringBuilder sb,
                        Object extractedValue,
                        Formatter formatter)
Description copied from interface: MagicMatcher
Returns the string version of the extracted value.

Specified by:
renderValue in interface MagicMatcher


This content is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.