MagicDetector implements Detector { public static MagicDetector parse( MediaType mediaType, String type, String offset, String value, String mask) { int start = 0; int end = 0; if (offset != null) { int colon = offset.indexOf(':'); if (colon == -1) { start = Integer.parseInt(offset); end = start; } else { start = Integer.parseInt(offset.substring(0, colon)); end = Integer.parseInt(offset.substring(colon + 1)); } } byte[] patternBytes = decodeValue(value, type); byte[] maskBytes = null; if (mask != null) { maskBytes = decodeValue(mask, type); } return new MagicDetector( mediaType, patternBytes, maskBytes, type.equals("regex"), type.equals("stringignorecase"), start, end); } MagicDetector(MediaType type, byte[] pattern);  MagicDetector(MediaType type, byte[] pattern, int offset);  MagicDetector(
        MediaType type, byte[] pattern, byte[] mask,
        int offsetRangeBegin, int offsetRangeEnd);  MagicDetector(
            MediaType type, byte[] pattern, byte[] mask,
            boolean isRegex,
            int offsetRangeBegin, int offsetRangeEnd);  MagicDetector(
            MediaType type, byte[] pattern, byte[] mask,
            boolean isRegex, boolean isStringIgnoreCase,
            int offsetRangeBegin, int offsetRangeEnd); static MagicDetector parse(
            MediaType mediaType,
            String type, String offset, String value, String mask); MediaType detect(InputStream input, Metadata metadata); int getLength(); String toString();  }
@Test public void testDetectString() throws Exception { String data = "abcdEFGhijklmnoPQRstuvwxyz0123456789"; MediaType testMT = new MediaType("application", "test"); Detector detector; detector = MagicDetector.parse(testMT, "string", "0:20", "abcd", null); assertDetect(detector, testMT, data.getBytes(US_ASCII)); detector = MagicDetector.parse(testMT, "string", "0:20", "cdEFGh", null); assertDetect(detector, testMT, data.getBytes(US_ASCII)); detector = MagicDetector.parse(testMT, "unicodeLE", "0:20", "cdEFGh", null); assertDetect(detector, testMT, data.getBytes(UTF_16LE)); detector = MagicDetector.parse(testMT, "unicodeBE", "0:20", "cdEFGh", null); assertDetect(detector, testMT, data.getBytes(UTF_16BE)); detector = MagicDetector.parse(testMT, "stringignorecase", "0:20", "BcDeFgHiJKlm", null); assertDetect(detector, testMT, data.getBytes(US_ASCII)); }