java.util.BitSet.toByteArray()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(671)

本文整理了Java中java.util.BitSet.toByteArray()方法的一些代码示例,展示了BitSet.toByteArray()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BitSet.toByteArray()方法的具体详情如下:
包路径:java.util.BitSet
类名称:BitSet
方法名:toByteArray

BitSet.toByteArray介绍

[英]Returns a new byte[] containing a little-endian representation the bits of this BitSet, suitable for passing to valueOf to reconstruct this BitSet.
[中]返回一个新的字节[],其中包含此位集的位的一个小的endian表示形式,适合传递给valueOf以重建此位集。

代码示例

代码示例来源:origin: apache/incubator-druid

  1. @Override
  2. public byte[] toBytes()
  3. {
  4. return bitmap.toByteArray();
  5. }

代码示例来源:origin: apache/hive

  1. public void setIncludedBuckets(BitSet includedBuckets) {
  2. // see comment next to the field
  3. this.includedBuckets = includedBuckets == null ? null : includedBuckets.toByteArray();
  4. }

代码示例来源:origin: debezium/debezium

  1. /**
  2. * Convert a value from its logical format (BitSet) to it's encoded format.
  3. *
  4. * @param schema the schema
  5. * @param value the logical value
  6. * @return the encoded value
  7. */
  8. public static byte[] fromBitSet(Schema schema, BitSet value) {
  9. return value.toByteArray();
  10. }

代码示例来源:origin: apache/incubator-druid

  1. public void serialize(ByteBuffer buffer)
  2. {
  3. buffer.put(this.bitmap.toByteArray());
  4. }
  5. }

代码示例来源:origin: apache/drill

  1. public void setIncludedBuckets(BitSet includedBuckets) {
  2. // see comment next to the field
  3. this.includedBuckets = includedBuckets.toByteArray();
  4. }

代码示例来源:origin: stackoverflow.com

  1. <a href="http://download.oracle.com/javase/7/docs/api/java/util/%42it%53et.html#to%42yte%41rray%28%29">
  2. BitSet.toByteArray()
  3. </a>

代码示例来源:origin: ethereum/ethereumj

  1. public byte[] toBytes() {
  2. byte[] ret = new byte[BLOOM_BYTES];
  3. byte[] bytes = mask.toByteArray();
  4. System.arraycopy(bytes, 0, ret, 0, bytes.length);
  5. return ret;
  6. }

代码示例来源:origin: apache/kylin

  1. @Override
  2. public void serialize(ImmutableBitSet value, ByteBuffer out) {
  3. BytesUtil.writeByteArray(value.set.toByteArray(), out);
  4. }

代码示例来源:origin: Codecademy/EventHub

  1. @Override
  2. public byte[] toBytes(BloomFilter bloomFilter) {
  3. ByteBuffer byteBuffer = ByteBuffer.allocate(getObjectSize());
  4. byteBuffer.put(bloomFilter.getBitSet().toByteArray());
  5. return byteBuffer.array();
  6. }

代码示例来源:origin: apache/ignite

  1. /**
  2. * Features supported by the current node.
  3. *
  4. * @return Byte array representing all supported features by current node.
  5. */
  6. public static byte[] allFeatures() {
  7. final BitSet set = new BitSet();
  8. for (IgniteFeatures value : IgniteFeatures.values()) {
  9. final int featureId = value.getFeatureId();
  10. assert !set.get(featureId) : "Duplicate feature ID found for [" + value + "] having same ID ["
  11. + featureId + "]";
  12. set.set(featureId);
  13. }
  14. return set.toByteArray();
  15. }
  16. }

代码示例来源:origin: zendesk/maxwell

  1. @Override
  2. public Object asJSON(Object value, MaxwellOutputConfig outputConfig) {
  3. byte[] bytes;
  4. if( value instanceof Boolean ){
  5. bytes = new byte[]{(byte) (( Boolean ) value ? 1 : 0)};
  6. } else if ( value instanceof BitSet ) {
  7. BitSet bs = (BitSet) value;
  8. bytes = bs.toByteArray();
  9. } else {
  10. bytes = (byte[]) value;
  11. }
  12. if ( bytes.length == 8 && ((bytes[7] & 0xFF) > 127) ) {
  13. return bytesToBigInteger(bytes);
  14. } else {
  15. return bytesToLong(bytes);
  16. }
  17. }

