@Override
 public void toData(DataOutput out) throws IOException {
   out.writeInt(this.prId);
   out.writeByte(this.scope.ordinal);
   InternalDataSerializer.invokeToData(this.pAttrs, out);
   out.writeBoolean(this.isDestroying);
   out.writeBoolean(this.isColocationComplete);
   InternalDataSerializer.invokeToData(this.nodes, out);
   DataSerializer.writeString(this.partitionResolver, out);
   DataSerializer.writeString(this.colocatedWith, out);
   DataSerializer.writeString(this.fullPath, out);
   InternalDataSerializer.invokeToData(this.ea, out);
   InternalDataSerializer.invokeToData(this.regionIdleTimeout, out);
   InternalDataSerializer.invokeToData(this.regionTimeToLive, out);
   InternalDataSerializer.invokeToData(this.entryIdleTimeout, out);
   InternalDataSerializer.invokeToData(this.entryTimeToLive, out);
   out.writeBoolean(this.firstDataStoreCreated);
   DataSerializer.writeObject(elderFPAs, out);
   DataSerializer.writeArrayList(this.partitionListenerClassNames, out);
   if (this.gatewaySenderIds.isEmpty()) {
     DataSerializer.writeObject(null, out);
   } else {
     DataSerializer.writeObject(this.gatewaySenderIds, out);
   }
 }
示例#2
0
  /**
   * Serializes a long to a binary stream with zero-compressed encoding. For -112 <= i <= 127, only
   * one byte is used with the actual value. For other values of i, the first byte value indicates
   * whether the long is positive or negative, and the number of bytes that follow. If the first
   * byte value v is between -113 and -120, the following long is positive, with number of bytes
   * that follow are -(v+112). If the first byte value v is between -121 and -128, the following
   * long is negative, with number of bytes that follow are -(v+120). Bytes are stored in the
   * high-non-zero-byte-first order.
   *
   * @param stream Binary output stream
   * @param i Long to be serialized
   * @throws java.io.IOException
   */
  public static void writeVLong(DataOutput stream, long i) throws IOException {
    if (i >= -112 && i <= 127) {
      stream.writeByte((byte) i);
      return;
    }

    int len = -112;
    if (i < 0) {
      i ^= -1L; // take one's complement'
      len = -120;
    }

    long tmp = i;
    while (tmp != 0) {
      tmp = tmp >> 8;
      len--;
    }

    stream.writeByte((byte) len);

    len = (len < -120) ? -(len + 120) : -(len + 112);

    for (int idx = len; idx != 0; idx--) {
      int shiftbits = (idx - 1) * 8;
      long mask = 0xFFL << shiftbits;
      stream.writeByte((byte) ((i & mask) >> shiftbits));
    }
  }
  public void writeProperties(DataOutput buffer, List<L2Property> list, UnrealPackageReadOnly up)
      throws UnrealException {
    try {
      for (L2Property property : list) {
        Property template = property.getTemplate();

        for (int i = 0; i < property.getSize(); i++) {
          Object obj = property.getAt(i);
          if (obj == null) continue;

          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          DataOutput objBuffer = new DataOutputStream(baos, buffer.getCharset());
          AtomicBoolean array = new AtomicBoolean(i > 0);
          AtomicReference<String> structName = new AtomicReference<>();
          AtomicReference<Type> type =
              new AtomicReference<>(
                  Type.valueOf(
                      template.getClass().getSimpleName().replace("Property", "").toUpperCase()));
          write(objBuffer, template, obj, array, structName, type, up);
          byte[] bytes = baos.toByteArray();

          int size = getPropertySize(bytes.length);
          int ord = type.get().ordinal();
          if (ord == 8) // FIXME
          ord = 5;
          int info = (array.get() ? 1 << 7 : 0) | (size << 4) | ord;

          buffer.writeCompactInt(up.nameReference(template.getEntry().getObjectName().getName()));
          buffer.writeByte(info);

          if (type.get() == Type.STRUCT) buffer.writeCompactInt(up.nameReference(structName.get()));
          switch (size) {
            case 5:
              buffer.writeByte(bytes.length);
              break;
            case 6:
              buffer.writeShort(bytes.length);
              break;
            case 7:
              buffer.writeInt(bytes.length);
              break;
          }
          if (i > 0) buffer.writeByte(i);
          buffer.write(bytes);
        }
      }
      buffer.writeCompactInt(up.nameReference("None"));
    } catch (IOException e) {
      throw new UnrealException(e);
    }
  }
示例#4
0
  private void serializeNode(DataOutput output, Node node) throws IOException {
    int flags = 0;
    if (node.left != null) {
      flags |= Flags.HAS_LEFT;
    }
    if (node.right != null) {
      flags |= Flags.HAS_RIGHT;
    }

    output.writeByte(flags);
    output.writeByte(node.level);
    output.writeLong(node.bits);
    output.writeDouble(node.weightedCount);
  }
 /**
  * Post 7.1, if changes are made to this method make sure that it is backwards compatible by
  * creating toDataPreXX methods. Also make sure that the callers to this method are backwards
  * compatible by creating toDataPreXX methods for them even if they are not changed. <br>
  * Callers for this method are: <br>
  * SendQueueMessage.toData(DataOutput) <br>
  */
 public void toData(DataOutput out) throws IOException {
   out.writeByte(this.op.ordinal);
   DataSerializer.writeObject(this.cbArg, out);
   if (this.op.isEntry()) {
     DataSerializer.writeObject(this.key, out);
     if (this.op.isUpdate() || this.op.isCreate()) {
       out.writeByte(this.deserializationPolicy);
       if (this.deserializationPolicy != DistributedCacheOperation.DESERIALIZATION_POLICY_EAGER) {
         DataSerializer.writeByteArray(this.value, out);
       } else {
         DataSerializer.writeObject(this.valueObj, out);
       }
     }
   }
 }
示例#6
0
 public void writeByte(int v) {
   try {
     dataOutput.writeByte(v);
   } catch (IOException ex) {
     throw new RuntimeException(ex.getMessage());
   }
 }
 @Override
 public void toData(DataOutput out) throws IOException {
   super.toData(out);
   out.writeByte(this.attributeCode);
   out.writeInt(this.newValue);
   out.writeInt(this.cacheId);
 }
示例#8
0
  void write(DataOutput dos) throws IOException {
    if (list.size() > 0) type = list.get(0).getId();
    else type = 1;

    dos.writeByte(type);
    dos.writeInt(list.size());
    for (int i = 0; i < list.size(); i++) list.get(i).write(dos);
  }
 /**
  * Writes the primitive value to the stream.
  *
  * @param out A stream to write to.
  * @param value A value to write.
  * @throws IOException If an I/O error occurs.
  */
 static void writePrimitive(DataOutput out, Object value) throws IOException {
   if (value instanceof Byte) out.writeByte((Byte) value);
   else if (value instanceof Short) out.writeShort((Short) value);
   else if (value instanceof Integer) out.writeInt((Integer) value);
   else if (value instanceof Long) out.writeLong((Long) value);
   else if (value instanceof Float) out.writeFloat((Float) value);
   else if (value instanceof Double) out.writeDouble((Double) value);
   else if (value instanceof Boolean) out.writeBoolean((Boolean) value);
   else if (value instanceof Character) out.writeChar((Character) value);
   else throw new IllegalArgumentException();
 }
