Here you can find the source of readBitSet(ByteBuffer buf, int len)
public static BitSet readBitSet(ByteBuffer buf, int len)
//package com.java2s; /**/*from w ww .jav a 2 s .com*/ * Project: ${puma-common.aid} * <p/> * File Created at 2012-6-6 $Id$ * <p/> * Copyright 2010 dianping.com. All rights reserved. * <p/> * This software is the confidential and proprietary information of Dianping * Company. ("Confidential Information"). You shall not disclose such * Confidential Information and shall use it only in accordance with the terms * of the license agreement you entered into with dianping.com. */ import java.nio.ByteBuffer; import java.util.BitSet; public class Main { public static BitSet readBitSet(ByteBuffer buf, int len) { BitSet bs = new BitSet((len + 7) >>> 3); int i; int b = 0; int leftBit = 0x01; int bitMask = 0; for (i = 0; i < len; i++) { if (i % 8 == 0) { b = buf.get(); bitMask = leftBit; } else { bitMask = bitMask << 1; } if ((bitMask & b) == bitMask) { bs.set(i); } else { bs.clear(i); } } return bs; } }