Java ByteBuffer Read readSize(ByteBuffer buffer)

Here you can find the source of readSize(ByteBuffer buffer)

Description

read Size

License

Open Source License

Declaration

public final static int readSize(ByteBuffer buffer) 

Method Source Code

//package com.java2s;
/**/*ww w.j a  va2  s .co  m*/
 * Copyright - See the COPYRIGHT that is included with this distribution.
 * EPICS pvData is distributed subject to a Software License Agreement found
 * in file LICENSE that is included with this distribution.
 */

import java.nio.ByteBuffer;

public class Main {
    public final static int readSize(ByteBuffer buffer) {
        final byte b = buffer.get();
        if (b == -1)
            return -1;
        else if (b == -2) {
            final int s = buffer.getInt();
            if (s < 0)
                throw new RuntimeException("negative array size");
            return s;
        } else
            return (int) (b < 0 ? b + 256 : b);
    }
}

Related

  1. readShortLength(ByteBuffer bb)
  2. readShorts(final ByteBuffer bb, final int length)
  3. readShortString(ByteBuffer buffer)
  4. readSignedVarint(ByteBuffer buffer)
  5. readSize(ByteBuffer buf)
  6. readSmart(ByteBuffer buffer)
  7. readToBytes(ByteBuffer byteBuffer)
  8. readTs(ByteBuffer is)
  9. readTs(ByteBuffer is, int c)