TrieParser implements Serializable { public int setUTF8Value(CharSequence cs, long value) { if (cs.length()<<3 > workingPipe.maxVarLen) { workingPipe = RawDataSchema.instance.newPipe(2,cs.length()); workingPipe.initBuffers(); } Pipe.addMsgIdx(workingPipe, RawDataSchema.MSG_CHUNKEDSTREAM_1); int origPos = Pipe.getWorkingBlobHeadPosition(workingPipe); int len = Pipe.copyUTF8ToByte(cs, 0, cs.length(), workingPipe); Pipe.addBytePosAndLen(workingPipe, origPos, len); Pipe.publishWrites(workingPipe); Pipe.confirmLowLevelWrite(workingPipe, Pipe.sizeOf(workingPipe, RawDataSchema.MSG_CHUNKEDSTREAM_1)); Pipe.takeMsgIdx(workingPipe); setValue(workingPipe, value); Pipe.confirmLowLevelRead(workingPipe, Pipe.sizeOf(workingPipe, RawDataSchema.MSG_CHUNKEDSTREAM_1)); Pipe.releaseReadLock(workingPipe); return len; } TrieParser();  TrieParser(int size);  TrieParser(int size, boolean skipDeepChecks);  TrieParser(int size, int resultSize, boolean skipDeepChecks, boolean supportsExtraction);  TrieParser(int size, int resultSize, boolean skipDeepChecks, boolean supportsExtraction, boolean ignoreCase);  TrieParser(int size, int resultSize, boolean skipDeepChecks, boolean supportsExtraction, boolean ignoreCase, byte customEscape); byte[] lastSetValueExtractonPattern(); int lastSetValueExtractionCount(); int maxExtractedFields(); static int maxExtractedFields(TrieParser that); static int getLimit(TrieParser that); int getLimit(); boolean isSkipDeepChecks(); void setValue(byte[] source, int offset, int length, int mask, long value); String toString(); StringBuilder toString(StringBuilder builder); void visitPatterns(TrieParserVisitor pv); A toDOT(A builder); int setUTF8Value(CharSequence cs, long value); int setUTF8Value(CharSequence cs, CharSequence suffix, long value); int setUTF8Value(CharSequence prefix, CharSequence cs, CharSequence suffix, long value); void setValue(Pipe p, long value); int longestKnown(); int shortestKnown(); void setMaxBytesCapturable(int value); void setMaxNumericLengthCapturable(int value); void setValue(byte[] bytes, long value); void toDOTFile(File targetFile); static final byte TYPE_RUN; static final byte TYPE_BRANCH_VALUE; static final byte TYPE_ALT_BRANCH; static final byte TYPE_SWITCH_BRANCH; static final byte TYPE_VALUE_NUMERIC; static final byte TYPE_VALUE_BYTES; static final byte TYPE_SAFE_END; static final byte TYPE_END; final byte ESCAPE_BYTE; final byte NO_ESCAPE_SUPPORT; static final byte ESCAPE_CMD_OPTIONAL_SIGNED_INT; static final byte ESCAPE_CMD_SIGNED_INT; static final byte ESCAPE_CMD_UNSIGNED_INT; static final byte ESCAPE_CMD_SIGNED_HEX; static final byte ESCAPE_CMD_UNSIGNED_HEX; static final byte ESCAPE_CMD_DECIMAL; static final byte ESCAPE_CMD_RATIONAL; static final byte ESCAPE_CMD_BYTES; final byte caseRuleMask; }
@Test public void testCharSequenceQuery() { TrieParserReader reader = new TrieParserReader(); TrieParser map = new TrieParser(16); CharSequence test = "hello"; CharSequence test1 = "1234"; map.setUTF8Value("hello", 2); map.setUTF8Value("%b", 3); assertEquals(2, reader.query(map, test)); assertEquals(3, reader.query(map, test1)); }
@Test public void testCharSequenceNumberQuery() { TrieParserReader reader = new TrieParserReader(true); TrieParser map = new TrieParser(16); CharSequence test = "hello"; CharSequence test1 = "1234"; CharSequence test2 = "A1234.123"; CharSequence test3 = "B1234.123D"; map.setUTF8Value("hello", 2); map.setUTF8Value("%i", 3); map.setUTF8Value("A%i.%i", 4); map.setUTF8Value("B%i%.", 5); assertEquals(2, reader.query(map, test)); assertEquals(3, reader.query(map, test1)); assertEquals(1234, reader.capturedLongField(reader, 0)); assertEquals(4, reader.query(map, test2)); assertEquals(1234, reader.capturedLongField(reader, 0)); assertEquals(123, reader.capturedLongField(reader, 1)); assertEquals(5, reader.query(map, test3)); assertEquals(1234, reader.capturedLongField(reader, 0)); assertEquals(123, reader.capturedLongField(reader, 1)); assertEquals(1234, reader.capturedDecimalMField(reader, 0)); assertEquals(0, reader.capturedDecimalEField(reader, 0)); assertEquals(123, reader.capturedDecimalMField(reader, 1)); assertEquals(-3, reader.capturedDecimalEField(reader, 1)); }
@Test public void testNumbersOverTextQuery() { TrieParserReader reader = new TrieParserReader(true); CharSequence test2 = "A1234.123"; TrieParser map2 = new TrieParser(16); map2.setUTF8Value("A%b.123", 2); map2.setUTF8Value("A%i.123", 3); assertEquals(3, reader.query(map2, test2)); TrieParser map1 = new TrieParser(16); map1.setUTF8Value("A%i.123", 3); map1.setUTF8Value("A%b.123", 2); assertEquals(3, reader.query(map1, test2)); }
@Test public void testwriteCapturedValuesToDataOutput() throws IOException { TrieParserReader reader = new TrieParserReader(); TrieParser map = new TrieParser(16); map.setUTF8Value("%b1234", 33); CharSequence test1 = "abcd1234"; reader.query(map, test1); Pipe<RawDataSchema> pipe = RawDataSchema.instance.newPipe(2, 64); pipe.initBuffers(); int size = Pipe.addMsgIdx(pipe, RawDataSchema.MSG_CHUNKEDSTREAM_1); DataOutputBlobWriter x = Pipe.outputStream(pipe); DataOutputBlobWriter.openField(x); int numCapturedBytes = TrieParserReader.writeCapturedValuesToDataOutput(reader, x); x.closeLowLevelField(); Pipe.confirmLowLevelWrite(pipe, size); Pipe.publishWrites(pipe); int msg = Pipe.takeMsgIdx(pipe); assertEquals(RawDataSchema.MSG_CHUNKEDSTREAM_1, msg); DataInputBlobReader y = Pipe.inputStream(pipe); y.openLowLevelAPIField(); StringBuilder str = new StringBuilder(); y.readUTFOfLength(y.available(), str); Pipe.confirmLowLevelRead(pipe, size); Pipe.releaseReadLock(pipe); assertEquals(numCapturedBytes, 4); reader = new TrieParserReader(); map = new TrieParser(16); map.setUTF8Value("%i%.", 33); String test2 = "3.75"; reader.query(map, test2); pipe = RawDataSchema.instance.newPipe(2, 64); pipe.initBuffers(); size = Pipe.addMsgIdx(pipe, RawDataSchema.MSG_CHUNKEDSTREAM_1); x = Pipe.outputStream(pipe); DataOutputBlobWriter.openField(x); numCapturedBytes = TrieParserReader.writeCapturedValuesToDataOutput(reader, x); x.closeLowLevelField(); Pipe.confirmLowLevelWrite(pipe, size); Pipe.publishWrites(pipe); msg = Pipe.takeMsgIdx(pipe); assertEquals(RawDataSchema.MSG_CHUNKEDSTREAM_1, msg); y = Pipe.inputStream(pipe); y.openLowLevelAPIField(); long l1 = y.readPackedLong(); int b1 = y.read(); Pipe.confirmLowLevelRead(pipe, size); Pipe.releaseReadLock(pipe); assertEquals(l1, 375); assertEquals(b1, -2); }
@Test public void testcapturedFieldSetValue() { TrieParserReader reader = new TrieParserReader(); TrieParser map = new TrieParser(16); map.setUTF8Value("12%b1234", 33); StringBuilder x = new StringBuilder(); CharSequence test = "12abcd1234"; reader.query(map, test); TrieParserReader.capturedFieldSetValue(reader, 0, map, 22); long val = reader.query(map, "abcd"); assertEquals(val, 22); }
@Test public void testcapturedFieldQuery() { TrieParserReader reader = new TrieParserReader(); TrieParser map = new TrieParser(16); TrieParser map2 = new TrieParser(16); map.setUTF8Value("%b1234", 33); map2.setUTF8Value("abcd", 12); reader.query(map, "abcd1234"); long val1 = TrieParserReader.capturedFieldQuery(reader, 0, reader, map2); assertEquals(val1, 12); }
@Test public void testwriteCapturedShort() { TrieParserReader reader = new TrieParserReader(); TrieParser map = new TrieParser(16); map.setUTF8Value("12%iabcd", 33); CharSequence test = "128abcd"; reader.query(map, test); Pipe<RawDataSchema> pipe = RawDataSchema.instance.newPipe(2, 64); pipe.initBuffers(); int size = Pipe.addMsgIdx(pipe, RawDataSchema.MSG_CHUNKEDSTREAM_1); DataOutputBlobWriter x = Pipe.outputStream(pipe); DataOutputBlobWriter.openField(x); TrieParserReader.writeCapturedShort(reader, 0, x); x.closeLowLevelField(); Pipe.confirmLowLevelWrite(pipe, size); Pipe.publishWrites(pipe); int msg = Pipe.takeMsgIdx(pipe); assertEquals(RawDataSchema.MSG_CHUNKEDSTREAM_1, msg); DataInputBlobReader y = Pipe.inputStream(pipe); y.openLowLevelAPIField(); byte[] vals = new byte[2]; y.read(vals); assertEquals(vals[1], 8); }
@Test public void testparseSkip() { TrieParserReader reader = new TrieParserReader(); TrieParser map = new TrieParser(16); map.setUTF8Value("12%b123", 33); CharSequence test = "12abcd123"; TrieParserReader.parseSetup(reader, "12abcd123".getBytes(), 0, 9, 8); assertEquals(9, reader.sourceLen); int x = reader.parseSkipOne(); int len = reader.parseSkip(2); long val = reader.query(map, test); assertEquals(x, 49); assertEquals(val, 33); assertEquals(len, 2); reader = new TrieParserReader(); TrieParserReader.parseSetup(reader, "12abcd123".getBytes(), 0, 9, 8); boolean b = TrieParserReader.parseSkipUntil(reader, 51); val = reader.query(map, test); assertTrue(b); }
@Test public void testParseSetUpGrow() { TrieParserReader reader = new TrieParserReader(); TrieParser map = new TrieParser(16); map.setUTF8Value("12%b123", 33); CharSequence test = "12abcd123"; long val = reader.query(map, test); TrieParserReader.parseSetup(reader, "12abcd123".getBytes(), 0, 9, 1023); assertEquals(reader.sourceLen, 9); TrieParserReader.parseSetupGrow(reader, 2); assertEquals(reader.sourceLen, 11); }
@Test public void testsaveloadPositionMemo() { TrieParserReader reader = new TrieParserReader(); TrieParser map = new TrieParser(16); map.setUTF8Value("12%b", 33); CharSequence test = "12abcd"; TrieParserReader.parseSetup(reader, "12%b".getBytes(), 0, 4, 7); long val = TrieParserReader.query(reader, map, test); TrieParserReader.parseSetup(reader, "12%b".getBytes(), 0, 4, 7); int[] target = { 49, 50, 61, 62, 63, 64 }; int value = TrieParserReader.savePositionMemo(reader, target, 0); assertEquals(val, 33); assertEquals(value, 4); CharSequence x = "12abcde"; reader.query(map, x); assertEquals(reader.sourcePos, 14); reader.moveBack(1); assertEquals(reader.sourcePos, 13); TrieParserReader.loadPositionMemo(reader, target, 0); assertEquals(reader.sourcePos, 0); }
@Test public void testwriteCapturedUTF8ToPipe() throws IOException { TrieParserReader reader = new TrieParserReader(); TrieParser map = new TrieParser(16); map.setUTF8Value("%b1234", 33); CharSequence test1 = "abcd1234"; reader.query(map, test1); Pipe<RawDataSchema> pipe = RawDataSchema.instance.newPipe(2, 64); pipe.initBuffers(); int size = Pipe.addMsgIdx(pipe, RawDataSchema.MSG_CHUNKEDSTREAM_1); DataOutputBlobWriter x = Pipe.outputStream(pipe); DataOutputBlobWriter.openField(x); int num = TrieParserReader.writeCapturedUTF8ToPipe(reader, pipe, 0, RawDataSchema.MSG_CHUNKEDSTREAM_1_FIELD_BYTEARRAY_2); x.closeLowLevelField(); Pipe.confirmLowLevelWrite(pipe, size); Pipe.publishWrites(pipe); int msg = Pipe.takeMsgIdx(pipe); assertEquals(RawDataSchema.MSG_CHUNKEDSTREAM_1, msg); DataInputBlobReader y = Pipe.inputStream(pipe); y.openLowLevelAPIField(); StringBuilder str = new StringBuilder(); y.readUTFOfLength(y.available(), str); Pipe.confirmLowLevelRead(pipe, size); Pipe.releaseReadLock(pipe); assertEquals(num, 4); }
@Test public void testQuotesWithExtractions() { TrieParserReader reader = new TrieParserReader(); TrieParser map = new TrieParser(1000); map.setUTF8Value("\"%b\"", 1); map.setUTF8Value("\"%b\\", 2); byte[] testMatch1 = "\"hello\" ".getBytes(); assertEquals(1, TrieParserReader.query(reader, map, testMatch1, 0, testMatch1.length, 7)); byte[] testMatch2 = "\"hello\\ ".getBytes(); assertEquals(2, TrieParserReader.query(reader, map, testMatch2, 0, testMatch2.length, 7)); byte[] testMatch3 = "\"hello ".getBytes(); assertEquals(-1, TrieParserReader.query(reader, map, testMatch3, 0, testMatch3.length, 15)); }
@Test public void testEmptyPatterns() { TrieParserReader reader = new TrieParserReader(true); TrieParser map = new TrieParser(16); map.setUTF8Value("%b:%b:%b:", value2); map.setUTF8Value("%o,%o,%o,", value3); byte[] text3 = "3,,3,".getBytes(); assertEquals(value3, TrieParserReader.query(reader, map, wrapping(text3, 4), 0, text3.length, 15)); assertEquals(3, TrieParserReader.capturedLongField(reader, 0)); assertEquals(0, TrieParserReader.capturedLongField(reader, 1)); assertEquals(3, TrieParserReader.capturedLongField(reader, 2)); }
@Test public void testComplexNumericPattern() { TrieParserReader reader = new TrieParserReader(true); TrieParser map = new TrieParser(16); map.setUTF8Value("%i%.%/%.", value2); byte[] text4 = "5".getBytes(); assertEquals(value2, TrieParserReader.query(reader, map, wrapping(text4, 4), 0, text4.length, 15)); long n1M4 = TrieParserReader.capturedDecimalMField(reader, 0); long n1E4 = TrieParserReader.capturedDecimalEField(reader, 0); long n2M4 = TrieParserReader.capturedDecimalMField(reader, 1); long n2E4 = TrieParserReader.capturedDecimalEField(reader, 1); long d3M4 = TrieParserReader.capturedDecimalMField(reader, 2); long d3E4 = TrieParserReader.capturedDecimalEField(reader, 2); long d4M4 = TrieParserReader.capturedDecimalMField(reader, 3); long d4E4 = TrieParserReader.capturedDecimalEField(reader, 3); assertEquals(5, n1M4); assertEquals(0, n1E4); assertEquals(0, n2M4); assertEquals(-1, n2E4); assertEquals(1, d3M4); assertEquals(0, d3E4); assertEquals(0, d4M4); assertEquals(-1, d4E4); byte[] text3 = "1/3".getBytes(); assertEquals(value2, TrieParserReader.query(reader, map, wrapping(text3, 4), 0, text3.length, 15)); long n1M3 = TrieParserReader.capturedDecimalMField(reader, 0); long n1E3 = TrieParserReader.capturedDecimalEField(reader, 0); long n2M3 = TrieParserReader.capturedDecimalMField(reader, 1); long n2E3 = TrieParserReader.capturedDecimalEField(reader, 1); long d3M3 = TrieParserReader.capturedDecimalMField(reader, 2); long d3E3 = TrieParserReader.capturedDecimalEField(reader, 2); long d4M3 = TrieParserReader.capturedDecimalMField(reader, 3); long d4E3 = TrieParserReader.capturedDecimalEField(reader, 3); assertEquals(1, n1M3); assertEquals(0, n1E3); assertEquals(0, n2M3); assertEquals(-1, n2E3); assertEquals(3, d3M3); assertEquals(0, d3E3); assertEquals(0, d4M3); assertEquals(-1, d4E3); byte[] text2 = "1.2".getBytes(); assertEquals(value2, TrieParserReader.query(reader, map, wrapping(text2, 4), 0, text2.length, 15)); long n1M2 = TrieParserReader.capturedDecimalMField(reader, 0); long n1E2 = TrieParserReader.capturedDecimalEField(reader, 0); long n2M2 = TrieParserReader.capturedDecimalMField(reader, 1); long n2E2 = TrieParserReader.capturedDecimalEField(reader, 1); long d3M2 = TrieParserReader.capturedDecimalMField(reader, 2); long d3E2 = TrieParserReader.capturedDecimalEField(reader, 2); long d4M2 = TrieParserReader.capturedDecimalMField(reader, 3); long d4E2 = TrieParserReader.capturedDecimalEField(reader, 3); assertEquals(1, n1M2); assertEquals(0, n1E2); assertEquals(2, n2M2); assertEquals(-1, n2E2); assertEquals(1, d3M2); assertEquals(0, d3E2); assertEquals(0, d4M2); assertEquals(-1, d4E2); byte[] text1 = "1.2/3.4".getBytes(); assertEquals(value2, TrieParserReader.query(reader, map, wrapping(text1, 4), 0, text1.length, 15)); long n1M1 = TrieParserReader.capturedDecimalMField(reader, 0); long n1E1 = TrieParserReader.capturedDecimalEField(reader, 0); long n2M1 = TrieParserReader.capturedDecimalMField(reader, 1); long n2E1 = TrieParserReader.capturedDecimalEField(reader, 1); long d3M1 = TrieParserReader.capturedDecimalMField(reader, 2); long d3E1 = TrieParserReader.capturedDecimalEField(reader, 2); long d4M1 = TrieParserReader.capturedDecimalMField(reader, 3); long d4E1 = TrieParserReader.capturedDecimalEField(reader, 3); assertEquals(1, n1M1); assertEquals(0, n1E1); assertEquals(2, n2M1); assertEquals(-1, n2E1); assertEquals(3, d3M1); assertEquals(0, d3E1); assertEquals(4, d4M1); assertEquals(-1, d4E1); }
@Test public void testRationalNumericPattern() { TrieParserReader reader = new TrieParserReader(true); TrieParser map = new TrieParser(16); map.setUTF8Value("%i%/", value2); byte[] text4 = "5".getBytes(); assertEquals(value2, TrieParserReader.query(reader, map, wrapping(text4, 4), 0, text4.length, 15)); long nM4 = TrieParserReader.capturedLongField(reader, 0); long dM4 = TrieParserReader.capturedLongField(reader, 1); assertEquals(5, nM4); assertEquals(1, dM4); byte[] text3 = "1/3".getBytes(); assertEquals(value2, TrieParserReader.query(reader, map, wrapping(text3, 4), 0, text3.length, 15)); long nM3 = TrieParserReader.capturedLongField(reader, 0); long dM3 = TrieParserReader.capturedLongField(reader, 1); assertEquals(1, nM3); assertEquals(3, dM3); byte[] text2 = "1.2".getBytes(); assertEquals(value2, TrieParserReader.query(reader, map, wrapping(text2, 4), 0, text2.length, 15)); long nM2 = TrieParserReader.capturedLongField(reader, 0); long dM2 = TrieParserReader.capturedLongField(reader, 1); assertEquals(1, nM2); assertEquals(1, dM2); byte[] text1 = "1.2/3.4".getBytes(); assertEquals(value2, TrieParserReader.query(reader, map, wrapping(text1, 4), 0, text1.length, 15)); long nM1 = TrieParserReader.capturedLongField(reader, 0); long dM1 = TrieParserReader.capturedLongField(reader, 1); assertEquals(1, nM1); assertEquals(1, dM1); }
@Test public void testDecimalNumericPattern() { TrieParserReader reader = new TrieParserReader(true); TrieParser map = new TrieParser(16); map.setUTF8Value("%i%.", value2); byte[] text4 = "5".getBytes(); assertEquals(value2, TrieParserReader.query(reader, map, wrapping(text4, 4), 0, text4.length, 15)); long nM4 = TrieParserReader.capturedDecimalMField(reader, 0); long nE4 = TrieParserReader.capturedDecimalEField(reader, 0); long dM4 = TrieParserReader.capturedDecimalMField(reader, 1); long dE4 = TrieParserReader.capturedDecimalEField(reader, 1); assertEquals(5, nM4); assertEquals(0, nE4); assertEquals(0, dM4); assertEquals(-1, dE4); byte[] text3 = "1/3".getBytes(); assertEquals(value2, TrieParserReader.query(reader, map, wrapping(text3, 4), 0, text3.length, 15)); long nM3 = TrieParserReader.capturedDecimalMField(reader, 0); long nE3 = TrieParserReader.capturedDecimalEField(reader, 0); long dM3 = TrieParserReader.capturedDecimalMField(reader, 1); long dE3 = TrieParserReader.capturedDecimalEField(reader, 1); assertEquals(1, nM3); assertEquals(0, nE3); assertEquals(0, dM3); assertEquals(-1, dE3); byte[] text2 = "1.2".getBytes(); assertEquals(value2, TrieParserReader.query(reader, map, wrapping(text2, 4), 0, text2.length, 15)); long nM2 = TrieParserReader.capturedDecimalMField(reader, 0); long nE2 = TrieParserReader.capturedDecimalEField(reader, 0); long dM2 = TrieParserReader.capturedDecimalMField(reader, 1); long dE2 = TrieParserReader.capturedDecimalEField(reader, 1); assertEquals(1, nM2); assertEquals(0, nE2); assertEquals(2, dM2); assertEquals(-1, dE2); byte[] text1 = "1.2/3.4".getBytes(); assertEquals(value2, TrieParserReader.query(reader, map, wrapping(text1, 4), 0, text1.length, 15)); long nM1 = TrieParserReader.capturedDecimalMField(reader, 0); long nE1 = TrieParserReader.capturedDecimalEField(reader, 0); long dM1 = TrieParserReader.capturedDecimalMField(reader, 1); long dE1 = TrieParserReader.capturedDecimalEField(reader, 1); assertEquals(1, nM1); assertEquals(0, nE1); assertEquals(2, dM1); assertEquals(-1, dE1); }
@Test public void testCustomEscapeChar() { TrieParser parser = new TrieParser(1000, 1, true, true, false, (byte) '"'); TrieParserReader reader = new TrieParserReader(true); parser.setUTF8Value("#{\"b}", TrieParser.ESCAPE_CMD_SIGNED_INT); parser.setUTF8Value("#\"b/", TrieParser.ESCAPE_CMD_SIGNED_INT); parser.setUTF8Value("#\"b?", TrieParser.ESCAPE_CMD_SIGNED_INT); parser.setUTF8Value("#\"b&", TrieParser.ESCAPE_CMD_SIGNED_INT); parser.setUTF8Value("#\"b", TrieParser.ESCAPE_CMD_SIGNED_INT); parser.setUTF8Value("^{\"b}", TrieParser.ESCAPE_CMD_DECIMAL); parser.setUTF8Value("^\"b/", TrieParser.ESCAPE_CMD_DECIMAL); parser.setUTF8Value("^\"b?", TrieParser.ESCAPE_CMD_DECIMAL); parser.setUTF8Value("^\"b&", TrieParser.ESCAPE_CMD_DECIMAL); parser.setUTF8Value("^\"b", TrieParser.ESCAPE_CMD_DECIMAL); parser.setUTF8Value("${\"b}", TrieParser.ESCAPE_CMD_BYTES); parser.setUTF8Value("$\"b?", TrieParser.ESCAPE_CMD_BYTES); parser.setUTF8Value("$\"b", TrieParser.ESCAPE_CMD_BYTES); parser.setUTF8Value("$\"b&", TrieParser.ESCAPE_CMD_BYTES); parser.setUTF8Value("$\"b/", TrieParser.ESCAPE_CMD_BYTES); parser.setUTF8Value("%{\"b}", TrieParser.ESCAPE_CMD_RATIONAL); parser.setUTF8Value("%\"b/", TrieParser.ESCAPE_CMD_RATIONAL); parser.setUTF8Value("%\"b?", TrieParser.ESCAPE_CMD_RATIONAL); parser.setUTF8Value("%\"b&", TrieParser.ESCAPE_CMD_RATIONAL); parser.setUTF8Value("%\"b", TrieParser.ESCAPE_CMD_RATIONAL); findShortText(parser, reader, "%hello?", TrieParser.ESCAPE_CMD_RATIONAL); findShortText(parser, reader, "%hello/", TrieParser.ESCAPE_CMD_RATIONAL); findShortText(parser, reader, "%{hello}", TrieParser.ESCAPE_CMD_RATIONAL); findShortText(parser, reader, "%hello&", TrieParser.ESCAPE_CMD_RATIONAL); findShortText(parser, reader, "%hello", TrieParser.ESCAPE_CMD_RATIONAL); findShortText(parser, reader, "$hello?", TrieParser.ESCAPE_CMD_BYTES); findShortText(parser, reader, "$hello/", TrieParser.ESCAPE_CMD_BYTES); findShortText(parser, reader, "${hello}", TrieParser.ESCAPE_CMD_BYTES); findShortText(parser, reader, "$hello&", TrieParser.ESCAPE_CMD_BYTES); findShortText(parser, reader, "$hello", TrieParser.ESCAPE_CMD_BYTES); findShortText(parser, reader, "#hello?", TrieParser.ESCAPE_CMD_SIGNED_INT); findShortText(parser, reader, "#hello/", TrieParser.ESCAPE_CMD_SIGNED_INT); findShortText(parser, reader, "#{hello}", TrieParser.ESCAPE_CMD_SIGNED_INT); findShortText(parser, reader, "#hello&", TrieParser.ESCAPE_CMD_SIGNED_INT); findShortText(parser, reader, "#hello", TrieParser.ESCAPE_CMD_SIGNED_INT); findShortText(parser, reader, "^hello?", TrieParser.ESCAPE_CMD_DECIMAL); findShortText(parser, reader, "^hello/", TrieParser.ESCAPE_CMD_DECIMAL); findShortText(parser, reader, "^{hello}", TrieParser.ESCAPE_CMD_DECIMAL); findShortText(parser, reader, "^hello&", TrieParser.ESCAPE_CMD_DECIMAL); findShortText(parser, reader, "^hello", TrieParser.ESCAPE_CMD_DECIMAL); }
@Test public void testRoute() { TrieParser map = new TrieParser(512,2,false ,true, true); map.setUTF8Value("%b ",67108863); map.setUTF8Value("/plaintext ",0); map.setUTF8Value("/json ",1); map.setUTF8Value("/db ",2); map.setUTF8Value("/queries?queries=%i ",3); map.setUTF8Value("/queries ",4); map.setUTF8Value("/queries?queries=%b ",5); map.setUTF8Value("/updates?queries=%i ",6); map.setUTF8Value("/updates ",7); map.setUTF8Value("/updates?queries=%b ",8); map.setUTF8Value("/fortunes ",9); TrieParserReader reader = new TrieParserReader(); byte[] text1 = "/json ".getBytes(); assertEquals(1, TrieParserReader.query(reader, map, wrapping(text1, 5), 0, text1.length, 31)); }