当前位置: 首页>>代码示例>>Java>>正文


Java Slice.getInput方法代码示例

本文整理汇总了Java中io.airlift.slice.Slice.getInput方法的典型用法代码示例。如果您正苦于以下问题:Java Slice.getInput方法的具体用法?Java Slice.getInput怎么用?Java Slice.getInput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.airlift.slice.Slice的用法示例。


在下文中一共展示了Slice.getInput方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: NumericHistogram

import io.airlift.slice.Slice; //导入方法依赖的package包/类
public NumericHistogram(Slice serialized, int buffer)
{
    requireNonNull(serialized, "serialized is null");
    checkArgument(buffer >= 1, "buffer must be >= 1");

    SliceInput input = serialized.getInput();

    checkArgument(input.readByte() == FORMAT_TAG, "Unsupported format tag");

    maxBuckets = input.readInt();
    nextIndex = input.readInt();
    values = new double[maxBuckets + buffer];
    weights = new double[maxBuckets + buffer];

    input.readBytes(Slices.wrappedDoubleArray(values), nextIndex * SizeOf.SIZE_OF_DOUBLE);
    input.readBytes(Slices.wrappedDoubleArray(weights), nextIndex * SizeOf.SIZE_OF_DOUBLE);
}
 
开发者ID:y-lan,项目名称:presto,代码行数:18,代码来源:NumericHistogram.java

示例2: deserialize

import io.airlift.slice.Slice; //导入方法依赖的package包/类
public static StringClassifierAdapter deserialize(byte[] data)
{
    Slice slice = Slices.wrappedBuffer(data);
    BasicSliceInput input = slice.getInput();
    int classifierLength = input.readInt();

    Model classifier = ModelUtils.deserialize(input.readSlice(classifierLength));
    int numEnumerations = input.readInt();

    ImmutableMap.Builder<Integer, String> builder = ImmutableMap.builder();

    for (int i = 0; i < numEnumerations; i++) {
        int key = input.readInt();
        int valueLength = input.readInt();
        String value = input.readSlice(valueLength).toStringUtf8();
        builder.put(key, value);
    }

    return new StringClassifierAdapter(checkType(classifier, Classifier.class, "classifier"), builder.build());
}
 
开发者ID:y-lan,项目名称:presto,代码行数:21,代码来源:StringClassifierAdapter.java

示例3: advance

import io.airlift.slice.Slice; //导入方法依赖的package包/类
private void advance()
        throws IOException
{
    if (compressedSliceInput == null || compressedSliceInput.remaining() == 0) {
        current = null;
        return;
    }

    // 3 byte header
    // NOTE: this must match BLOCK_HEADER_SIZE
    currentCompressedBlockOffset = Ints.checkedCast(compressedSliceInput.position());
    int b0 = compressedSliceInput.readUnsignedByte();
    int b1 = compressedSliceInput.readUnsignedByte();
    int b2 = compressedSliceInput.readUnsignedByte();

    boolean isUncompressed = (b0 & 0x01) == 1;
    int chunkLength = (b2 << 15) | (b1 << 7) | (b0 >>> 1);

    Slice chunk = compressedSliceInput.readSlice(chunkLength);

    if (isUncompressed) {
        current = chunk.getInput();
    }
    else {
        int uncompressedSize;
        if (compressionKind == ZLIB) {
            uncompressedSize = decompressZip(chunk);
        }
        else {
            uncompressedSize = decompressSnappy(chunk);
        }

        current = Slices.wrappedBuffer(buffer, 0, uncompressedSize).getInput();
    }
}
 
开发者ID:y-lan,项目名称:presto,代码行数:36,代码来源:OrcInputStream.java

示例4: OrcReader

