Example usage for com.google.common.io LittleEndianDataInputStream readUnsignedShort

List of usage examples for com.google.common.io LittleEndianDataInputStream readUnsignedShort

Introduction

In this page you can find the example usage for com.google.common.io LittleEndianDataInputStream readUnsignedShort.

Prototype

@Override
public int readUnsignedShort() throws IOException 

Source Link

Document

Reads an unsigned short as specified by DataInputStream#readUnsignedShort() , except using little-endian byte order.

Usage

From source file:pw.simplyintricate.bitcoin.models.datastructures.VariableInteger.java

public static VariableInteger fromInputStream(LittleEndianDataInputStream reader) throws IOException {
    byte determiningSize = reader.readByte();
    UnsignedInteger value;/* w w w  .ja  v a2  s  . c  o  m*/
    if (determiningSize < 0xfd) {
        value = UnsignedInteger.fromIntBits(determiningSize);
    } else if (determiningSize <= 0xffff) {
        int followUpValue = reader.readUnsignedShort();
        value = UnsignedInteger.fromIntBits(followUpValue);
    } else if (determiningSize <= 0xffffffff) {
        int followUpValue = reader.readInt();
        value = UnsignedInteger.valueOf(followUpValue);
    } else {
        long followUpValue = reader.readLong();
        value = UnsignedInteger.valueOf(followUpValue);
    }

    VariableInteger variableInteger = new VariableInteger(value);

    return variableInteger;
}

From source file:pw.simplyintricate.bitcoin.models.datastructures.NetworkAddress.java

public static NetworkAddress fromInputStream(LittleEndianDataInputStream reader, boolean readTime)
        throws IOException {
    int time = -1;
    if (readTime) {
        time = reader.readInt();/*from www  .  j a va2s .c  o  m*/
    }

    long services = reader.readLong();
    reader.skip(12); // skip ipv6 support :(
    byte[] ipAddress = new byte[4];
    reader.read(ipAddress, 0, 4);
    short port = EndianUtils.swapShort(((short) reader.readUnsignedShort()));

    NetworkAddress networkAddress;
    if (readTime) {
        networkAddress = new NetworkAddress(UnsignedInteger.valueOf(services), ipAddress, port,
                UnsignedInteger.fromIntBits(time));
    } else {
        networkAddress = new NetworkAddress(UnsignedInteger.valueOf(services), ipAddress, port);
    }

    return networkAddress;
}