com.j256.simplemagic.types
Class StringType

java.lang.Object
  extended by com.j256.simplemagic.types.StringType
All Implemented Interfaces:
MagicMatcher
Direct Known Subclasses:
BigEndianString16Type, PStringType, SearchType

public class StringType
extends Object
implements MagicMatcher

From the magic(5) man page: A string of bytes. The string type specification can be optionally followed by /[Bbc]*. The ``B'' flag compacts whitespace in the target, which must contain at least one whitespace character. If the magic has n consecutive blanks, the target needs at least n consecutive blanks to match. The ``b'' flag treats every blank in the target as an optional blank. Finally the ``c'' flag, specifies case insensitive matching: lower-case characters in the magic match both lower and upper case characters in the target, whereas upper case characters in the magic only match upper-case characters in the target.

Author:
graywatson

Nested Class Summary
protected static class StringType.StringTestInfo
          Internal holder for test information about strings.
 
Constructor Summary
StringType()
           
 
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 MagicMatcher.isMatch(Object, Long, boolean, Object, int, byte[]).
 Object extractValueFromBytes(int offset, byte[] bytes)
          Extract the value from the bytes.
protected  String findOffsetMatch(StringType.StringTestInfo info, int offset, byte[] bytes, String line)
          Called from the string and search types to see if a string or byte array matches our pattern.
 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

StringType

public StringType()
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 MagicMatcher.isMatch(Object, Long, boolean, 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.

Specified by:
isMatch in interface MagicMatcher
Returns:
The extracted-value object, or null if no match.

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

findOffsetMatch

protected String findOffsetMatch(StringType.StringTestInfo info,
                                 int offset,
                                 byte[] bytes,
                                 String line)
Called from the string and search types to see if a string or byte array matches our pattern.



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