Beispiel #1
0
 private void loadFromFile() throws IOException, ReflectiveOperationException {
   RandomAccessFile file = null;
   try {
     int fieldId = 0;
     file = new RandomAccessFile(filePath, "r");
     while (file.getFilePointer() < file.length()) {
       String fieldName = file.readUTF();
       int fieldType = file.readUnsignedByte();
       BitSet bitSet = BitSet.valueOf(new byte[] {file.readByte()});
       boolean indexed = bitSet.get(BIT_INDEX_INDEXED);
       boolean stored = bitSet.get(BIT_INDEX_STORED);
       Field f = new Field();
       f.setFieldId(fieldId);
       f.setFieldName(fieldName);
       f.setIsIndexed(indexed);
       f.setIsStored(stored);
       f.setFieldType(fieldTypeStore.findTypeById(fieldType));
       fieldIdMapping.add(f);
       fieldNameMapping.put(f.getFieldName(), f);
       fieldId++;
     }
   } finally {
     if (file != null) {
       file.close();
     }
   }
 }
  public boolean verify(String message, Signature signature, PublicKey publicKey) throws Exception {
    if (!(publicKey instanceof PublicKeyLamport)) {
      throw new Exception("Wrong Type of Signing Key");
    }

    final PublicKeyLamport publicKeyLamport = (PublicKeyLamport) publicKey;

    if (!(signature instanceof SignatureLamport)) {
      throw new Exception("Wrong Type of Signature");
    }

    final SignatureLamport signatureLamport = (SignatureLamport) signature;
    final BitSet messageBits = new BitSet(this.k);
    messageBits.or(BitSet.valueOf(message.getBytes()));

    // verification algorithm
    for (int i = 0; i < this.k; ++i) {
      final Hash hashX = this.h.hash(signatureLamport.getSig(i).toByteArray());
      final Hash hashY =
          !messageBits.get(i) ? publicKeyLamport.getY1(i) : publicKeyLamport.getY2(i);
      if (!hashX.equals(hashY)) {
        return false;
      }
    }

    return true;
  }
 public boolean isPublicQueryable() {
   if (!isPublic()) {
     throw new IllegalStateException("This method is only valid for public edges.");
   }
   BitSet bs = BitSet.valueOf(new byte[] {this.publicLabel.getData()[16]});
   return bs.get(7);
 }
Beispiel #4
0
 void printByte(byte b) {
   byte[] bb = {b};
   BitSet bits = BitSet.valueOf(bb);
   for (int i = 0; i < 8; i++) {
     System.out.print(printBoolean(bits.get(i)) + " ");
   }
   System.out.println();
 }
Beispiel #5
0
  public boolean[][] getValues() {
    if (values != null) {
      return values;
    }

    boolean[][] v = new boolean[height()][width()];
    for (int j = 0; j < bytes() * width(); j += bytes()) {
      for (int b = 0; b < bytes(); b++) {
        BitSet bs = BitSet.valueOf(HexUtils.toBytes(getHexLetter().split(" ")[j + b]));
        for (int k = 8 * b; k < Math.min(8 * (b + 1), height()); k++) {
          final int colIndex = (j / bytes());
          v[k][colIndex] = bs.get(7 - k + 8 * b);
        }
      }
    }
    return v;
  }
Beispiel #6
0
  /**
   * @return an iterator over all tuples on this page (calling remove on this iterator throws an
   *     UnsupportedOperationException) (note that this iterator shouldn't return tuples in empty
   *     slots!)
   */
  public Iterator<Tuple> iterator() {
    // hdj
    final BitSet bitset = BitSet.valueOf(header);
    Iterator<Tuple> it =
        new Iterator<Tuple>() {
          int currentIndex = -1;

          public boolean hasNext() {
            if (bitset.nextSetBit(currentIndex + 1) == -1) return false;
            else return true;
          }

          public Tuple next() {
            currentIndex = bitset.nextSetBit(currentIndex + 1);
            return tuples[currentIndex];
          }

          public void remove() {
            throw new UnsupportedOperationException();
          }
        };

    return it;
  }
public class BinaryReflectedGrayCodeUtilTest {
  private static final BitSet MIN = BitSet.valueOf(new long[] {Long.MIN_VALUE});
  private static final BitSet B_MIN = BitSet.valueOf(new long[] {-1L});
  private static final BitSet G_MIN = BitSet.valueOf(new long[] {-4611686018427387904L});
  private static final BitSet ZERO = BitSet.valueOf(new long[] {0L});
  private static final BitSet ONE = BitSet.valueOf(new long[] {1L});
  private static final BitSet TWO = BitSet.valueOf(new long[] {2L});
  private static final BitSet TREE = BitSet.valueOf(new long[] {3L});
  private static final BitSet FOUR = BitSet.valueOf(new long[] {4L});
  private static final BitSet FIVE = BitSet.valueOf(new long[] {5L});
  private static final BitSet SIX = BitSet.valueOf(new long[] {6L});
  private static final BitSet SEVEN = BitSet.valueOf(new long[] {7L});
  private static final BitSet MAX = BitSet.valueOf(new long[] {Long.MAX_VALUE});
  private static final BitSet B_MAX = BitSet.valueOf(new long[] {6148914691236517205L});
  private static final BitSet G_MAX = BitSet.valueOf(new long[] {4611686018427387904L});

