Пример #1
0
 @Override
 public int hashCode() {
   int result = (int) length;
   result = 31 * result + (referencing != null ? referencing.hashCode() : 0);
   result = 31 * result + (isPersist ? 1 : 0);
   result = 31 * result + (allocationMode != null ? allocationMode.hashCode() : 0);
   return result;
 }
Пример #2
0
 @Override
 public void write(DataOutputStream out) throws IOException {
   if (length() >= Integer.MAX_VALUE)
     throw new IllegalArgumentException(
         "Length of data buffer can not be >= Integer.MAX_VALUE on output");
   out.writeUTF(allocationMode.name());
   out.writeInt((int) length());
   out.writeUTF(dataType().name());
   if (dataType() == Type.DOUBLE) {
     for (int i = 0; i < length(); i++) out.writeDouble(getDouble(i));
   } else if (dataType() == Type.INT) {
     for (int i = 0; i < length(); i++) out.writeInt(getInt(i));
   } else {
     for (int i = 0; i < length(); i++) out.writeFloat(getFloat(i));
   }
 }
Пример #3
0
  @Override
  public void read(DataInputStream s) {
    try {
      referencing = Collections.synchronizedSet(new HashSet<String>());
      dirty = new AtomicBoolean(false);
      allocationMode = AllocationMode.valueOf(s.readUTF());
      length = s.readInt();
      Type currentType = Type.valueOf(s.readUTF());
      type = globalType;
      if (currentType == Type.DOUBLE) elementSize = 8;
      else if (currentType == Type.FLOAT || currentType == Type.INT) elementSize = 4;
      if (currentType != globalType && currentType != Type.INT) {
        log.warn(
            "Loading a data stream with type different from what is set globally. Expect precision loss");
        if (globalType == Type.INT) log.warn("Int to float/double widening UNSUPPORTED!!!");
      }
      pointerIndexerByGlobalType(currentType);
      if (currentType == Type.DOUBLE) {
        for (int i = 0; i < length(); i++) {
          putByGlobalType(i, s.readDouble());
        }
      } else if (currentType == Type.FLOAT) {
        for (int i = 0; i < length(); i++) {
          putByGlobalType(i, s.readFloat());
        }
      } else {
        for (int i = 0; i < length(); i++) {
          putByGlobalType(i, s.readInt());
        }
      }
      wrappedBuffer = pointer.asByteBuffer();

    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }