public static Slice serialize(OGCGeometry input) { requireNonNull(input, "input is null"); DynamicSliceOutput output = new DynamicSliceOutput(100); writeGeometry(output, input); return output.slice(); }
/** * Serialize JTS {@link Geometry} shape into an ESRI shape */ public static Slice serialize(Geometry geometry) { requireNonNull(geometry, "input is null"); DynamicSliceOutput output = new DynamicSliceOutput(100); writeGeometry(geometry, output); return output.slice(); }
public Slice writePostscript(int footerLength, int metadataLength, CompressionKind compression, int compressionBlockSize) throws IOException { // postscript is not compressed DynamicSliceOutput output = new DynamicSliceOutput(64); metadataWriter.writePostscript(output, footerLength, metadataLength, compression, compressionBlockSize); return output.slice(); }
@Override public final void encodeValueInto(Block block, int position, SliceOutput output) { buffer.reset(); encodeValue(block, position, buffer); // structural types nested in structural types are length prefixed Slice slice = buffer.slice(); output.writeInt(Integer.reverseBytes(slice.length())); output.writeBytes(slice); }
private Slice getSliceOutput() { buffer.close(); DynamicSliceOutput output = new DynamicSliceOutput(toIntExact(buffer.getOutputDataSize())); buffer.writeDataTo(output); Slice slice = output.slice(); buffer.reset(); return slice; } }
@Setup public void setup() { int[] codePointSet = ascii ? ASCII_CODE_POINTS : ALL_CODE_POINTS; ThreadLocalRandom random = ThreadLocalRandom.current(); codePoints = new int[length]; DynamicSliceOutput sliceOutput = new DynamicSliceOutput(length * 4); for (int i = 0; i < codePoints.length; i++) { int codePoint = codePointSet[random.nextInt(codePointSet.length)]; codePoints[i] = codePoint; sliceOutput.appendBytes(new String(Character.toChars(codePoint)).getBytes(StandardCharsets.UTF_8)); } slice = sliceOutput.slice(); }
protected static Slice createExpectedValue(int length) { DynamicSliceOutput dynamicSliceOutput = new DynamicSliceOutput(16); for (int index = 0; index < length; index++) { dynamicSliceOutput.writeByte(length * (index + 1)); } return dynamicSliceOutput.slice(); }
private static Slice createExpectedValue(int length) { DynamicSliceOutput dynamicSliceOutput = new DynamicSliceOutput(16); for (int index = 0; index < length; index++) { dynamicSliceOutput.writeByte(length * (index + 1)); } return dynamicSliceOutput.slice(); } }
private static Slice createExpectedValue(int length) { DynamicSliceOutput dynamicSliceOutput = new DynamicSliceOutput(16); for (int index = 0; index < length; index++) { dynamicSliceOutput.writeByte(length * (index + 1)); } return dynamicSliceOutput.slice(); }
@Override public Slice extract(JsonParser jsonParser) throws IOException { if (!jsonParser.hasCurrentToken()) { throw new JsonParseException(jsonParser, "Unexpected end of value"); } DynamicSliceOutput dynamicSliceOutput = new DynamicSliceOutput(ESTIMATED_JSON_OUTPUT_SIZE); try (JsonGenerator jsonGenerator = createJsonGenerator(JSON_FACTORY, dynamicSliceOutput)) { jsonGenerator.copyCurrentStructure(jsonParser); } return dynamicSliceOutput.slice(); } }
private static Slice createGreaterValue(Slice expectedValue, int offset, int length) { DynamicSliceOutput greaterOutput = new DynamicSliceOutput(length + 1); greaterOutput.writeBytes(expectedValue, offset, length); greaterOutput.writeByte('_'); return greaterOutput.slice(); }
private static Block createVariableWidthBlock(int entries) { int[] offsets = new int[entries + 1]; DynamicSliceOutput dynamicSliceOutput = new DynamicSliceOutput(entries); for (int i = 0; i < entries; i++) { dynamicSliceOutput.writeByte(i); offsets[i + 1] = dynamicSliceOutput.size(); } return new VariableWidthBlock(entries, dynamicSliceOutput.slice(), offsets, Optional.empty()); } }
@Test public void testRoundTrip() { DynamicSliceOutput sliceOutput = new DynamicSliceOutput(1024); writeType(sliceOutput, BOOLEAN); Type actualType = readType(new TestingTypeManager(), sliceOutput.slice().getInput()); assertEquals(actualType, BOOLEAN); } }
@Test public void testWriteHugeByteChucks() { int size = 1024 * 1024; byte[] largeByteArray = new byte[size]; Arrays.fill(largeByteArray, (byte) 0xA); OrcOutputBuffer sliceOutput = new OrcOutputBuffer(CompressionKind.NONE, 256 * 1024); DynamicSliceOutput output = new DynamicSliceOutput(size); sliceOutput.writeBytes(largeByteArray, 10, size - 10); assertEquals(sliceOutput.writeDataTo(output), size - 10); assertEquals(output.slice(), wrappedBuffer(largeByteArray, 10, size - 10)); sliceOutput.reset(); output.reset(); sliceOutput.writeBytes(wrappedBuffer(largeByteArray), 100, size - 100); assertEquals(sliceOutput.writeDataTo(output), size - 100); assertEquals(output.slice(), wrappedBuffer(largeByteArray, 100, size - 100)); }
private static Block copyBlock(Block block) { DynamicSliceOutput sliceOutput = new DynamicSliceOutput(1024); BLOCK_ENCODING_SERDE.writeBlock(sliceOutput, block); return BLOCK_ENCODING_SERDE.readBlock(sliceOutput.slice().getInput()); }
private static Block copyBlockViaBlockSerde(Block block) { DynamicSliceOutput sliceOutput = new DynamicSliceOutput(1024); BLOCK_ENCODING_SERDE.writeBlock(sliceOutput, block); return BLOCK_ENCODING_SERDE.readBlock(sliceOutput.slice().getInput()); }
public static Slice serialize(Envelope envelope) { requireNonNull(envelope, "envelope is null"); verify(!envelope.isEmpty()); DynamicSliceOutput output = new DynamicSliceOutput(100); output.appendByte(GeometrySerializationType.ENVELOPE.code()); output.appendDouble(envelope.getXMin()); output.appendDouble(envelope.getYMin()); output.appendDouble(envelope.getXMax()); output.appendDouble(envelope.getYMax()); return output.slice(); }
private static int serializedSize(List<? extends Type> types, Page expectedPage) { PagesSerde serde = new TestingPagesSerdeFactory().createPagesSerde(); DynamicSliceOutput sliceOutput = new DynamicSliceOutput(1024); writePages(serde, sliceOutput, expectedPage); Slice slice = sliceOutput.slice(); Iterator<Page> pageIterator = readPages(serde, slice.getInput()); if (pageIterator.hasNext()) { assertPageEquals(types, pageIterator.next(), expectedPage); } else { assertEquals(expectedPage.getPositionCount(), 0); } assertFalse(pageIterator.hasNext()); return slice.length(); } }
@Test public void testRoundTrip() { BlockBuilder expectedBlockBuilder = VARCHAR.createBlockBuilder(null, 4); VARCHAR.writeString(expectedBlockBuilder, "alice"); VARCHAR.writeString(expectedBlockBuilder, "bob"); VARCHAR.writeString(expectedBlockBuilder, "charlie"); VARCHAR.writeString(expectedBlockBuilder, "dave"); Block expectedBlock = expectedBlockBuilder.build(); DynamicSliceOutput sliceOutput = new DynamicSliceOutput(1024); blockEncodingSerde.writeBlock(sliceOutput, expectedBlock); Block actualBlock = blockEncodingSerde.readBlock(sliceOutput.slice().getInput()); assertBlockEquals(VARCHAR, actualBlock, expectedBlock); }
@Test public void testStackRepresentation() { Block actualBlock = arrayBlockOf(new ArrayType(BIGINT), arrayBlockOf(BIGINT, 1L, 2L), arrayBlockOf(BIGINT, 3L)); DynamicSliceOutput actualSliceOutput = new DynamicSliceOutput(100); writeBlock(functionAssertions.getMetadata().getBlockEncodingSerde(), actualSliceOutput, actualBlock); Block expectedBlock = new ArrayType(BIGINT) .createBlockBuilder(null, 3) .appendStructure(BIGINT.createBlockBuilder(null, 2).writeLong(1).closeEntry().writeLong(2).closeEntry().build()) .appendStructure(BIGINT.createBlockBuilder(null, 1).writeLong(3).closeEntry().build()) .build(); DynamicSliceOutput expectedSliceOutput = new DynamicSliceOutput(100); writeBlock(functionAssertions.getMetadata().getBlockEncodingSerde(), expectedSliceOutput, expectedBlock); assertEquals(actualSliceOutput.slice(), expectedSliceOutput.slice()); }