public static void writeByteArray(byte[] array, int len, DataOutput out) throws IOException {

    InternalDataSerializer.checkOut(out);

    int length = len; // to avoid warnings about parameter assignment

    if (array == null) {
      length = -1;
    } else {
      if (length > array.length) {
        length = array.length;
      }
    }
    InternalDataSerializer.writeArrayLength(length, out);
    if (logger.isTraceEnabled(LogMarker.SERIALIZER_VERBOSE)) {
      logger.trace(LogMarker.SERIALIZER_VERBOSE, "Writing byte array of length {}", length);
    }
    if (length > 0) {
      out.write(array, 0, length);
    }
  }
Writes the first <code>len</code> elements of an array of <code>byte</code>s to a
<code>DataOutput</code>. This method will serialize a <code>null</code> array and not throw a
<code>NullPointerException</code>.

@param array the array of {@code byte}s to write
@param len the actual number of entries to write. If len is greater than then length of the
@param out the {@link DataOutput} to write to
       array then the entire array is written.
@throws IOException A problem occurs while writing to <code>out</code>

@see #readByteArray
geode-core/src/main/java/org/apache/geode/DataSerializer.java