metron-platform/metron-common/src/main/java/org/apache/metron/common/utils/SerDeUtils.java [135:244]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      if (!Util.isAndroid) {
        // Use ReflectASM if the class is not a non-static member class.
        Class enclosingType = type.getEnclosingClass();
        boolean isNonStaticMemberClass = enclosingType != null && type.isMemberClass()
                && !Modifier.isStatic(type.getModifiers());
        if (!isNonStaticMemberClass) {
          try {
            final ConstructorAccess access = ConstructorAccess.get(type);
            return new ObjectInstantiator() {
              @Override
              public Object newInstance () {
                try {
                  return access.newInstance();
                } catch (Exception ex) {
                  throw new KryoException("Error constructing instance of class: " + className(type), ex);
                }
              }
            };
          } catch (Exception ignored) {
          }
        }
      }
      // Reflection.
      try {
        Constructor ctor;
        try {
          ctor = type.getConstructor((Class[])null);
        } catch (Exception ex) {
          ctor = type.getDeclaredConstructor((Class[])null);
          ctor.setAccessible(true);
        }
        final Constructor constructor = ctor;
        return new ObjectInstantiator() {
          @Override
          public Object newInstance () {
            try {
              return constructor.newInstance();
            } catch (Exception ex) {
              throw new KryoException("Error constructing instance of class: " + className(type), ex);
            }
          }
        };
      } catch (Exception ignored) {
      }
      if (fallbackStrategy == null) {
        if (type.isMemberClass() && !Modifier.isStatic(type.getModifiers()))
          throw new KryoException("Class cannot be created (non-static member class): " + className(type));
        else
          throw new KryoException("Class cannot be created (missing no-arg constructor): " + className(type));
      }
      // InstantiatorStrategy.
      return fallbackStrategy.newInstantiatorOf(type);
    }
  }

  public static Serializer SERIALIZER = new Serializer();

  private static class Serializer implements Function<Object, byte[]>, Serializable {
    /**
     * Serializes the given Object into bytes.
     *
     */
    @Override
    public byte[] apply(Object o) {
      return toBytes(o);
    }
  }

  public static class Deserializer<T> implements Function<byte[], T>, Serializable {

    private Class<T> clazz;

    public Deserializer(Class<T> clazz) {
      this.clazz = clazz;
    }
    /**
     * Deserializes the given bytes.
     *
     * @param bytes the function argument
     * @return the function result
     */
    @Override
    public T apply(byte[] bytes) {
      return fromBytes(bytes, clazz);
    }
  }

  private SerDeUtils() {
    // do not instantiate
  }

  /**
   * Serialize a profile measurement's value.
   *
   * <p>The value produced by a Profile definition can be any numeric data type.  The data
   * type depends on how the profile is defined by the user.  The user should be able to
   * choose the data type that is most suitable for their use case.
   *
   * @param value The value to serialize.
   */
  public static byte[] toBytes(Object value) {
    try {
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      Output output = new Output(bos);
      kryo.get().writeClassAndObject(output, value);
      output.flush();
      bos.flush();
      return bos.toByteArray();
    }
    catch(Throwable t) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/common/utils/SerDeUtils.java [137:247]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      if (!Util.isAndroid) {
        // Use ReflectASM if the class is not a non-static member class.
        Class enclosingType = type.getEnclosingClass();
        boolean isNonStaticMemberClass = enclosingType != null && type.isMemberClass()
                && !Modifier.isStatic(type.getModifiers());
        if (!isNonStaticMemberClass) {
          try {
            final ConstructorAccess access = ConstructorAccess.get(type);
            return new ObjectInstantiator() {
              @Override
              public Object newInstance () {
                try {
                  return access.newInstance();
                } catch (Exception ex) {
                  throw new KryoException("Error constructing instance of class: " + className(type), ex);
                }
              }
            };
          } catch (Exception ignored) {
          }
        }
      }
      // Reflection.
      try {
        Constructor ctor;
        try {
          ctor = type.getConstructor((Class[])null);
        } catch (Exception ex) {
          ctor = type.getDeclaredConstructor((Class[])null);
          ctor.setAccessible(true);
        }
        final Constructor constructor = ctor;
        return new ObjectInstantiator() {
          @Override
          public Object newInstance () {
            try {
              return constructor.newInstance();
            } catch (Exception ex) {
              throw new KryoException("Error constructing instance of class: " + className(type), ex);
            }
          }
        };
      } catch (Exception ignored) {
      }
      if (fallbackStrategy == null) {
        if (type.isMemberClass() && !Modifier.isStatic(type.getModifiers()))
          throw new KryoException("Class cannot be created (non-static member class): " + className(type));
        else
          throw new KryoException("Class cannot be created (missing no-arg constructor): " + className(type));
      }
      // InstantiatorStrategy.
      return fallbackStrategy.newInstantiatorOf(type);
    }
  }

  public static Serializer SERIALIZER = new Serializer();

  private static class Serializer implements Function<Object, byte[]>, Serializable {
    /**
     * Serializes the given Object into bytes.
     *
     */
    @Override
    public byte[] apply(Object o) {
      return toBytes(o);
    }
  }

  public static class Deserializer<T> implements Function<byte[], T>, Serializable {

    private Class<T> clazz;

    public Deserializer(Class<T> clazz) {
      this.clazz = clazz;
    }
    /**
     * Deserializes the given bytes.
     *
     * @param bytes the function argument
     * @return the function result
     */
    @Override
    public T apply(byte[] bytes) {
      return fromBytes(bytes, clazz);
    }
  }


  private SerDeUtils() {
    // do not instantiate
  }

  /**
   * Serialize a profile measurement's value.
   *
   * The value produced by a Profile definition can be any numeric data type.  The data
   * type depends on how the profile is defined by the user.  The user should be able to
   * choose the data type that is most suitable for their use case.
   *
   * @param value The value to serialize.
   */
  public static byte[] toBytes(Object value) {
    try {
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      Output output = new Output(bos);
      kryo.get().writeClassAndObject(output, value);
      output.flush();
      bos.flush();
      return bos.toByteArray();
    }
    catch(Throwable t) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