示例#10
0
  /** Write a {@link Writable}, {@link String}, primitive type, or an array of the preceding. */
  public static void writeObject(
      DataOutput out, Object instance, Class declaredClass, Configuration conf) throws IOException {

    if (instance == null) { // null
      instance = new NullInstance(declaredClass, conf);
      declaredClass = Writable.class;
    }

    UTF8.writeString(out, declaredClass.getName()); // always write declared

    if (declaredClass.isArray()) { // array
      int length = Array.getLength(instance);
      out.writeInt(length);
      for (int i = 0; i < length; i++) {
        writeObject(out, Array.get(instance, i), declaredClass.getComponentType(), conf);
      }

    } else if (declaredClass == String.class) { // String
      UTF8.writeString(out, (String) instance);

    } else if (declaredClass.isPrimitive()) { // primitive type

      if (declaredClass == Boolean.TYPE) { // boolean
        out.writeBoolean(((Boolean) instance).booleanValue());
      } else if (declaredClass == Character.TYPE) { // char
        out.writeChar(((Character) instance).charValue());
      } else if (declaredClass == Byte.TYPE) { // byte
        out.writeByte(((Byte) instance).byteValue());
      } else if (declaredClass == Short.TYPE) { // short
        out.writeShort(((Short) instance).shortValue());
      } else if (declaredClass == Integer.TYPE) { // int
        out.writeInt(((Integer) instance).intValue());
      } else if (declaredClass == Long.TYPE) { // long
        out.writeLong(((Long) instance).longValue());
      } else if (declaredClass == Float.TYPE) { // float
        out.writeFloat(((Float) instance).floatValue());
      } else if (declaredClass == Double.TYPE) { // double
        out.writeDouble(((Double) instance).doubleValue());
      } else if (declaredClass == Void.TYPE) { // void
      } else {
        throw new IllegalArgumentException("Not a primitive: " + declaredClass);
      }
    } else if (declaredClass.isEnum()) { // enum
      UTF8.writeString(out, ((Enum) instance).name());
    } else if (Writable.class.isAssignableFrom(declaredClass)) { // Writable
      UTF8.writeString(out, instance.getClass().getName());
      ((Writable) instance).write(out);

    } else {
      throw new IOException("Can't write: " + instance + " as " + declaredClass);
    }
  }
示例#11
0
文件: GMS.java 项目: jtoerber/JGroups
 public void writeTo(DataOutput out) throws Exception {
   out.writeByte(type);
   boolean isMergeView = view != null && view instanceof MergeView;
   out.writeBoolean(isMergeView);
   Util.writeStreamable(view, out);
   Util.writeAddress(mbr, out);
   Util.writeAddresses(mbrs, out);
   Util.writeStreamable(join_rsp, out);
   Util.writeStreamable(my_digest, out);
   Util.writeStreamable(merge_id, out);
   out.writeBoolean(merge_rejected);
   out.writeBoolean(useFlushIfPresent);
 }
示例#12
0
 private static void writeDNASequence(String sequence, DataOutput out) throws IOException {
   out.writeInt(sequence.length());
   for (int i = 0; i < sequence.length(); i += 4) {
     String substring = sequence.substring(i, Math.min(i + 4, sequence.length()));
     int value = 0;
     for (int j = 0; j < 4; j++) {
       value += (j < substring.length() ? getSerializedDNABase(substring.charAt(j)) : 0);
       if (j != 3) {
         value <<= 2;
       }
     }
     out.writeByte(value);
   }
 }
 public void writeStructBin(
     DataOutput objBuffer, List<L2Property> struct, String structName, UnrealPackageReadOnly up)
     throws UnrealException {
   try {
     switch (structName) {
       case "Core.Object.Color":
         for (int i = 0; i < 4; i++) objBuffer.writeByte((Integer) struct.get(i).getAt(0));
         break;
       case "Core.Object.Vector":
         for (int i = 0; i < 3; i++) objBuffer.writeFloat((Float) struct.get(i).getAt(0));
         break;
       case "Core.Object.Rotator":
         for (int i = 0; i < 3; i++) objBuffer.writeInt((Integer) struct.get(i).getAt(0));
         break;
       case "Fire.FireTexture.Spark":
         for (int i = 0; i < 8; i++) objBuffer.writeByte((Integer) struct.get(i).getAt(0));
         break;
       default:
         throw new UnsupportedOperationException("not implemented"); // TODO
     }
   } catch (IOException e) {
     throw new UnrealException(e);
   }
 }
示例#14
0
 public static void writeRNASequence(RNASequence sequence, DataOutput out) throws IOException {
   int length = sequence.getLength();
   String string = sequence.getSequenceAsString();
   out.writeInt(length);
   for (int i = 0; i < length; i += 4) {
     String substring = string.substring(i, Math.min(i + 4, length));
     int value = 0;
     for (int j = 0; j < 4; j++) {
       value += (j < substring.length() ? getSerializedRNABase(substring.charAt(j)) : 0);
       if (j != 3) {
         value <<= 2;
       }
     }
     out.writeByte(value);
   }
 }
示例#15
0
 public void writeTo(DataOutput out) throws Exception {
   out.writeByte(type.ordinal());
   // We can't use Util.writeObject since it's size is limited to 2^15-1
   try {
     if (object instanceof Streamable) {
       out.writeShort(-1);
       Util.writeGenericStreamable((Streamable) object, out);
     } else {
       byte[] bytes = Util.objectToByteBuffer(object);
       out.writeInt(bytes.length);
       out.write(bytes);
     }
   } catch (IOException e) {
     throw e;
   } catch (Exception e) {
     throw new IOException("Exception encountered while serializing execution request", e);
   }
   out.writeLong(request);
 }
  /**
   * Write a compressed integer only supporting signed values. Formats are (with x representing
   * value bits):
   *
   * <PRE>
   * 1 Byte - 00xxxxxx                              Represents the value <= 63 (0x3f)
   * 2 Byte - 01xxxxxx xxxxxxxx                     Represents the value > 63 && <= 16383 (0x3fff)
   * 4 byte - 1xxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   Represents the value > 16383 && <= MAX_INT
   * </PRE>
   *
   * @exception IOException value is negative or an exception was thrown by a method on out.
   */
  public static final int writeInt(DataOutput out, int value) throws IOException {

    if (value < 0) throw new IOException();

    if (value <= 0x3f) {

      out.writeByte(value);
      return 1;
    }

    if (value <= 0x3fff) {

      out.writeByte(0x40 | (value >>> 8));
      out.writeByte(value & 0xff);
      return 2;
    }

    out.writeByte(((value >>> 24) | 0x80) & 0xff);
    out.writeByte((value >>> 16) & 0xff);
    out.writeByte((value >>> 8) & 0xff);
    out.writeByte((value) & 0xff);
    return 4;
  }
  private void write(
      DataOutput objBuffer,
      Property template,
      Object obj,
      AtomicBoolean array,
      AtomicReference<String> structName,
      AtomicReference<Type> type,
      UnrealPackageReadOnly up)
      throws IOException {
    if (template instanceof ByteProperty) {
      System.out.println(template.getEntry().getObjectInnerFullName() + " [BYTE]");
      objBuffer.writeByte((Integer) obj);
    } else if (template instanceof IntProperty) {
      System.out.println(template.getEntry().getObjectInnerFullName() + " [INT]");
      objBuffer.writeInt((Integer) obj);
    } else if (template instanceof BoolProperty) {
      System.out.println(template.getEntry().getObjectInnerFullName() + " [BOOL]");
      array.set((Boolean) obj);
    } else if (template instanceof FloatProperty) {
      System.out.println(template.getEntry().getObjectInnerFullName() + " [FLOAT]");
      objBuffer.writeFloat((Float) obj);
    } else if (template instanceof ObjectProperty) {
      System.out.println(template.getEntry().getObjectInnerFullName() + " [OBJ]");
      objBuffer.writeCompactInt((Integer) obj);
    } else if (template instanceof NameProperty) {
      System.out.println(template.getEntry().getObjectInnerFullName() + " [NAME]");
      objBuffer.writeCompactInt((Integer) obj);
    } else if (template instanceof ArrayProperty) {
      System.out.println(template.getEntry().getObjectInnerFullName() + " [ARRAY]");
      ArrayProperty arrayProperty = (ArrayProperty) template;

      List<Object> arrayList = (List<Object>) obj;
      objBuffer.writeCompactInt(arrayList.size());

      UnrealPackageReadOnly.ExportEntry arrayInner =
          (UnrealPackageReadOnly.ExportEntry) arrayProperty.getInner();
      String a = arrayInner.getObjectClass().getObjectName().getName();
      try {
        Class<? extends Property> pc =
            Class.forName("acmi.l2.clientmod.unreal." + a).asSubclass(Property.class);
        Property f =
            pc.getConstructor(
                    ByteBuffer.class, UnrealPackageReadOnly.ExportEntry.class, PropertiesUtil.class)
                .newInstance(
                    ByteBuffer.wrap(arrayInner.getObjectRawDataExternally())
                        .order(ByteOrder.LITTLE_ENDIAN),
                    arrayInner,
                    this);

        for (Object arrayObj : arrayList) {
          write(
              objBuffer,
              f,
              arrayObj,
              new AtomicBoolean(),
              new AtomicReference<>(),
              new AtomicReference<>(),
              up);
        }
      } catch (ReflectiveOperationException e) {
        throw new RuntimeException(e);
      }
    } else if (template instanceof StructProperty) {
      System.out.println(template.getEntry().getObjectInnerFullName() + " [STRUCT]");
      StructProperty structProperty = (StructProperty) template;
      structName.set(structProperty.getStructType().getObjectName().getName());
      writeStruct(objBuffer, structName.get(), up, (List<L2Property>) obj);
      //            if (false) { //Not used in L2?
      //                switch (structName.get()) {
      //                    case "Vector":
      //                        type.set(Type.VECTOR);
      //                        break;
      //                    case "Rotator":
      //                        type.set(Type.ROTATOR);
      //                        break;
      //                }
      //            }
    } else if (template instanceof StrProperty) {
      System.out.println(template.getEntry().getObjectInnerFullName() + " [STR]");
      objBuffer.writeLine((String) obj);
    } else {
      throw new UnsupportedOperationException(
          template.getClass().getSimpleName() + " serialization not implemented");
    }
  }
  /**
   * Write a compressed long only supporting signed values.
   *
   * <p>Formats are (with x representing value bits):
   *
   * <PRE>
   * 2 byte - 00xxxxxx xxxxxxxx                     Represents the value <= 16383 (0x3fff)
   * 4 byte - 01xxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   Represents the value > 16383  && <= 0x3fffffff
   * 8 byte - 1xxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   Represents the value > 0x3fffffff && <= MAX_LONG
   * </PRE>
   *
   * @exception IOException value is negative or an exception was thrown by a method on out.
   */
  public static final int writeLong(DataOutput out, long value) throws IOException {

    if (value < 0) throw new IOException();

    if (value <= 0x3fff) {

      out.writeByte((int) ((value >>> 8) & 0xff));
      out.writeByte((int) ((value) & 0xff));
      return 2;
    }

    if (value <= 0x3fffffff) {

      out.writeByte((int) (((value >>> 24) | 0x40) & 0xff));
      out.writeByte((int) ((value >>> 16) & 0xff));
      out.writeByte((int) ((value >>> 8) & 0xff));
      out.writeByte((int) ((value) & 0xff));
      return 4;
    }

    out.writeByte((int) (((value >>> 56) | 0x80) & 0xff));
    out.writeByte((int) ((value >>> 48) & 0xff));
    out.writeByte((int) ((value >>> 40) & 0xff));
    out.writeByte((int) ((value >>> 32) & 0xff));
    out.writeByte((int) ((value >>> 24) & 0xff));
    out.writeByte((int) ((value >>> 16) & 0xff));
    out.writeByte((int) ((value >>> 8) & 0xff));
    out.writeByte((int) ((value) & 0xff));
    return 8;
  }
 public void toData(DataOutput out) throws IOException {
   out.writeByte(this.interestPolicy.ordinal);
 }
