Java Object Serialize and Deserialize deserializeShort(byte[] inbuf, int offset)

Here you can find the source of deserializeShort(byte[] inbuf, int offset)

Description

Deserialize a short, but do not convert it from little endian in the process

License

Open Source License

Parameter

Parameter Description
inbuf a parameter
offset a parameter

Return

short

Declaration

public static short deserializeShort(byte[] inbuf, int offset) 

Method Source Code


//package com.java2s;
/*/*  ww  w  .j a va 2  s .com*/
 *  PHEX - The pure-java Gnutella-servent.
 *  Copyright (C) 2001 - 2005 Phex Development Group
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 *  --- CVS Information ---
 *  $Id: IOUtil.java,v 1.36 2005/10/29 18:05:40 gregork Exp $
 */

import java.io.*;

public class Main {
    /**
     * Deserialize a short, but do not convert it from little endian in the process
     * @param inbuf
     * @param offset
     * @return short
     */
    public static short deserializeShort(byte[] inbuf, int offset) {
        return (short) ((inbuf[offset] & 0xff) << 8 | (inbuf[offset + 1] & 0xff));
    }

    /**
     * Deserialize a short, but do not convert it from little endian in the process
     * @param inStream
     * @return short
     */
    public static short deserializeShort(InputStream inStream) throws IOException {
        int a = (inStream.read() & 0xFF) << 8;
        int b = inStream.read() & 0xFF;
        return (short) (a | b);
    }
}

Related

  1. deserializeObjectFromByteArray(byte[] data)
  2. deserializeObjectFromByteArray(byte[] theSerializedVersion)
  3. deserializeProperties(byte[] bytes)
  4. deserializeRaw(byte[] array)
  5. deserializeSafe(byte[] buf, T obj)
  6. deserializeStream(final String witness)
  7. serializeAndDeserialize(Object o)
  8. serializeAndDeserialize(Object o)
  9. serializeAndDeserialize(Object obj)