List of usage examples for java.nio ByteBuffer getShort
public abstract short getShort();
From source file:ByteString.java
public void retrieve(ByteBuffer bb) { short n = bb.getShort(); if (n > 0) { bytes = new byte[n]; bb.get(bytes);//from www. jav a 2 s .c om } else { bytes = null; } }
From source file:de.rwhq.serializer.FixedStringSerializer.java
@Override public String deserialize(final byte[] o) { final ByteBuffer buf = ByteBuffer.wrap(o); final short length = buf.getShort(); final byte[] bytes = new byte[length]; buf.get(bytes);// w ww . j ava 2 s.c o m return new String(bytes); }
From source file:au.org.ala.layers.grid.GridCacheBuilder.java
static void nextRowOfFloats(float[] row, String datatype, boolean byteOrderLSB, int ncols, RandomAccessFile raf, byte[] b, float noDataValue) throws IOException { int size = 4; if (datatype.charAt(0) == 'U') { size = 1;/*from w w w . j a v a2 s .c om*/ } else if (datatype.charAt(0) == 'B') { size = 1; } else if (datatype.charAt(0) == 'S') { size = 2; } else if (datatype.charAt(0) == 'I') { size = 4; } else if (datatype.charAt(0) == 'L') { size = 8; } else if (datatype.charAt(0) == 'F') { size = 4; } else if (datatype.charAt(0) == 'D') { size = 8; } raf.read(b, 0, size * ncols); ByteBuffer bb = ByteBuffer.wrap(b); if (byteOrderLSB) { bb.order(ByteOrder.LITTLE_ENDIAN); } else { bb.order(ByteOrder.BIG_ENDIAN); } int i; int length = ncols; if (datatype.charAt(0) == 'U') { for (i = 0; i < length; i++) { float ret = bb.get(); if (ret < 0) { ret += 256; } row[i] = ret; } } else if (datatype.charAt(0) == 'B') { for (i = 0; i < length; i++) { row[i] = (float) bb.get(); } } else if (datatype.charAt(0) == 'S') { for (i = 0; i < length; i++) { row[i] = (float) bb.getShort(); } } else if (datatype.charAt(0) == 'I') { for (i = 0; i < length; i++) { row[i] = (float) bb.getInt(); } } else if (datatype.charAt(0) == 'L') { for (i = 0; i < length; i++) { row[i] = (float) bb.getLong(); } } else if (datatype.charAt(0) == 'F') { for (i = 0; i < length; i++) { row[i] = (float) bb.getFloat(); } } else if (datatype.charAt(0) == 'D') { for (i = 0; i < length; i++) { row[i] = (float) bb.getDouble(); } } else { logger.info("UNKNOWN TYPE: " + datatype); } for (i = 0; i < length; i++) { if (row[i] == noDataValue) { row[i] = Float.NaN; } } }
From source file:org.openhab.binding.ulux.internal.ump.messages.LuxMessage.java
public LuxMessage(final short actorId, final ByteBuffer data) { super((byte) 0x08, UluxMessageId.Lux, actorId, data); this.lux = data.getShort(); this.valid = data.get() == 0x01; }
From source file:org.openhab.binding.ulux.internal.ump.messages.EditValueMessage.java
public EditValueMessage(final short actorId, final ByteBuffer data) { super((byte) 0x06, UluxMessageId.EditValue, actorId, data); this.value = data.getShort(); }
From source file:com.spotify.heroic.metric.datastax.schema.legacy.MapSerializer.java
@Override public Map<A, B> deserialize(ByteBuffer buffer) throws IOException { final short len = buffer.getShort(); final Map<A, B> map = new LinkedHashMap<>(); for (short i = 0; i < len; i++) { final A key = next(buffer, a); final B value = next(buffer, b); if (value == null) { continue; }/*from w w w. j a va 2s. c o m*/ map.put(key, value); } return map; }
From source file:org.openhab.binding.ulux.internal.ump.messages.IdListMessage.java
public IdListMessage(final short actorId, final ByteBuffer data) { super((byte) 0x04, UluxMessageId.IdList, actorId, data); this.actorCount = data.getShort(); this.actors = new short[this.actorCount]; for (short i = 0; i < actorCount; i++) { this.actors[i] = data.getShort(); }//from w ww .j av a2 s . co m }
From source file:com.spotify.heroic.metric.datastax.schema.legacy.MapSerializer.java
private <T> T next(ByteBuffer buffer, TypeSerializer<T> serializer) throws IOException { final short segment = buffer.getShort(); final ByteBuffer slice = buffer.slice(); slice.limit(segment);/*from w w w. j ava 2s .co m*/ final T value = serializer.deserialize(slice); buffer.position(buffer.position() + segment); return value; }
From source file:net.jenet.Header.java
public void fromBuffer(ByteBuffer buffer) { peerID = buffer.getShort(); flags = buffer.get();//from w ww . j av a 2s. c o m commandCount = buffer.get(); sentTime = buffer.getInt(); challenge = buffer.getInt(); }
From source file:org.opendaylight.lispflowmapping.implementation.serializer.address.LispTrafficEngineeringLCAFAddressSerializer.java
@Override protected LcafTrafficEngineeringAddress deserializeData(ByteBuffer buffer, byte res2, short length) { List<Hops> hops = new ArrayList<Hops>(); while (length > 0) { byte flags = (byte) buffer.getShort(); boolean lookup = ByteUtil.extractBit(flags, Flags.LOOKUP); boolean RLOCProbe = ByteUtil.extractBit(flags, Flags.RLOC_PROBE); boolean strict = ByteUtil.extractBit(flags, Flags.STRICT); PrimitiveAddress address = LispAFIConvertor .toPrimitive(LispAddressSerializer.getInstance().deserialize(buffer)); HopsBuilder builder = new HopsBuilder(); builder.setLookup(lookup);//from w ww.j av a 2s .com builder.setRLOCProbe(RLOCProbe); builder.setStrict(strict); builder.setHop(new HopBuilder().setPrimitiveAddress(address).build()); length -= LispAddressSerializer.getInstance() .getAddressSize(LispAFIConvertor.toAFIfromPrimitive(address)) + 2; hops.add(builder.build()); } return new LcafTrafficEngineeringAddrBuilder().setAfi(AddressFamilyNumberEnum.LCAF.getIanaCode()) .setLcafType((short) LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING.getLispCode()).setHops(hops) .build(); }