import io.airlift.slice.Slice; //导入方法依赖的package包/类
public OrcReader(OrcDataSource orcDataSource, MetadataReader metadataReader, DataSize maxMergeDistance, DataSize maxReadSize)
        throws IOException
{
    orcDataSource = wrapWithCacheIfTiny(requireNonNull(orcDataSource, "orcDataSource is null"), maxMergeDistance);
    this.orcDataSource = orcDataSource;
    this.metadataReader = requireNonNull(metadataReader, "metadataReader is null");
    this.maxMergeDistance = requireNonNull(maxMergeDistance, "maxMergeDistance is null");
    this.maxReadSize = requireNonNull(maxReadSize, "maxReadSize is null");

    //
    // Read the file tail:
    //
    // variable: Footer
    // variable: Metadata
    // variable: PostScript - contains length of footer and metadata
    // 3 bytes: file magic "ORC"
    // 1 byte: postScriptSize = PostScript + Magic

    // figure out the size of the file using the option or filesystem
    long size = orcDataSource.getSize();
    if (size <= 0) {
        throw new OrcCorruptionException("Malformed ORC file %s. Invalid file size %s", orcDataSource, size);
    }

    // Read the tail of the file
    byte[] buffer = new byte[Ints.checkedCast(min(size, EXPECTED_FOOTER_SIZE))];
    orcDataSource.readFully(size - buffer.length, buffer);

    // get length of PostScript - last byte of the file
    int postScriptSize = buffer[buffer.length - SIZE_OF_BYTE] & 0xff;

    // make sure this is an ORC file and not an RCFile or something else
    verifyOrcFooter(orcDataSource, postScriptSize, buffer);

    // decode the post script
    int postScriptOffset = buffer.length - SIZE_OF_BYTE - postScriptSize;
    PostScript postScript = metadataReader.readPostScript(buffer, postScriptOffset, postScriptSize);

    // verify this is a supported version
    checkOrcVersion(orcDataSource, postScript.getVersion());

    // check compression codec is supported
    this.compressionKind = postScript.getCompression();

    this.bufferSize = Ints.checkedCast(postScript.getCompressionBlockSize());

    int footerSize = Ints.checkedCast(postScript.getFooterLength());
    int metadataSize = Ints.checkedCast(postScript.getMetadataLength());

    // check if extra bytes need to be read
    Slice completeFooterSlice;
    int completeFooterSize = footerSize + metadataSize + postScriptSize + SIZE_OF_BYTE;
    if (completeFooterSize > buffer.length) {
        // allocate a new buffer large enough for the complete footer
        byte[] newBuffer = new byte[completeFooterSize];
        completeFooterSlice = Slices.wrappedBuffer(newBuffer);

        // initial read was not large enough, so read missing section
        orcDataSource.readFully(size - completeFooterSize, newBuffer, 0, completeFooterSize - buffer.length);

        // copy already read bytes into the new buffer
        completeFooterSlice.setBytes(completeFooterSize - buffer.length, buffer);
    }
    else {
        // footer is already in the bytes in buffer, just adjust position, length
        completeFooterSlice = Slices.wrappedBuffer(buffer, buffer.length - completeFooterSize, completeFooterSize);
    }

    // read metadata
    Slice metadataSlice = completeFooterSlice.slice(0, metadataSize);
    try (InputStream metadataInputStream = new OrcInputStream(orcDataSource.toString(), metadataSlice.getInput(), compressionKind, bufferSize, new AggregatedMemoryContext())) {
        this.metadata = metadataReader.readMetadata(metadataInputStream);
    }

    // read footer
    Slice footerSlice = completeFooterSlice.slice(metadataSize, footerSize);
    try (InputStream footerInputStream = new OrcInputStream(orcDataSource.toString(), footerSlice.getInput(), compressionKind, bufferSize, new AggregatedMemoryContext())) {
        this.footer = metadataReader.readFooter(footerInputStream);
    }
}
 
开发者ID:y-lan,项目名称:presto,代码行数:81,代码来源:OrcReader.java


注:本文中的io.airlift.slice.Slice.getInput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。