  @Test
  public void testBinaryToGray() throws Exception {
    assertEquals(G_MIN, BinaryReflectedGrayCodeUtil.binaryToGray(MIN));
    assertEquals(ZERO, BinaryReflectedGrayCodeUtil.binaryToGray(ZERO));
    assertEquals(ONE, BinaryReflectedGrayCodeUtil.binaryToGray(ONE));
    assertEquals(TREE, BinaryReflectedGrayCodeUtil.binaryToGray(TWO));
    assertEquals(TWO, BinaryReflectedGrayCodeUtil.binaryToGray(TREE));
    assertEquals(SIX, BinaryReflectedGrayCodeUtil.binaryToGray(FOUR));
    assertEquals(SEVEN, BinaryReflectedGrayCodeUtil.binaryToGray(FIVE));
    assertEquals(FIVE, BinaryReflectedGrayCodeUtil.binaryToGray(SIX));
    assertEquals(FOUR, BinaryReflectedGrayCodeUtil.binaryToGray(SEVEN));
    assertEquals(G_MAX, BinaryReflectedGrayCodeUtil.binaryToGray(MAX));
  }

  @Test
  public void testGrayToBinary() throws Exception {
    assertEquals(B_MIN, BinaryReflectedGrayCodeUtil.grayToBinary(MIN));
    assertEquals(ZERO, BinaryReflectedGrayCodeUtil.grayToBinary(ZERO));
    assertEquals(ONE, BinaryReflectedGrayCodeUtil.grayToBinary(ONE));
    assertEquals(TREE, BinaryReflectedGrayCodeUtil.grayToBinary(TWO));
    assertEquals(TWO, BinaryReflectedGrayCodeUtil.grayToBinary(TREE));
    assertEquals(SEVEN, BinaryReflectedGrayCodeUtil.grayToBinary(FOUR));
    assertEquals(SIX, BinaryReflectedGrayCodeUtil.grayToBinary(FIVE));
    assertEquals(FOUR, BinaryReflectedGrayCodeUtil.grayToBinary(SIX));
    assertEquals(FIVE, BinaryReflectedGrayCodeUtil.grayToBinary(SEVEN));
    assertEquals(B_MAX, BinaryReflectedGrayCodeUtil.grayToBinary(MAX));
  }
}
 // WARNING: the current implementation of BitSet (1.7) copies the contents of ByteBuffer to
 // on heap!
 // TODO: make a new BitSet implementation which can use ByteBuffers properly.
 public WrappedImmutableBitSetBitmap(ByteBuffer byteBuffer) {
   this(BitSet.valueOf(byteBuffer));
 }
  /** {@inheritDoc} */
  @Override
  public BitSet readBitSet() {
    long[] arr = readLongArray();

    return arr != null ? BitSet.valueOf(arr) : null;
  }
 private static byte setBit(byte input, byte pos, boolean set) {
   BitSet bs = BitSet.valueOf(new byte[] {input});
   bs.set(pos, set);
   return bs.toByteArray()[0];
 }
Beispiel #11
0
 private BitSetWrapper makeBitSetWrapper(byte[] bytes) {
   BitSet bitSet = BitSet.valueOf(bytes);
   return new BitSetWrapper(bitSet);
 }
