Here you can find the source of getModularShort(ByteBuffer bb)
Parameter | Description |
---|---|
bb | Data given as a ByteBuffer |
public static int getModularShort(ByteBuffer bb)
//package com.java2s; /*//from w w w. j av a2 s.c o m * JGrass - Free Open Source Java GIS http://www.jgrass.org * (C) HydroloGIS - www.hydrologis.com * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Library General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) any * later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more * details. * * You should have received a copy of the GNU Library General Public License * along with this library; if not, write to the Free Foundation, Inc., 59 * Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.Vector; public class Main { /** * Read a int value (the size of a modular short) from a ByteBuffer * * @param bb Data given as a ByteBuffer * @return int Size of the modular short */ public static int getModularShort(ByteBuffer bb) { Vector shorts = new Vector(); bb.order(ByteOrder.BIG_ENDIAN); short shortt = bb.getShort(); int size = 0; while ((shortt & 0x80) > 0) { shorts.add(new Short(shortt)); shortt = bb.getShort(); } shorts.add(new Short(shortt)); for (int i = 0; i < shorts.size(); i++) { shortt = ((Short) shorts.get(i)).shortValue(); shorts.set(i, new Integer(((shortt & 0xff00) >> 8) | ((shortt & 0xff) << 8))); } int slen = shorts.size(); if (slen == 1) { size = (((Integer) shorts.get(0)).intValue()) & 0x7fff;//(new Integer(((Integer)shorts.get(0)).shortValue() & 0x7fff)).byteValue(); } else if (slen == 2) { int tmp = ((Integer) shorts.get(0)).intValue(); shorts.set(0, shorts.get(1)); shorts.set(1, new Integer(tmp)); size = (((((Integer) shorts.get(0)).intValue()) & 0x7fff) << 15) | (((((Integer) shorts.get(1)).intValue()) & 0x7fff));//(new Integer(((Integer)shorts.get(0)).shortValue() & 0x7fff)).byteValue(); } else { System.out.println("Unexpected array length: " + slen); } return size; } }