예제 #1
0
  public int getOrCreateField(Field f) throws IOException, ReflectiveOperationException {
    if (fieldIdMapping.size() > f.getFieldId()) {
      return fieldIdMapping.get(f.getFieldId()).getFieldId();
    }
    RandomAccessFile file = null;
    try {
      file = new RandomAccessFile(filePath, "rw");
      file.seek(file.length());
      f.setFieldId(fieldIdMapping.size());
      file.writeUTF(f.getFieldName());
      int typeId = fieldTypeStore.getOrCreateTypeId(f.getFieldType());
      file.writeByte(typeId);
      BitSet bitSet = new BitSet(8);
      bitSet.set(BIT_INDEX_INDEXED, f.isIndexed());
      bitSet.set(BIT_INDEX_STORED, f.isStored());
      file.write(bitSet.toByteArray());
      // Add to indexes
      fieldIdMapping.add(f);
      fieldNameMapping.put(f.getFieldName(), f);

      return f.getFieldId();
    } finally {
      if (file != null) {
        file.close();
      }
    }
  }
예제 #2
0
  public static void main(String[] args) {
    BitSet bits1 = new BitSet();
    BitSet bits2 = new BitSet(16);

    bits1.set(1);
    bits1.set(2);
    bits1.set(3);
    bits2.set(2);
    bits2.set(3);
    bits2.set(5);
    bits2.set(4);

    System.out.println(bits1);
    System.out.println(bits2);
    // bits2.andNot(bits1);
    for (int i = 0; i < bits1.toByteArray().length; i++) {
      System.out.println(bits1.toByteArray().length);
    }
    // System.out.println();

    long l[] = bits1.toLongArray();
    System.out.println(l.length);
  }
예제 #3
0
 public static final byte[] encodeUrl(BitSet paramBitSet, byte[] paramArrayOfByte) {
   if (paramArrayOfByte == null) {
     return null;
   }
   BitSet localBitSet = paramBitSet;
   if (paramBitSet == null) {
     localBitSet = WWW_FORM_URL;
   }
   paramBitSet = new ByteArrayOutputStream();
   int m = paramArrayOfByte.length;
   int j = 0;
   if (j < m) {
     int k = paramArrayOfByte[j];
     int i = k;
     if (k < 0) {
       i = k + 256;
     }
     if (localBitSet.get(i)) {
       k = i;
       if (i == 32) {
         k = 43;
       }
       paramBitSet.write(k);
     }
     for (; ; ) {
       j += 1;
       break;
       paramBitSet.write(37);
       k = Character.toUpperCase(Character.forDigit(i >> 4 & 0xF, 16));
       i = Character.toUpperCase(Character.forDigit(i & 0xF, 16));
       paramBitSet.write(k);
       paramBitSet.write(i);
     }
   }
   return paramBitSet.toByteArray();
 }
 @Override
 public byte[] toBytes() {
   return bitmap.toByteArray();
 }
예제 #5
0
 /**
  * Constructing a new BitChromosome from a given BitSet. The BitSet is copied while construction.
  * The length of the constructed BitChromosome will be {@code bitSet.length()} ({@link
  * BitSet#length}).
  *
  * @param bits the bit-set which initializes the chromosome
  * @return a new {@code BitChromosome} with the given parameter
  * @throws NullPointerException if the {@code bitSet} is {@code null}.
  */
 public static BitChromosome of(final BitSet bits) {
   return new BitChromosome(bits.toByteArray(), -1);
 }
예제 #6
0
 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];
 }
