Here you can find the source of encodeByteArray(DataOutputStream out, byte[] bytes)
public static void encodeByteArray(DataOutputStream out, byte[] bytes) throws IOException
//package com.java2s; //License from project: Apache License import java.io.DataOutputStream; import java.io.IOException; public class Main { public static void encodeByteArray(DataOutputStream out, byte[] bytes) throws IOException { if (bytes == null) { out.writeInt(-1);//from w w w. j ava 2s .c om return; } out.writeInt(bytes.length); out.write(bytes); } }