代码示例来源:origin: apache/hive

  1. ByteBuffer byteBuffer = ByteBuffer.wrap(abortedBits.toByteArray());
  2. GetOpenTxnsResponse otr = new GetOpenTxnsResponse(hwm, openList, byteBuffer);
  3. if(minOpenTxn < Long.MAX_VALUE) {

代码示例来源:origin: debezium/debezium

  1. byte[] bytes = ((BitSet) data).toByteArray();
  2. r.deliver(padLittleEndian(numBytes, bytes));

代码示例来源:origin: apache/hive

  1. ByteBuffer byteBuffer = ByteBuffer.wrap(abortedBits.toByteArray());
  2. TableValidWriteIds owi = new TableValidWriteIds(fullTableName, writeIdHwm, invalidWriteIdList, byteBuffer);
  3. if (minOpenWriteId < Long.MAX_VALUE) {

代码示例来源:origin: vsch/flexmark-java

  1. public byte[] toByteArray() {return myBits.toByteArray();}
  2. public long[] toLongArray() {return myBits.toLongArray();}

代码示例来源:origin: lealone/Lealone

  1. @Override
  2. public void writeMeta(DataBuffer buff) {
  3. buff.putVarLong(tid);
  4. buff.putVarInt(logId);
  5. if (rowLock) {
  6. buff.put((byte) 0);
  7. } else {
  8. buff.put((byte) 1);
  9. byte[] bytes = lockedColumns.toByteArray();
  10. int len = bytes.length;
  11. buff.putVarInt(len);
  12. for (int i = 0; i < len; i++) {
  13. buff.put(bytes[i]);
  14. }
  15. }
  16. if (oldValue == null) {
  17. buff.put((byte) 0);
  18. } else {
  19. buff.put((byte) 1);
  20. oldValueType.write(buff, oldValue);
  21. }
  22. ValueString.type.write(buff, hostAndPort);
  23. ValueString.type.write(buff, globalReplicationName);
  24. buff.putVarLong(version);
  25. }

代码示例来源:origin: apache/metron

  1. public Map<String, String> bin(String hash) throws DecoderException {
  2. Random r = new Random(0);
  3. byte[] h = Hex.decodeHex(hash.substring(2 * checksumOption.getChecksumLength()).toCharArray());
  4. BitSet vector = BitSet.valueOf(h);
  5. int n = vector.length();
  6. Map<String, String> ret = new HashMap<>();
  7. boolean singleHash = hashes.size() == 1;
  8. for (int numHashes : hashes) {
  9. BitSet projection = new BitSet();
  10. for (int i = 0; i < numHashes; ++i) {
  11. int index = r.nextInt(n);
  12. projection.set(i, vector.get(index));
  13. }
  14. String outputHash = numHashes + Hex.encodeHexString(projection.toByteArray());
  15. if (singleHash) {
  16. ret.put(TLSH_BIN_KEY, outputHash);
  17. } else {
  18. ret.put(TLSH_BIN_KEY + "_" + numHashes, outputHash);
  19. }
  20. }
  21. return ret;
  22. }

代码示例来源:origin: freenet/fred

  1. @Override
  2. public void writeToDataOutputStream(DataOutputStream dos) throws IOException {
  3. dos.writeInt(size);
  4. byte[] outputBits = bits.toByteArray();
  5. if (outputBits.length != getByteSize()) {
  6. outputBits = Arrays.copyOf(outputBits, getByteSize());
  7. }
  8. dos.write(outputBits);
  9. }

代码示例来源:origin: jenetics/jenetics

  1. @Test
  2. public void fromBitSet() {
  3. final Random random = new Random(234);
  4. final BitSet bits = new BitSet(2343);
  5. for (int i = 0; i < bits.size(); ++i) {
  6. bits.set(i, random.nextBoolean());
  7. }
  8. final BitChromosome c = BitChromosome.of(bits);
  9. Assert.assertEquals(c.toByteArray(), bits.toByteArray());
  10. }

代码示例来源:origin: jenetics/jenetics

  1. @Test
  2. public void fromByteArrayBitSet() {
  3. final Random random = new Random(123);
  4. final byte[] bytes = new byte[234];
  5. random.nextBytes(bytes);
  6. final BitSet bits = BitSet.valueOf(bytes);
  7. final BitChromosome c = BitChromosome.of(bits);
  8. Assert.assertEquals(c.toByteArray(), bytes);
  9. Assert.assertEquals(bits.toByteArray(), bytes);
  10. }

相关文章