Serialize the given data.<p>

@param data the data to serialize

@return byte[] the serailized data

@throws IOException if something goes wrong
426422
public static byte[] dataSerialize(Object data) throws IOException {

        if (isParseable(data.getClass())) {
            return format(data).getBytes();
        }

        // serialize the data
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        ObjectOutputStream oout = new ObjectOutputStream(bout);
        Object obj = data;
        if (data instanceof Map) {
            Hashtable<Object, Object> ht = new Hashtable<Object, Object>();
            @SuppressWarnings("unchecked")
            Iterator<Entry<Object, Object>> it = ((Map<Object, Object>)data).entrySet().iterator();
            while (it.hasNext()) {
                Entry<Object, Object> entry = it.next();
                if ((entry.getKey() != null) && (entry.getValue() != null)) {
                    ht.put(entry.getKey(), entry.getValue());
                }
            }
            obj = ht;
        }
        oout.writeObject(obj);
        oout.close();
        return bout.toByteArray();
    }
1182540
public static byte[] serialize(Object obj) throws IOException {
    if (obj == null) {
      return null;
    }
    try (ByteArrayOutputStream b = new ByteArrayOutputStream()) {
      try (ObjectOutputStream o = new ObjectOutputStream(b)) {
        o.writeObject(obj);
      }
      return b.toByteArray();
    }
  }
671201
public static byte[] serializeLong(Long data) {
    if (data == null) {
      return null;
    }

    return new byte[] {
        (byte) (data >>> 56),
        (byte) (data >>> 48),
        (byte) (data >>> 40),
        (byte) (data >>> 32),
        (byte) (data >>> 24),
        (byte) (data >>> 16),
        (byte) (data >>> 8),
        data.byteValue()
    };
  }
1373093
public byte[] serializeToBytes(final Serializable o) {
        byte[] bytes = null;
        try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
             final ObjectOutputStream oos = new ObjectOutputStream(baos)) {
            oos.writeObject(o);
            oos.flush();
            bytes = baos.toByteArray();
        } catch (final IOException e) {
            logger.warn("cannot Java serialize object", e);
        }
        return bytes;
    }
869038
protected final SerializedData serialize(final SerializedDataType type, final Object data) {
        return EscSpiUtils.serialize(serRegistry, type, data);
    }
467781
@SuppressWarnings("unchecked")
    public BaseBo fromByteArray(byte[] data) {
        Map<String, Object> dataMap = null;
        try {
            dataMap = data != null ? SerializationUtils.fromByteArray(data, Map.class) : null;
        } catch (Exception e) {
            dataMap = null;
        }
        return fromMap(dataMap);
    }
1346895
@SuppressWarnings("unchecked")
    public static Map<String, Object> bytesToDocument(byte[] data) {
        return data != null && data.length > 0
                ? SerializationUtils.fromByteArrayFst(data, Map.class)
                : null;
    }
205951
public void setData(byte[] data) throws IOException {
        output = new ByteArrayOutputStream();
        output.write(data);
        output.flush();
        setContentLength(output.size());
    }
293238
public static StringBuffer encode(byte[] data)
	{
		int rem = data.length % 3;
		int num = data.length / 3;
		StringBuffer result = new StringBuffer();
		int p = 0;
		// int c=0;

		for (int i = 0; i < num; i++)
		{
			int b1 = (data[p] & 0xfc) >> 2;
			int b2 = (data[p] & 0x03) << 4 | (data[p + 1] & 0xf0) >> 4;
			int b3 = (data[p + 1] & 0x0f) << 2 | (data[p + 2] & 0xc0) >> 6;
			int b4 = data[p + 2] & 0x3f;

			result.append(b64encode(b1));
			result.append(b64encode(b2));
			result.append(b64encode(b3));
			result.append(b64encode(b4));

			p += 3;
			// c += 4;
		}

		switch (rem)
		{
			case 0:
				break;

			case 1:
			{
				int b1 = (data[p] & 0xfc) >> 2;
				int b2 = (data[p] & 0x03) << 4;

				result.append(b64encode(b1));
				result.append(b64encode(b2));
				result.append('=');
				result.append('=');
				break;
			}

			case 2:
			{
				int b1 = (data[p] & 0xfc) >> 2;
				int b2 = (data[p] & 0x03) << 4 | (data[p + 1] & 0xf0) >> 4;
				int b3 = (data[p + 1] & 0x0f) << 2;

				result.append(b64encode(b1));
				result.append(b64encode(b2));
				result.append(b64encode(b3));
				result.append('=');
				break;
			}
		}

		return result;
	}
44923
public static byte[] decompress(byte[] data) throws Exception {
		ByteArrayInputStream bais = new ByteArrayInputStream(data);
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		decompress(bais, baos);
		data = baos.toByteArray();
		baos.flush();
		baos.close();
		bais.close();
		return data;
	}
258229
public static byte[] compress(byte[] data) throws Exception {
		ByteArrayInputStream bais = new ByteArrayInputStream(data);
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		compress(bais, baos);
		byte[] output = baos.toByteArray();
		baos.flush();
		baos.close();
		bais.close();
		return output;
	}
438113
@Override
    public byte[] decode(final String data) {
        return data != null ? data.getBytes(CHARSET) : null;
    }
905034
public void fromBytes(byte[] data) {
        int index = 0;
        // 1. read field count
        fieldCount = data[index];
        index++;
        // 2. read warning count
        this.warningCount = ByteHelper.readUnsignedShortLittleEndian(data, index);
        index += 2;
        // 3. read status flag
        this.statusFlag = ByteHelper.readUnsignedShortLittleEndian(data, index);
        // end read
    }
1088133
public static byte[] toBytes(final long data) {
    return new byte[]{
      (byte) (data >> 56 & 0xFF),
      (byte) (data >> 48 & 0xFF),
      (byte) (data >> 40 & 0xFF),
      (byte) (data >> 32 & 0xFF),
      (byte) (data >> 24 & 0xFF),
      (byte) (data >> 16 & 0xFF),
      (byte) (data >> 8 & 0xFF),
      (byte) (data & 0xFF)};
  }
715718
protected static byte[] getData(byte[] data, int size) {
        if (data == null) {
            return NO_DATA;
        }
        if (data.length <= size) {
            return data;
        }
        byte[] newData = new byte[size];
        System.arraycopy(data, 0, newData, 0, size);
        return newData;
    }
1343835
public static final byte[] compress(byte[] data, int level) throws IOException {
		final Deflater deflater = new Deflater(level, true);
		deflater.setInput(data);
		deflater.finish();
		final byte[] buffer = new byte[data.length + 128];
		final int length = deflater.deflate(buffer);
		final byte[] compressed = new byte[length];
		System.arraycopy(buffer, 0, compressed, 0, length);
		return compressed;
	}
845094
@Override
  public T decode(final byte[] data) {
    final WakeTuplePBuf tuple;
    try {
      tuple = WakeTuplePBuf.parseFrom(data);
    } catch (final InvalidProtocolBufferException e) {
      e.printStackTrace();
      throw new RemoteRuntimeException(e);
    }

    final String className = tuple.getClassName();
    final byte[] message = tuple.getData().toByteArray();
    final Class<?> clazz;
    try {
      clazz = Class.forName(className);
    } catch (final ClassNotFoundException e) {
      e.printStackTrace();
      throw new RemoteRuntimeException(e);
    }
    return clazzToDecoderMap.get(clazz).decode(message);
  }