示例#20
0
 public void writeTo(DataOutput out) throws Exception {
   out.writeByte(type);
   out.writeShort(version.length);
   out.write(version);
 }
 void write(DataOutput dos) throws IOException {
   for (Tag tag : tags.values()) {
     Tag.writeNamedTag(tag, dos);
   }
   dos.writeByte(Tag.TAG_End);
 }
示例#22
0
 void writeTagContents(DataOutput dataoutput) throws IOException {
   dataoutput.writeByte(byteValue);
 }
示例#23
0
  @Override
  public void write(DataOutput out) throws IOException {
    int numCol = colType.length;
    boolean[] nullBits = new boolean[numCol];
    int[] colLength = new int[numCol];
    byte[] enumType = new byte[numCol];
    int[] padLength = new int[numCol];
    byte[] padbytes = new byte[8];

    /**
     * Compute the total payload and header length header = total length (4 byte), Version (2 byte),
     * Error (1 byte), #col (2 byte) col type array = #col * 1 byte null bit array = ceil(#col/8)
     */
    int datlen = 4 + 2 + 1 + 2;
    datlen += numCol;
    datlen += getNullByteArraySize(numCol);

    for (int i = 0; i < numCol; i++) {
      /* Get the enum type */
      DBType coldbtype;
      switch (DataType.get(colType[i])) {
        case BIGINT:
          coldbtype = DBType.BIGINT;
          break;
        case BOOLEAN:
          coldbtype = DBType.BOOLEAN;
          break;
        case FLOAT8:
          coldbtype = DBType.FLOAT8;
          break;
        case INTEGER:
          coldbtype = DBType.INTEGER;
          break;
        case REAL:
          coldbtype = DBType.REAL;
          break;
        case SMALLINT:
          coldbtype = DBType.SMALLINT;
          break;
        case BYTEA:
          coldbtype = DBType.BYTEA;
          break;
        default:
          coldbtype = DBType.TEXT;
      }
      enumType[i] = (byte) (coldbtype.ordinal());

      /* Get the actual value, and set the null bit */
      if (colValue[i] == null) {
        nullBits[i] = true;
        colLength[i] = 0;
      } else {
        nullBits[i] = false;

        /*
         * For fixed length type, we get the fixed length.
         * For var len binary format, the length is in the col value.
         * For text format, we must convert encoding first.
         */
        if (!coldbtype.isVarLength()) {
          colLength[i] = coldbtype.getTypeLength();
        } else if (!isTextForm(colType[i])) {
          colLength[i] = ((byte[]) colValue[i]).length;
        } else {
          colLength[i] = ((String) colValue[i]).getBytes(CHARSET).length;
        }

        /* calculate and add the type alignment padding */
        padLength[i] = roundUpAlignment(datlen, coldbtype.getAlignment()) - datlen;
        datlen += padLength[i];

        /* for variable length type, we add a 4 byte length header */
        if (coldbtype.isVarLength()) {
          datlen += 4;
        }
      }
      datlen += colLength[i];
    }

    /*
     * Add the final alignment padding for the next record
     */
    int endpadding = roundUpAlignment(datlen, 8) - datlen;
    datlen += endpadding;

    /* Construct the packet header */
    out.writeInt(datlen);
    out.writeShort(VERSION);
    out.writeByte(errorFlag);
    out.writeShort(numCol);

    /* Write col type */
    for (int i = 0; i < numCol; i++) {
      out.writeByte(enumType[i]);
    }

    /* Nullness */
    byte[] nullBytes = boolArrayToByteArray(nullBits);
    out.write(nullBytes);

    /* Column Value */
    for (int i = 0; i < numCol; i++) {
      if (!nullBits[i]) {
        /* Pad the alignment byte first */
        if (padLength[i] > 0) {
          out.write(padbytes, 0, padLength[i]);
        }

        /* Now, write the actual column value */
        switch (DataType.get(colType[i])) {
          case BIGINT:
            out.writeLong(((Long) colValue[i]));
            break;
          case BOOLEAN:
            out.writeBoolean(((Boolean) colValue[i]));
            break;
          case FLOAT8:
            out.writeDouble(((Double) colValue[i]));
            break;
          case INTEGER:
            out.writeInt(((Integer) colValue[i]));
            break;
          case REAL:
            out.writeFloat(((Float) colValue[i]));
            break;
          case SMALLINT:
            out.writeShort(((Short) colValue[i]));
            break;

            /* For BYTEA format, add 4byte length header at the beginning  */
          case BYTEA:
            out.writeInt(colLength[i]);
            out.write((byte[]) colValue[i]);
            break;

            /* For text format, add 4byte length header. string is already '\0' terminated */
          default:
            {
              out.writeInt(colLength[i]);
              byte[] data = ((String) colValue[i]).getBytes(CHARSET);
              out.write(data);
              break;
            }
        }
      }
    }

    /* End padding */
    out.write(padbytes, 0, endpadding);
  }
示例#24
0
  public void write(DataOutput out) throws InvalidByteCodeException, IOException {

    out.writeByte(CONSTANT_INTEGER);
    super.write(out);
    if (debug) debug("wrote ");
  }