Beispiel #12
0
  @Override
  public void decode(ByteBuf buf) {
    id = buf.readLong();
    byte[] bitSetBuf = new byte[8];
    buf.readBytes(bitSetBuf);
    this.bitSet = BitSet.valueOf(bitSetBuf);

    if (bitSet.get(0)) {
      position = readLongVector3(buf);
    }
    if (bitSet.get(1)) {
      orientation = readOrientation(buf);
    }
    if (bitSet.get(2)) {
      velocity = readFloatVector3(buf);
    }
    if (bitSet.get(3)) {
      accel = readFloatVector3(buf);
    }
    if (bitSet.get(4)) {
      extraVel = readFloatVector3(buf);
    }
    if (bitSet.get(5)) {
      lookPitch = buf.readFloat();
    }
    if (bitSet.get(6)) {
      physicsFlags = buf.readUnsignedInt();
    }
    if (bitSet.get(7)) {
      hostileType = buf.readByte();
    }
    if (bitSet.get(8)) {
      entityType = buf.readUnsignedInt();
    }
    if (bitSet.get(9)) {
      currentMode = buf.readByte();
    }
    if (bitSet.get(10)) {
      lastShootTime = buf.readUnsignedInt();
    }
    if (bitSet.get(11)) {
      hitCounter = buf.readUnsignedInt();
    }
    if (bitSet.get(12)) {
      lastHitTime = buf.readUnsignedInt();
    }
    if (bitSet.get(13)) {
      app.decode(buf);
    }
    if (bitSet.get(14)) {
      flags1 = buf.readByte();
      flags2 = buf.readByte();
    }
    if (bitSet.get(15)) {
      rollTime = buf.readUnsignedInt();
    }
    if (bitSet.get(16)) {
      stunTime = buf.readInt();
    }
    if (bitSet.get(17)) {
      slowedTime = buf.readUnsignedInt();
    }
    if (bitSet.get(18)) {
      makeBlueTime = buf.readUnsignedInt();
    }
    if (bitSet.get(19)) {
      speedUpTime = buf.readUnsignedInt();
    }
    if (bitSet.get(20)) {
      slowPatchTime = buf.readFloat();
    }
    if (bitSet.get(21)) {
      classType = buf.readByte();
    }
    if (bitSet.get(22)) {
      specialization = buf.readByte();
    }
    if (bitSet.get(23)) {
      chargedMP = buf.readFloat();
    }
    if (bitSet.get(24)) {
      nu1 = buf.readUnsignedInt();
      nu2 = buf.readUnsignedInt();
      nu3 = buf.readUnsignedInt();
    }
    if (bitSet.get(25)) {
      nu4 = buf.readUnsignedInt();
      nu5 = buf.readUnsignedInt();
      nu6 = buf.readUnsignedInt();
    }
    if (bitSet.get(26)) {
      rayHit = readFloatVector3(buf);
    }
    if (bitSet.get(27)) {
      HP = buf.readFloat();
    }
    if (bitSet.get(28)) {
      MP = buf.readFloat();
    }
    if (bitSet.get(29)) {
      blockPower = buf.readFloat();
    }
    if (bitSet.get(30)) {
      maxHPMultiplier = buf.readFloat();
      shootSpeed = buf.readFloat();
      damageMultiplier = buf.readFloat();
      armorMultiplier = buf.readFloat();
      resistanceMultiplier = buf.readFloat();
    }
    if (bitSet.get(31)) {
      nu7 = buf.readByte();
    }
    if (bitSet.get(32)) {
      nu8 = buf.readByte();
    }
    if (bitSet.get(33)) {
      level = buf.readUnsignedInt();
    }
    if (bitSet.get(34)) {
      currentXP = buf.readUnsignedInt();
    }
    if (bitSet.get(35)) {
      parentOwner = buf.readLong();
    }
    if (bitSet.get(36)) {
      na1 = buf.readUnsignedInt();
      na2 = buf.readUnsignedInt();
    }
    if (bitSet.get(37)) {
      na3 = buf.readByte();
    }
    if (bitSet.get(38)) {
      na4 = buf.readUnsignedInt();
    }
    if (bitSet.get(39)) {
      na5 = buf.readUnsignedInt();
      nu11 = buf.readUnsignedInt();
      nu12 = buf.readUnsignedInt();
    }
    if (bitSet.get(40)) {
      spawnPosition = readLongVector3(buf);
    }
    if (bitSet.get(41)) {
      nu20 = buf.readUnsignedInt();
      nu21 = buf.readUnsignedInt();
      nu22 = buf.readUnsignedInt();
    }
    if (bitSet.get(42)) {
      nu19 = buf.readByte();
    }
    if (bitSet.get(43)) {
      itemData.decode(buf);
    }
    if (bitSet.get(44)) {
      for (int i = 0; i < 13; i++) {
        GItem item = new GItem();
        item.decode(buf);
        equipment[i] = item;
      }
    }
    if (bitSet.get(45)) {
      name = new String(buf.readBytes(16).array(), Charsets.US_ASCII).trim();
    }
    if (bitSet.get(46)) {
      for (int i = 0; i < 11; i++) {
        skills[i] = buf.readUnsignedInt();
      }
    }
    if (bitSet.get(47)) {
      iceBlockFour = buf.readUnsignedInt();
    }

    debugCap = buf.capacity();
    buf.resetReaderIndex();
    buf.resetWriterIndex();
  }
Beispiel #13
0
 /** Returns true if associated slot on this page is filled. */
 public boolean isSlotUsed(int i) {
   // hdj
   BitSet bitset = BitSet.valueOf(header);
   return bitset.get(i);
 }
Beispiel #14
0
 /** Returns the number of empty slots on this page. */
 public int getNumEmptySlots() {
   // hdj:!!! use getNumTuples instead of bitset.size() or bitset.length()
   BitSet bitset = BitSet.valueOf(header);
   return getNumTuples() - bitset.cardinality();
 }
Beispiel #15
0
 /**
  * Constructs event class from given byte array.
  *
  * @param newStates changed states as byte array
  */
 public NewStatesEvent(byte[] newStates) {
   this(BitSet.valueOf(newStates));
 }