writes the length of data as an 31 bit unsigned value, followed by the actual data. - Java File Path IO

Java examples for File Path IO:Byte Array

Description

writes the length of data as an 31 bit unsigned value, followed by the actual data.

Demo Code


import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.Iterator;
import org.apache.log4j.Logger;

public class Main{
    /**/*from w w w  .java 2s. com*/
     * writes the length of data as an 31 bit unsigned value, followed by the
     * actual data. does not check that the length of the data-array actually
     * fits in the lengths field.
     * 
     * @param buf
     * @param data
     */
    final static public void writeArray31(ByteBuffer buf, byte[] data) {
        buf.putInt((int) data.length);
        buf.put(data);
    }
}

Related Tutorials