本文整理了Java中java.util.BitSet.toByteArray()
方法的一些代码示例,展示了BitSet.toByteArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BitSet.toByteArray()
方法的具体详情如下:
包路径:java.util.BitSet
类名称: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
@Override
public byte[] toBytes()
{
return bitmap.toByteArray();
}
代码示例来源:origin: apache/hive
public void setIncludedBuckets(BitSet includedBuckets) {
// see comment next to the field
this.includedBuckets = includedBuckets == null ? null : includedBuckets.toByteArray();
}
代码示例来源:origin: debezium/debezium
/**
* Convert a value from its logical format (BitSet) to it's encoded format.
*
* @param schema the schema
* @param value the logical value
* @return the encoded value
*/
public static byte[] fromBitSet(Schema schema, BitSet value) {
return value.toByteArray();
}
代码示例来源:origin: apache/incubator-druid
public void serialize(ByteBuffer buffer)
{
buffer.put(this.bitmap.toByteArray());
}
}
代码示例来源:origin: apache/drill
public void setIncludedBuckets(BitSet includedBuckets) {
// see comment next to the field
this.includedBuckets = includedBuckets.toByteArray();
}
代码示例来源:origin: stackoverflow.com
<a href="http://download.oracle.com/javase/7/docs/api/java/util/%42it%53et.html#to%42yte%41rray%28%29">
BitSet.toByteArray()
</a>
代码示例来源:origin: ethereum/ethereumj
public byte[] toBytes() {
byte[] ret = new byte[BLOOM_BYTES];
byte[] bytes = mask.toByteArray();
System.arraycopy(bytes, 0, ret, 0, bytes.length);
return ret;
}
代码示例来源:origin: apache/kylin
@Override
public void serialize(ImmutableBitSet value, ByteBuffer out) {
BytesUtil.writeByteArray(value.set.toByteArray(), out);
}
代码示例来源:origin: Codecademy/EventHub
@Override
public byte[] toBytes(BloomFilter bloomFilter) {
ByteBuffer byteBuffer = ByteBuffer.allocate(getObjectSize());
byteBuffer.put(bloomFilter.getBitSet().toByteArray());
return byteBuffer.array();
}
代码示例来源:origin: apache/ignite
/**
* Features supported by the current node.
*
* @return Byte array representing all supported features by current node.
*/
public static byte[] allFeatures() {
final BitSet set = new BitSet();
for (IgniteFeatures value : IgniteFeatures.values()) {
final int featureId = value.getFeatureId();
assert !set.get(featureId) : "Duplicate feature ID found for [" + value + "] having same ID ["
+ featureId + "]";
set.set(featureId);
}
return set.toByteArray();
}
}
代码示例来源:origin: zendesk/maxwell
@Override
public Object asJSON(Object value, MaxwellOutputConfig outputConfig) {
byte[] bytes;
if( value instanceof Boolean ){
bytes = new byte[]{(byte) (( Boolean ) value ? 1 : 0)};
} else if ( value instanceof BitSet ) {
BitSet bs = (BitSet) value;
bytes = bs.toByteArray();
} else {
bytes = (byte[]) value;
}
if ( bytes.length == 8 && ((bytes[7] & 0xFF) > 127) ) {
return bytesToBigInteger(bytes);
} else {
return bytesToLong(bytes);
}
}
代码示例来源:origin: apache/hive
ByteBuffer byteBuffer = ByteBuffer.wrap(abortedBits.toByteArray());
GetOpenTxnsResponse otr = new GetOpenTxnsResponse(hwm, openList, byteBuffer);
if(minOpenTxn < Long.MAX_VALUE) {
代码示例来源:origin: debezium/debezium
byte[] bytes = ((BitSet) data).toByteArray();
r.deliver(padLittleEndian(numBytes, bytes));
代码示例来源:origin: apache/hive
ByteBuffer byteBuffer = ByteBuffer.wrap(abortedBits.toByteArray());
TableValidWriteIds owi = new TableValidWriteIds(fullTableName, writeIdHwm, invalidWriteIdList, byteBuffer);
if (minOpenWriteId < Long.MAX_VALUE) {
代码示例来源:origin: vsch/flexmark-java
public byte[] toByteArray() {return myBits.toByteArray();}
public long[] toLongArray() {return myBits.toLongArray();}
代码示例来源:origin: lealone/Lealone
@Override
public void writeMeta(DataBuffer buff) {
buff.putVarLong(tid);
buff.putVarInt(logId);
if (rowLock) {
buff.put((byte) 0);
} else {
buff.put((byte) 1);
byte[] bytes = lockedColumns.toByteArray();
int len = bytes.length;
buff.putVarInt(len);
for (int i = 0; i < len; i++) {
buff.put(bytes[i]);
}
}
if (oldValue == null) {
buff.put((byte) 0);
} else {
buff.put((byte) 1);
oldValueType.write(buff, oldValue);
}
ValueString.type.write(buff, hostAndPort);
ValueString.type.write(buff, globalReplicationName);
buff.putVarLong(version);
}
代码示例来源:origin: apache/metron
public Map<String, String> bin(String hash) throws DecoderException {
Random r = new Random(0);
byte[] h = Hex.decodeHex(hash.substring(2 * checksumOption.getChecksumLength()).toCharArray());
BitSet vector = BitSet.valueOf(h);
int n = vector.length();
Map<String, String> ret = new HashMap<>();
boolean singleHash = hashes.size() == 1;
for (int numHashes : hashes) {
BitSet projection = new BitSet();
for (int i = 0; i < numHashes; ++i) {
int index = r.nextInt(n);
projection.set(i, vector.get(index));
}
String outputHash = numHashes + Hex.encodeHexString(projection.toByteArray());
if (singleHash) {
ret.put(TLSH_BIN_KEY, outputHash);
} else {
ret.put(TLSH_BIN_KEY + "_" + numHashes, outputHash);
}
}
return ret;
}
代码示例来源:origin: freenet/fred
@Override
public void writeToDataOutputStream(DataOutputStream dos) throws IOException {
dos.writeInt(size);
byte[] outputBits = bits.toByteArray();
if (outputBits.length != getByteSize()) {
outputBits = Arrays.copyOf(outputBits, getByteSize());
}
dos.write(outputBits);
}
代码示例来源:origin: jenetics/jenetics
@Test
public void fromBitSet() {
final Random random = new Random(234);
final BitSet bits = new BitSet(2343);
for (int i = 0; i < bits.size(); ++i) {
bits.set(i, random.nextBoolean());
}
final BitChromosome c = BitChromosome.of(bits);
Assert.assertEquals(c.toByteArray(), bits.toByteArray());
}
代码示例来源:origin: jenetics/jenetics
@Test
public void fromByteArrayBitSet() {
final Random random = new Random(123);
final byte[] bytes = new byte[234];
random.nextBytes(bytes);
final BitSet bits = BitSet.valueOf(bytes);
final BitChromosome c = BitChromosome.of(bits);
Assert.assertEquals(c.toByteArray(), bytes);
Assert.assertEquals(bits.toByteArray(), bytes);
}
内容来源于网络,如有侵权,请联系作者删除!