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


Java BytesUtil类代码示例

本文整理汇总了Java中org.apache.kylin.common.util.BytesUtil的典型用法代码示例。如果您正苦于以下问题:Java BytesUtil类的具体用法?Java BytesUtil怎么用?Java BytesUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BytesUtil类属于org.apache.kylin.common.util包,在下文中一共展示了BytesUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readDimensionEncoding

import org.apache.kylin.common.util.BytesUtil; //导入依赖的package包/类
private static DimensionEncoding readDimensionEncoding(ByteBuffer in) {
    try {
        int isNull = BytesUtil.readVInt(in);
        if (isNull == 1) {
            return null;
        }

        byte[] bytes = BytesUtil.readByteArray(in);
        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(bais);
        DimensionEncoding ret = (DimensionEncoding) ois.readObject();
        return ret;
    } catch (IOException | ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:apache,项目名称:kylin,代码行数:17,代码来源:TrimmedCubeCodeSystem.java

示例2: peekLength

import org.apache.kylin.common.util.BytesUtil; //导入依赖的package包/类
public int peekLength(ByteBuffer in) {
    int mark = in.position();
    int len;

    byte scheme = in.get();
    if (scheme == 0) { // map scheme
        int size = BytesUtil.readVInt(in);
        int indexLen = getRegisterIndexSize();
        len = in.position() - mark + (indexLen + 1) * size;
    } else {
        len = in.position() - mark + m;
    }

    in.position(mark);
    return len;
}
 
开发者ID:apache,项目名称:kylin,代码行数:17,代码来源:HLLCounterOld.java

示例3: peekLength

import org.apache.kylin.common.util.BytesUtil; //导入依赖的package包/类
@Override
public int peekLength(ByteBuffer in) {
    int mark = in.position();
    int len = 0;
    if (in.hasRemaining()) {
        int size = BytesUtil.readVInt(in);
        len = in.position() - mark;
        for (int i = 0; i < size; i++) {
            int length = BytesUtil.peekByteArrayLength(in);
            in.position(in.position() + length);
            len += length;
        }
    }
    in.position(mark);
    return len;
}
 
开发者ID:apache,项目名称:kylin,代码行数:17,代码来源:RawSerializer.java

示例4: deserialize

import org.apache.kylin.common.util.BytesUtil; //导入依赖的package包/类
@Override
public List<ByteArray> deserialize(ByteBuffer in) {
    List<ByteArray> values = new ArrayList<>();
    int size = BytesUtil.readVInt(in);
    if (size >= 0) {
        for (int i = 0; i < size; i++) {
            ByteArray ba = new ByteArray(BytesUtil.readByteArray(in));
            if (ba.length() != 0) {
                values.add(ba);
            }
        }
    } else {
        throw new RuntimeException("Read error data size:" + size);
    }
    return values;
}
 
开发者ID:apache,项目名称:kylin,代码行数:17,代码来源:RawSerializer.java

示例5: getRowKeysDifferentShards

import org.apache.kylin.common.util.BytesUtil; //导入依赖的package包/类
private List<byte[]> getRowKeysDifferentShards(byte[] halfCookedKey) {
    final short cuboidShardNum = cubeSeg.getCuboidShardNum(cuboid.getId());

    if (!cubeSeg.isEnableSharding()) {
        return Lists.newArrayList(halfCookedKey);//not shard to append at head, so it is already well cooked
    } else {
        List<byte[]> ret = Lists.newArrayList();
        for (short i = 0; i < cuboidShardNum; ++i) {
            short shard = ShardingHash.normalize(cubeSeg.getCuboidBaseShard(cuboid.getId()), i, cubeSeg.getTotalShards(cuboid.getId()));
            byte[] cookedKey = Arrays.copyOf(halfCookedKey, halfCookedKey.length);
            BytesUtil.writeShort(shard, cookedKey, 0, RowConstants.ROWKEY_SHARDID_LEN);
            ret.add(cookedKey);
        }
        return ret;
    }
}
 
开发者ID:apache,项目名称:kylin,代码行数:17,代码来源:CubeHBaseScanRPC.java

示例6: serialize

import org.apache.kylin.common.util.BytesUtil; //导入依赖的package包/类
@Override
public void serialize(BigDecimal value, ByteBuffer out) {
    if (value.scale() > type.getScale()) {
        if (avoidVerbose++ % 10000 == 0) {
            logger.warn("value's scale has exceeded the " + type.getScale() + ", cut it off, to ensure encoded value do not exceed maxLength " + maxLength + " times:" + (avoidVerbose));
        }
        value = value.setScale(type.getScale(), BigDecimal.ROUND_HALF_EVEN);
    }
    byte[] bytes = value.unscaledValue().toByteArray();
    if (bytes.length + 2 > maxLength) {
        throw new IllegalArgumentException("'" + value + "' exceeds the expected length for type " + type);
    }

    BytesUtil.writeVInt(value.scale(), out);
    BytesUtil.writeVInt(bytes.length, out);
    out.put(bytes);
}
 
开发者ID:apache,项目名称:kylin,代码行数:18,代码来源:BigDecimalSerializer.java

示例7: deserialize

import org.apache.kylin.common.util.BytesUtil; //导入依赖的package包/类
@Override
public CoprocessorRowType deserialize(ByteBuffer in) {
    int n = BytesUtil.readVInt(in);
    int bodyOffset = BytesUtil.readVInt(in);
    TblColRef[] cols = new TblColRef[n];
    int[] colSizes = new int[n];
    for (int i = 0; i < n; i++) {
        String tableName = BytesUtil.readAsciiString(in);
        String colName = BytesUtil.readAsciiString(in);
        String datatype = BytesUtil.readAsciiString(in);
        TableDesc table = new TableDesc();
        table.setName(tableName);
        ColumnDesc col = new ColumnDesc();
        col.setTable(table);
        col.setName(colName);
        col.setDatatype(datatype);
        col.init(table);
        cols[i] = col.getRef();

        int colSize = BytesUtil.readVInt(in);
        colSizes[i] = colSize;
    }
    return new CoprocessorRowType(cols, colSizes, bodyOffset);
}
 
开发者ID:apache,项目名称:kylin,代码行数:25,代码来源:CoprocessorRowType.java

示例8: writeDimensionEncoding

import org.apache.kylin.common.util.BytesUtil; //导入依赖的package包/类
private static void writeDimensionEncoding(DimensionEncoding encoding, ByteBuffer out) {
    try {
        if (encoding == null) {
            BytesUtil.writeVInt(1, out);
        } else {
            BytesUtil.writeVInt(0, out);

            if (encoding instanceof DictionaryDimEnc) {
                encoding = new TrimmedDimEnc(encoding.getLengthOfEncoding());
            }
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(encoding);
            BytesUtil.writeByteArray(baos.toByteArray(), out);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:apache,项目名称:kylin,代码行数:20,代码来源:TrimmedCubeCodeSystem.java

示例9: deserialize

import org.apache.kylin.common.util.BytesUtil; //导入依赖的package包/类
@Override
public IGTCodeSystem deserialize(ByteBuffer in) {
    Map<Integer, Integer> dependentMetricsMap = Maps.newHashMap();

    int size = BytesUtil.readVInt(in);
    for (int i = 0; i < size; ++i) {
        int key = BytesUtil.readVInt(in);
        int value = BytesUtil.readVInt(in);
        dependentMetricsMap.put(key, value);
    }

    DimensionEncoding[] dimEncs = new DimensionEncoding[BytesUtil.readVInt(in)];
    for (int i = 0; i < dimEncs.length; i++) {
        dimEncs[i] = readDimensionEncoding(in);
    }

    return new TrimmedCubeCodeSystem(dimEncs, dependentMetricsMap);
}
 
开发者ID:apache,项目名称:kylin,代码行数:19,代码来源:TrimmedCubeCodeSystem.java

示例10: encode

import org.apache.kylin.common.util.BytesUtil; //导入依赖的package包/类
@Override
public void encode(String valueStr, byte[] output, int outputOffset) {
    if (valueStr == null) {
        Arrays.fill(output, outputOffset, outputOffset + fixedLen, NULL);
        return;
    }

    long integer = Long.parseLong(valueStr);
    if (integer > CAP[fixedLen] || integer < TAIL[fixedLen]) {
        if (avoidVerbose++ % 10000 == 0) {
            logger.warn("Expect at most " + fixedLen + " bytes, but got " + valueStr + ", will truncate, hit times:" + avoidVerbose);
        }
    }

    if (integer == TAIL[fixedLen]) {
        if (avoidVerbose2++ % 10000 == 0) {
            logger.warn("Value " + valueStr + " does not fit into " + fixedLen + " bytes ");
        }
    }

    BytesUtil.writeLong(integer + CAP[fixedLen], output, outputOffset, fixedLen);//apply an offset to preserve binary order, overflow is okay
}
 
开发者ID:apache,项目名称:kylin,代码行数:23,代码来源:IntegerDimEnc.java

示例11: decode

import org.apache.kylin.common.util.BytesUtil; //导入依赖的package包/类
@Override
public String decode(byte[] bytes, int offset, int len) {
    if (isNull(bytes, offset, len)) {
        return null;
    }

    long integer = BytesUtil.readLong(bytes, offset, len) - CAP[fixedLen];

    //only take useful bytes
    integer = integer & MASK[fixedLen];
    boolean positive = (integer & ((0x80L) << ((fixedLen - 1) << 3))) == 0;
    if (!positive) {
        integer |= (~MASK[fixedLen]);
    }

    return String.valueOf(integer);
}
 
开发者ID:apache,项目名称:kylin,代码行数:18,代码来源:IntegerDimEnc.java

示例12: encode

import org.apache.kylin.common.util.BytesUtil; //导入依赖的package包/类
@Override
public void encode(String valueStr, byte[] output, int outputOffset) {
    if (valueStr == null) {
        Arrays.fill(output, outputOffset, outputOffset + fixedLen, NULL);
        return;
    }

    long integer = Long.parseLong(valueStr);
    if (integer > CAP[fixedLen]) {
        if (avoidVerbose++ % 10000 == 0) {
            logger.warn("Expect at most " + fixedLen + " bytes, but got " + valueStr + ", will truncate, hit times:" + avoidVerbose);
        }
    }

    BytesUtil.writeLong(integer, output, outputOffset, fixedLen);
}
 
开发者ID:apache,项目名称:kylin,代码行数:17,代码来源:IntDimEnc.java

示例13: addNodeMaybeOverflow

import org.apache.kylin.common.util.BytesUtil; //导入依赖的package包/类
private AppendDictNode addNodeMaybeOverflow(byte[] value, int start, int end) {
    AppendDictNode head = null;
    AppendDictNode current = null;
    for (; start + 255 < end; start += 255) {
        AppendDictNode c = new AppendDictNode(BytesUtil.subarray(value, start, start + 255), false);
        if (head == null) {
            head = c;
            current = c;
        } else {
            current.addChild(c);
            current = c;
        }
    }
    AppendDictNode last = new AppendDictNode(BytesUtil.subarray(value, start, end), true);
    last.id = createNextId();
    if (head == null) {
        head = last;
    } else {
        current.addChild(last);
    }
    return head;
}
 
开发者ID:apache,项目名称:kylin,代码行数:23,代码来源:AppendTrieDictionaryBuilder.java

示例14: init

import org.apache.kylin.common.util.BytesUtil; //导入依赖的package包/类
private void init() {
    if (BytesUtil.compareBytes(HEAD_MAGIC, 0, trieBytes, 0, HEAD_MAGIC.length) != 0)
        throw new IllegalArgumentException("Wrong file type (magic does not match)");

    try {
        DataInputStream headIn = new DataInputStream(new ByteArrayInputStream(trieBytes, HEAD_SIZE_I, trieBytes.length - HEAD_SIZE_I));
        this.headSize = headIn.readShort();
        this.bodyLen = headIn.readInt();
        this.nValues = headIn.readInt();
        this.sizeChildOffset = headIn.read();
        this.sizeOfId = headIn.read();

        this.childOffsetMask = ~(((long) (BIT_IS_LAST_CHILD | BIT_IS_END_OF_VALUE)) << ((sizeChildOffset - 1) * 8));
        this.firstByteOffset = sizeChildOffset + 1; // the offset from begin of node to its first value byte
    } catch (Exception e) {
        if (e instanceof RuntimeException)
            throw (RuntimeException) e;
        else
            throw new RuntimeException(e);
    }
}
 
开发者ID:apache,项目名称:kylin,代码行数:22,代码来源:AppendDictSlice.java

示例15: deserializeFrom

import org.apache.kylin.common.util.BytesUtil; //导入依赖的package包/类
public static AppendDictSlice deserializeFrom(DataInput in) throws IOException {
    byte[] headPartial = new byte[HEAD_MAGIC.length + Short.SIZE / Byte.SIZE + Integer.SIZE / Byte.SIZE];
    in.readFully(headPartial);

    if (BytesUtil.compareBytes(HEAD_MAGIC, 0, headPartial, 0, HEAD_MAGIC.length) != 0)
        throw new IllegalArgumentException("Wrong file type (magic does not match)");

    DataInputStream headIn = new DataInputStream(//
            new ByteArrayInputStream(headPartial, HEAD_SIZE_I, headPartial.length - HEAD_SIZE_I));
    int headSize = headIn.readShort();
    int bodyLen = headIn.readInt();
    headIn.close();

    byte[] all = new byte[headSize + bodyLen];
    System.arraycopy(headPartial, 0, all, 0, headPartial.length);
    in.readFully(all, headPartial.length, all.length - headPartial.length);

    return new AppendDictSlice(all);
}
 
开发者ID:apache,项目名称:kylin,代码行数:20,代码来源:AppendDictSlice.java


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