Java examples for java.io:DataInput
Read a littleEndian short(16 bits) from DataInput
/*/*from w w w .jav a2 s . com*/ (C) Copyright 2015-2016 Alberto Fern?ndez <infjaf@gmail.com> (C) Copyright 2014 Jan Schl??in (C) Copyright 2003-2004 Anil Kumar K <anil@linuxense.com> This library 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; either version 3.0 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see <http://www.gnu.org/licenses/>. */ //package com.java2s; import java.io.DataInput; import java.io.IOException; public class Main { /** * Read a littleEndian short(16 bits) from DataInput * @param in DataInput to read from * @return short value of next 16 bits as littleEndian * @throws IOException */ public static short readLittleEndianShort(DataInput in) throws IOException { int low = in.readUnsignedByte() & 0xff; int high = in.readUnsignedByte(); return (short) (high << 8 | low); } }