Here you can find the source of readUnsignedShort(ByteBuffer bb)
readUnsignedShort
method of DataInput
.
Parameter | Description |
---|---|
bb | bb |
public static int readUnsignedShort(ByteBuffer bb) throws BufferUnderflowException
//package com.java2s; /**/* w w w .j av a 2 s .c o m*/ * Copyright 2009 DFKI GmbH. * All Rights Reserved. Use is subject to license terms. * * This file is part of MARY TTS. * * MARY TTS is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3 of the License. * * This program 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; public class Main { /** * See the general contract of the <code>readUnsignedShort</code> method of <code>DataInput</code>. * <p> * Bytes for this operation are read from the given byte buffer * * @param bb * bb * @return the next two bytes of this input stream, interpreted as an unsigned 16-bit integer. * @exception BufferUnderflowException * if this input stream reaches the end before reading two bytes. * @see java.io.FilterInputStream#in */ public static int readUnsignedShort(ByteBuffer bb) throws BufferUnderflowException { int ch1 = bb.get() & 0xFF; // convert byte to unsigned byte int ch2 = bb.get() & 0xFF; // convert byte to unsigned byte return (ch1 << 8) + (ch2 << 0); } }