use of com.questdb.std.str.DirectByteCharSequence in project questdb by bluestreak01.
the class CsvTest method testHeaders.
@Test
public void testHeaders() throws Exception {
final List<String> names = new ArrayList<>();
final List<String> expected = new ArrayList<String>() {
{
add("type");
add("value");
add("active");
add("desc");
add("grp");
}
};
ImportManager.parse(new File(this.getClass().getResource("/csv/test-headers.csv").getFile()), new PlainTextLexer(env).of(','), 1024 * 1024, true, new PlainTextParser() {
@Override
public void onError(int line) {
}
@Override
public void onFieldCount(int count) {
}
@Override
public void onFields(int line, ObjList<DirectByteCharSequence> values, int hi) {
}
@Override
public void onHeader(ObjList<DirectByteCharSequence> values, int hi) {
for (int i = 0; i < hi; i++) {
names.add(values.getQuick(i).toString());
}
}
@Override
public void onLineCount(int count) {
}
});
TestUtils.assertEquals(expected.iterator(), names.iterator());
}
use of com.questdb.std.str.DirectByteCharSequence in project questdb by bluestreak01.
the class Lexer2Test method testUnicode.
@Test
@Ignore
public void testUnicode() throws Exception {
Lexer2 lex = new Lexer2();
lex.defineSymbol("+");
lex.defineSymbol("++");
lex.defineSymbol("*");
String s = "'авг'";
byte[] bb = s.getBytes("UTF8");
System.out.println(new String(bb));
long mem = Unsafe.malloc(bb.length);
for (int i = 0; i < bb.length; i++) {
Unsafe.getUnsafe().putByte(mem + i, bb[i]);
}
DirectByteCharSequence cs = new DirectByteCharSequence();
cs.of(mem, mem + bb.length);
lex.setContent(cs);
StringSink sink = new StringSink();
while (lex.hasNext()) {
sink.put(lex.optionTok());
}
TestUtils.assertEquals("a+'b'*abc", sink);
}
use of com.questdb.std.str.DirectByteCharSequence in project questdb by bluestreak01.
the class LexerTest method testUnicode.
@Test
@Ignore
public void testUnicode() throws Exception {
Lexer lex = new Lexer();
lex.defineSymbol("+");
lex.defineSymbol("++");
lex.defineSymbol("*");
String s = "'авг'";
byte[] bb = s.getBytes("UTF8");
System.out.println(new String(bb));
long mem = Unsafe.malloc(bb.length);
for (int i = 0; i < bb.length; i++) {
Unsafe.getUnsafe().putByte(mem + i, bb[i]);
}
DirectByteCharSequence cs = new DirectByteCharSequence();
cs.of(mem, mem + bb.length);
lex.setContent(cs);
StringSink sink = new StringSink();
while (lex.hasNext()) {
sink.put(lex.optionTok());
}
TestUtils.assertEquals("a+'b'*abc", sink);
}
use of com.questdb.std.str.DirectByteCharSequence in project questdb by bluestreak01.
the class RequestHeaderBuffer method write.
public long write(long ptr, int len, boolean _method) throws HeadersTooLargeException, MalformedHeaderException {
if (_method && needMethod) {
int l = parseMethod(ptr, len);
len -= l;
ptr += l;
}
long p = ptr;
long hi = p + len;
DirectByteCharSequence v;
while (p < hi) {
if (_wptr == this.hi) {
throw HeadersTooLargeException.INSTANCE;
}
char b = (char) Unsafe.getUnsafe().getByte(p++);
if (b == '\r') {
continue;
}
Unsafe.getUnsafe().putByte(_wptr++, (byte) b);
switch(b) {
case ':':
if (n == null) {
n = pool.next().of(_lo, _wptr - 1);
_lo = _wptr + 1;
}
break;
case '\n':
if (n == null) {
incomplete = false;
parseKnownHeaders();
return p;
}
v = pool.next().of(_lo, _wptr - 1);
_lo = _wptr;
headers.put(n, v);
n = null;
break;
default:
break;
}
}
return p;
}
use of com.questdb.std.str.DirectByteCharSequence in project questdb by bluestreak01.
the class PlainTextLexer method stashField.
private void stashField() {
if (calcFields) {
calcField();
}
if (fieldIndex >= fields.size()) {
plainTextParser.onError(lineCount++);
ignoreEolOnce = true;
fieldIndex = 0;
return;
}
DirectByteCharSequence seq = fields.getQuick(fieldIndex);
if (lastQuotePos > -1) {
seq.of(this.fieldLo, lastQuotePos - 1);
lastQuotePos = -1;
} else {
seq.of(this.fieldLo, this.fieldHi - 1);
}
this.fieldLo = this.fieldHi;
}
Aggregations