List of usage examples for java.util BitSet get
public boolean get(int bitIndex)
From source file:org.lwes.serializer.Deserializer.java
public static Short[] deserializeNInt16Array(DeserializerState state, byte[] bytes) { // get the number of items in the array int length = deserializeUINT16(state, bytes); // 2 bytes BitSet bs = deserializeBitSet(state, bytes); // 2 bytes * length worst case Short[] rtn = new Short[length]; for (int i = 0; i < length; i++) { if (bs.get(i)) { rtn[i] = deserializeINT16(state, bytes); } else {/* w ww.ja v a 2s . c o m*/ rtn[i] = null; } } return rtn; }
From source file:org.lwes.serializer.Deserializer.java
public static Double[] deserializeNDoubleArray(DeserializerState state, byte[] bytes) { // get the number of items in the array int length = deserializeUINT16(state, bytes); // 2 bytes BitSet bs = deserializeBitSet(state, bytes); // 2 bytes * length worst case Double[] rtn = new Double[length]; for (int i = 0; i < length; i++) { if (bs.get(i)) { rtn[i] = deserializeDOUBLE(state, bytes); } else {/* ww w. ja va2s . c o m*/ rtn[i] = null; } } return rtn; }
From source file:org.lwes.serializer.Deserializer.java
public static Integer[] deserializeNUInt16Array(DeserializerState state, byte[] bytes) { // get the number of items in the array int length = deserializeUINT16(state, bytes); // 2 bytes BitSet bs = deserializeBitSet(state, bytes); // 2 bytes * length worst case Integer[] rtn = new Integer[length]; for (int i = 0; i < length; i++) { if (bs.get(i)) { rtn[i] = deserializeUINT16(state, bytes); } else {/*from ww w . j a v a 2 s. c o m*/ rtn[i] = null; } } return rtn; }
From source file:org.lwes.serializer.Deserializer.java
public static Integer[] deserializeNInt32Array(DeserializerState state, byte[] bytes) { // get the number of items in the array int length = deserializeUINT16(state, bytes); // 2 bytes BitSet bs = deserializeBitSet(state, bytes); // 2 bytes * length worst case Integer[] rtn = new Integer[length]; for (int i = 0; i < length; i++) { if (bs.get(i)) { rtn[i] = deserializeINT32(state, bytes); } else {/*from ww w. j av a 2s .c o m*/ rtn[i] = null; } } return rtn; }
From source file:org.lwes.serializer.Deserializer.java
public static Boolean[] deserializeNBooleanArray(DeserializerState state, byte[] bytes) { // get the number of items in the array int length = deserializeUINT16(state, bytes); // 2 bytes BitSet bs = deserializeBitSet(state, bytes); // 2 bytes * length worst case Boolean[] rtn = new Boolean[length]; for (int i = 0; i < length; i++) { if (bs.get(i)) { rtn[i] = deserializeBOOLEAN(state, bytes); } else {//from w ww .j a v a2 s . c o m rtn[i] = null; } } return rtn; }
From source file:com.mcxiaoke.next.http.util.URLUtils.java
private static String urlEncode(final String content, final Charset charset, final BitSet safechars, final boolean blankAsPlus) { if (content == null) { return null; }/*from ww w .j a v a2 s .c o m*/ final StringBuilder buf = new StringBuilder(); final ByteBuffer bb = charset.encode(content); while (bb.hasRemaining()) { final int b = bb.get() & 0xff; if (safechars.get(b)) { buf.append((char) b); } else if (blankAsPlus && b == ' ') { buf.append('+'); } else { buf.append("%"); final char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, RADIX)); final char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, RADIX)); buf.append(hex1); buf.append(hex2); } } return buf.toString(); }
From source file:org.apache.openjpa.kernel.DetachManager.java
/** * Flush or invoke pre-store callbacks on the given broker if * needed. Return true if flushed/stored, false otherwise. *///from w w w .j a v a2 s . c om private static boolean flushDirty(StateManagerImpl sm) { if (!sm.isDirty() || !sm.getBroker().isActive()) return false; // only flush if there are actually any dirty non-flushed fields BitSet dirtyFields = sm.getDirty(); BitSet flushedFields = sm.getFlushed(); for (int i = 0; i < dirtyFields.size(); i++) { if (dirtyFields.get(i) && !flushedFields.get(i)) { if (sm.getBroker().getRollbackOnly()) sm.getBroker().preFlush(); else sm.getBroker().flush(); return true; } } return false; }
From source file:Main.java
public static byte[] encodedSeptetsToUnencodedSeptets(byte[] octetBytes, boolean discardLast) { byte newBytes[]; BitSet bitSet; int i, j, value1, value2; bitSet = new BitSet(octetBytes.length * 8); value1 = 0;/*from www . j ava2 s. c om*/ for (i = 0; i < octetBytes.length; i++) for (j = 0; j < 8; j++) { value1 = (i * 8) + j; if ((octetBytes[i] & (1 << j)) != 0) bitSet.set(value1); } value1++; // this is a bit count NOT a byte count value2 = value1 / 7 + ((value1 % 7 != 0) ? 1 : 0); // big diff here //System.out.println(octetBytes.length); //System.out.println(value1+" --> "+value2); if (value2 == 0) value2++; newBytes = new byte[value2]; for (i = 0; i < value2; i++) { for (j = 0; j < 7; j++) { if ((value1 + 1) > (i * 7 + j)) { if (bitSet.get(i * 7 + j)) { newBytes[i] |= (byte) (1 << j); } } } } if (discardLast && octetBytes.length * 8 % 7 > 0) { // when decoding a 7bit encoded string // the last septet may become 0, this should be discarded // since this is an artifact of the encoding not part of the // original string // this is only done for decoding 7bit encoded text NOT for // reversing octets to septets (e.g. for the encoding the UDH) if (newBytes[newBytes.length - 1] == 0) { byte[] retVal = new byte[newBytes.length - 1]; System.arraycopy(newBytes, 0, retVal, 0, retVal.length); return retVal; } } return newBytes; }
From source file:spypunk.tetris.ui.controller.input.TetrisControllerInputHandlerImpl.java
private boolean isKeyTriggered(final int keyCode, final BitSet bitSet) { return bitSet.get(keyCode); }
From source file:QCodec.java
/** * Encodes an array of bytes into an array of quoted-printable 7-bit characters. Unsafe characters are escaped. * //from ww w. ja va 2s . co m * <p> * This function implements a subset of quoted-printable encoding specification (rule #1 and rule #2) as defined in * RFC 1521 and is suitable for encoding binary data and unformatted text. * </p> * * @param printable * bitset of characters deemed quoted-printable * @param bytes * array of bytes to be encoded * @return array of bytes containing quoted-printable data */ public static final byte[] encodeQuotedPrintable(BitSet printable, byte[] bytes) { if (bytes == null) { return null; } if (printable == null) { printable = PRINTABLE_CHARS; } ByteArrayOutputStream buffer = new ByteArrayOutputStream(); for (int i = 0; i < bytes.length; i++) { int b = bytes[i]; if (b < 0) { b = 256 + b; } if (printable.get(b)) { buffer.write(b); } else { encodeQuotedPrintable(b, buffer); } } return buffer.toByteArray(); }