예제 #7
0
  @Override
  public void encode(ByteBuf buf) {
    // For testing purposes using default dummy entity :)
    /*boolean dummy = false;
    if (name.contains("dummy")) dummy = true;*/

    buf.writeLong(id); // Ulong but whatever
    buf.writeBytes(bitSet.toByteArray());
    buf.writeBytes(
        new byte
            [8 - bitSet.toByteArray().length]); // BitSet/BitArray are the stupidest classes ever :(
    if (bitSet.get(0)) {
      writeLongVector3(buf, position);
    }
    if (bitSet.get(1)) {
      writeOrientation(buf, orientation);
    }
    if (bitSet.get(2)) {
      writeFloatVector3(buf, velocity);
    }
    if (bitSet.get(3)) {
      writeFloatVector3(buf, accel);
    }
    if (bitSet.get(4)) {
      writeFloatVector3(buf, extraVel);
    }
    if (bitSet.get(5)) {
      buf.writeFloat(lookPitch);
    }
    if (bitSet.get(6)) {
      buf.writeInt((int) physicsFlags);
    }
    if (bitSet.get(7)) {
      buf.writeByte(hostileType);
    }
    if (bitSet.get(8)) {
      buf.writeInt((int) entityType);
    }
    if (bitSet.get(9)) {
      buf.writeByte(currentMode);
    }
    if (bitSet.get(10)) {
      buf.writeInt((int) lastShootTime);
    }
    if (bitSet.get(11)) {
      buf.writeInt((int) hitCounter);
    }
    if (bitSet.get(12)) {
      buf.writeInt((int) lastHitTime);
    }
    if (bitSet.get(13)) {
      app.encode(buf);
    }
    if (bitSet.get(14)) {
      buf.writeByte(flags1);
      buf.writeByte(flags2);
    }
    if (bitSet.get(15)) {
      buf.writeInt((int) rollTime);
    }
    if (bitSet.get(16)) {
      buf.writeInt(stunTime);
    }
    if (bitSet.get(17)) {
      buf.writeInt((int) slowedTime);
    }
    if (bitSet.get(18)) {
      buf.writeInt((int) makeBlueTime);
    }
    if (bitSet.get(19)) {
      buf.writeInt((int) speedUpTime);
    }
    if (bitSet.get(20)) {
      buf.writeFloat(slowPatchTime);
    }
    if (bitSet.get(21)) {
      buf.writeByte(classType);
    }
    if (bitSet.get(22)) {
      buf.writeByte(specialization);
    }
    if (bitSet.get(23)) {
      buf.writeFloat(chargedMP);
    }
    if (bitSet.get(24)) {
      buf.writeInt((int) nu1);
      buf.writeInt((int) nu2);
      buf.writeInt((int) nu3);
    }
    if (bitSet.get(25)) {
      buf.writeInt((int) nu4);
      buf.writeInt((int) nu5);
      buf.writeInt((int) nu6);
    }
    if (bitSet.get(26)) {
      writeFloatVector3(buf, rayHit);
    }
    if (bitSet.get(27)) {
      buf.writeFloat(HP);
    }
    if (bitSet.get(28)) {
      buf.writeFloat(MP);
    }
    if (bitSet.get(29)) {
      buf.writeFloat(blockPower);
    }
    if (bitSet.get(30)) {
      buf.writeFloat(maxHPMultiplier);
      buf.writeFloat(shootSpeed);
      buf.writeFloat(damageMultiplier);
      buf.writeFloat(armorMultiplier);
      buf.writeFloat(resistanceMultiplier);
    }
    if (bitSet.get(31)) {
      buf.writeByte(nu7);
    }
    if (bitSet.get(32)) {
      buf.writeByte(nu8);
    }
    if (bitSet.get(33)) {
      buf.writeInt((int) level);
    }
    if (bitSet.get(34)) {
      buf.writeInt((int) currentXP);
    }
    if (bitSet.get(35)) {
      buf.writeLong(parentOwner);
    }
    if (bitSet.get(36)) {
      buf.writeInt((int) na1);
      buf.writeInt((int) na2);
    }
    if (bitSet.get(37)) {
      buf.writeByte(na3);
    }
    if (bitSet.get(38)) {
      buf.writeInt((int) na4);
    }
    if (bitSet.get(39)) {
      buf.writeInt((int) na5);
      buf.writeInt((int) nu11);
      buf.writeInt((int) nu12);
    }
    if (bitSet.get(40)) {
      writeLongVector3(buf, spawnPosition);
    }
    if (bitSet.get(41)) {
      buf.writeInt((int) nu20);
      buf.writeInt((int) nu21);
      buf.writeInt((int) nu22);
    }
    if (bitSet.get(42)) {
      buf.writeByte(nu19);
    }
    if (bitSet.get(43)) {
      itemData.encode(buf);
    }
    if (bitSet.get(44)) {
      for (int i = 0; i < 13; i++) {
        GItem item = equipment[i];
        item.encode(buf);
      }
    }
    if (bitSet.get(45)) {
      byte[] ascii = name.getBytes(Charsets.US_ASCII);
      buf.writeBytes(ascii);
      buf.writeBytes(new byte[16 - name.length()]);
    }
    if (bitSet.get(46)) {
      for (int i = 0; i < 11; i++) {
        buf.writeInt((int) skills[i]);
      }
    }
    if (bitSet.get(47)) {
      buf.writeInt((int) iceBlockFour);
    }

    buf.capacity(buf.writerIndex() + 1);
    if (buf.readerIndex() > 0) {
      Glydar.getServer().getLogger().warning("Data read during encode.");
    }
  }