集册 Java实例教程 读取24位数组长度,后跟实际数组数据。

读取24位数组长度,后跟实际数组数据。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

388
读取24位数组长度,后跟实际数组数据。


import java.io.IOException;/*来自 时代Java - nowjava.com*/

import java.io.InputStream;

import java.nio.ByteBuffer;

import java.util.Iterator;

import org.apache.log4j.Logger;


public class Main{

    /**

     * Reads an 24 bit array length followed by the actual array data.

     * 

     * @param buf

     * @return the array read

     */

    final static public byte[] readArray24(ByteBuffer buf) {

        int length = getUnsigned24(buf);

        byte[] array = new byte[length];

        buf.get(array);

        return array;

    }/*nowjava*/

    /**

     * Return 24 unsigned bits as an integer. Big endian.

     * 

     * @param buf

     * @return

     */

    final public static int getUnsigned24(ByteBuffer buf) {

        
展开阅读全文