use of org.apache.hyracks.data.std.primitive.ByteArrayPointable in project asterixdb by apache.
the class ByteArrayNormalizedKeyComputerFactoryTest method testRandomNormalizedKey.
@Test
public void testRandomNormalizedKey() {
for (int i = 0; i < 10; ++i) {
ByteArrayPointable pointable1 = generateRandomByteArrayPointableWithFixLength(Math.abs(random.nextInt((i + 1) * 10)), random);
ByteArrayPointable pointable2 = generateRandomByteArrayPointableWithFixLength(Math.abs(random.nextInt((i + 1) * 10)), random);
assertNormalizeValue(pointable1, pointable2, computer);
}
}
use of org.apache.hyracks.data.std.primitive.ByteArrayPointable in project asterixdb by apache.
the class ByteArrayBase64ParserFactoryTest method testOneString.
void testOneString(String test) throws HyracksDataException {
IValueParser parser = ByteArrayBase64ParserFactory.INSTANCE.createValueParser();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream outputStream = new DataOutputStream(bos);
ByteArrayPointable bytePtr = new ByteArrayPointable();
parser.parse(test.toCharArray(), 0, test.length(), outputStream);
bytePtr.set(bos.toByteArray(), 0, bos.size());
byte[] answer = DatatypeConverter.parseBase64Binary(test);
assertTrue(bytePtr.getContentLength() == answer.length);
assertTrue(Arrays.equals(answer, copyContent(bytePtr)));
}
use of org.apache.hyracks.data.std.primitive.ByteArrayPointable in project asterixdb by apache.
the class ByteArrayNormalizedKeyComputerFactoryTest method testCornerCase.
@Test
public void testCornerCase() {
for (int len = 0; len < 4; ++len) {
ByteArrayPointable pointable1 = generateRandomByteArrayPointableWithFixLength(len, random);
ByteArrayPointable pointable2 = generateRandomByteArrayPointableWithFixLength(len, random);
assertNormalizeValue(pointable1, pointable2, computer);
}
ByteArrayPointable ptr1 = ByteArrayPointable.generatePointableFromPureBytes(new byte[] { 0, 25, 34, 42 });
ByteArrayPointable ptr2 = ByteArrayPointable.generatePointableFromPureBytes(new byte[] { (byte) 130, 25, 34, 42 });
int n1 = computer.normalize(ptr1.getByteArray(), ptr1.getStartOffset(), ptr1.getLength());
int n2 = computer.normalize(ptr2.getByteArray(), ptr2.getStartOffset(), ptr2.getLength());
assertTrue(n1 < n2);
}
use of org.apache.hyracks.data.std.primitive.ByteArrayPointable in project asterixdb by apache.
the class ByteArrayHexParserFactoryTest method testOneString.
void testOneString(String test) throws HyracksDataException {
IValueParser parser = ByteArrayHexParserFactory.INSTANCE.createValueParser();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream outputStream = new DataOutputStream(bos);
ByteArrayPointable bytePtr = new ByteArrayPointable();
parser.parse(test.toCharArray(), 0, test.length(), outputStream);
bytePtr.set(bos.toByteArray(), 0, bos.size());
assertTrue(bytePtr.getContentLength() == test.length() / 2);
assertEquals(DatatypeConverter.printHexBinary(ByteArrayPointable.copyContent(bytePtr)).toLowerCase(), test.toLowerCase());
}
use of org.apache.hyracks.data.std.primitive.ByteArrayPointable in project asterixdb by apache.
the class ABinaryPrinterTest method generateABinaryBytesByStringContent.
public static byte[] generateABinaryBytesByStringContent(String content) {
byte[] bytes = DatatypeConverter.parseHexBinary(content);
ByteArrayPointable ptr = ByteArrayPointable.generatePointableFromPureBytes(bytes);
byte[] ret = new byte[ptr.getLength() + 1];
System.arraycopy(ptr.getByteArray(), ptr.getStartOffset(), ret, 1, ptr.getLength());
return ret;
}
Aggregations