Java tutorial
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static void writeByteBuffer(byte[] buf, DataOutput out) throws Exception { writeByteBuffer(buf, 0, buf.length, out); } public static void writeByteBuffer(byte[] buf, int offset, int length, DataOutput out) throws Exception { if (buf != null) { out.write(1); out.writeInt(length); out.write(buf, offset, length); } else { out.write(0); } } }