List of usage examples for java.nio ByteBuffer getInt
public abstract int getInt();
From source file:com.healthmarketscience.jackcess.impl.office.EncryptionHeader.java
public EncryptionHeader(ByteBuffer buffer) { // OC: 2.3.2 EncryptionHeader Structure _flags = buffer.getInt(); _sizeExtra = buffer.getInt();/*w w w .jav a2s. c o m*/ int algId = buffer.getInt(); int algIdHash = buffer.getInt(); int keySize = buffer.getInt(); _providerType = buffer.getInt(); // determine encryption algorithm _cryptoAlg = parseCryptoAlgorithm(algId, _flags); // determine hash algorithm _hashAlg = parseHashAlgorithm(algIdHash, _flags); // reserved buffer.getInt(); buffer.getInt(); _cspName = readCspName(buffer); _keySize = parseKeySize(keySize, _cryptoAlg, _cspName); }
From source file:com.offbynull.portmapper.natpmp.TcpMappingNatPmpResponse.java
/** * Constructs a {@link TcpMappingNatPmpResponse} object by parsing a buffer. * @param buffer buffer containing PCP response data * @throws NullPointerException if any argument is {@code null} * @throws BufferUnderflowException if not enough data is available in {@code buffer} * @throws IllegalArgumentException if the version doesn't match the expected version (must always be {@code 0}), or if the op * {@code != 129}, or if external port in the buffer is {@code < 1 || > 65535}, or if there's an unsuccessful/unrecognized result code *///from w w w . ja va 2 s .co m public TcpMappingNatPmpResponse(ByteBuffer buffer) { super(buffer); Validate.isTrue(getOp() == 130); internalPort = buffer.getShort() & 0xFFFF; externalPort = buffer.getShort() & 0xFFFF; lifetime = buffer.getInt() & 0xFFFFFFFFL; Validate.inclusiveBetween(0, 65535, externalPort); }
From source file:com.offbynull.portmapper.natpmp.UdpMappingNatPmpResponse.java
/** * Constructs a {@link UdpMappingNatPmpResponse} object by parsing a buffer. * @param buffer buffer containing PCP response data * @throws NullPointerException if any argument is {@code null} * @throws BufferUnderflowException if not enough data is available in {@code buffer} * @throws IllegalArgumentException if the version doesn't match the expected version (must always be {@code 0}), or if the op * {@code != 129}, or if external port in the buffer is {@code < 1 || > 65535}, or if there's an unsuccessful/unrecognized result code *///from ww w. j a va2s . co m public UdpMappingNatPmpResponse(ByteBuffer buffer) { super(buffer); Validate.isTrue(getOp() == 129); internalPort = buffer.getShort() & 0xFFFF; externalPort = buffer.getShort() & 0xFFFF; lifetime = buffer.getInt() & 0xFFFFFFFFL; Validate.inclusiveBetween(0, 65535, externalPort); // 0 valid for deletion }
From source file:org.springframework.integration.support.json.EmbeddedJsonHeadersMessageMapper.java
@Nullable private Message<?> decodeNativeFormat(byte[] bytes, @Nullable Map<String, Object> headersToAdd) throws IOException { ByteBuffer buffer = ByteBuffer.wrap(bytes); if (buffer.remaining() > 4) { int headersLen = buffer.getInt(); if (headersLen >= 0 && headersLen < buffer.remaining() - 4) { buffer.position(headersLen + 4); int payloadLen = buffer.getInt(); if (payloadLen != buffer.remaining()) { return null; } else { buffer.position(4);// w w w . j a v a2 s . c om @SuppressWarnings("unchecked") Map<String, Object> headers = this.objectMapper.readValue(bytes, buffer.position(), headersLen, HashMap.class); buffer.position(buffer.position() + headersLen); buffer.getInt(); Object payload; byte[] payloadBytes = new byte[payloadLen]; buffer.get(payloadBytes); payload = payloadBytes; if (headersToAdd != null) { headersToAdd.forEach(headers::putIfAbsent); } return new GenericMessage<>(payload, new MutableMessageHeaders(headers)); } } } return null; }
From source file:de.unibayreuth.bayeos.goat.table.MassenTableModel.java
public boolean load(ObjektNode objekt, TimeFilter tFilter, StatusFilter sFilter) { try {//from w w w.j a va2 s .com Vector params = new Vector(); params.add(objekt.getId()); params.add(tFilter.getVector()); params.add(sFilter.getVector()); Vector vReturn = (Vector) xmlClient.execute("MassenTableHandler.getRows", params); // Rows als byte[] byte[] ba = (byte[]) vReturn.elementAt(1); statusList = new ArrayByteList(ba.length / rowLength); vonList = new ArrayIntList(ba.length / rowLength); wertList = new ArrayDoubleList(ba.length / rowLength); ByteBuffer b = ByteBuffer.wrap(ba); while (b.hasRemaining()) { vonList.add(b.getInt()); wertList.add((double) b.getFloat()); statusList.add(b.get()); } vReturn = null; logger.debug("MassenTableModel filled with " + getRowCount() + " records."); return true; } catch (XmlRpcException e) { MsgBox.error(e.getMessage()); return false; } }
From source file:com.github.srgg.yads.impl.context.communication.AbstractTransport.java
protected final int onReceive(final String sender, final String recipient, final ByteBuffer bb) throws Exception { // -- decode//w w w . j av a 2s. c o m if (bb.remaining() < 4) { return 4; } bb.mark(); final int length = bb.getInt(); if (bb.remaining() < length) { bb.reset(); return length; } final byte msgCode = bb.get(); final byte[] p = new byte[length - 1]; bb.get(p); final Class<? extends Message> c = getMessageClass(msgCode); final Message msg = payloadMapper.fromBytes(c, p); // -- fire final Messages.MessageTypes mt = Messages.MessageTypes.valueOf(msgCode); if (logger.isTraceEnabled()) { logger.trace(MessageUtils.dumpMessage(msg, "[MSG IN] '%s' -> '%s': %s@%s", msg.getSender(), recipient, mt, msg.getId())); } else { logger.debug("[MSG IN] '{}' -> '{}': {}@{}", sender, recipient, mt, msg.getId()); } boolean isHandled = true; if (recipient != null) { final CommunicationContext.MessageListener listener = handlerById(recipient); checkState(listener != null, "Can't process received message '%s' sended by '%s', recipient '%s' is not registered.", msgCode, sender, recipient); isHandled = listener.onMessage(recipient, mt, msg); } else { for (Map.Entry<String, CommunicationContext.MessageListener> e : handlers()) { if (!e.getValue().onMessage(null, mt, msg)) { isHandled = false; } } } if (!isHandled) { unhandledMessage(sender, recipient, mt, msg); } return -1; }
From source file:edu.umass.cs.gigapaxos.paxosutil.PaxosPacketDemultiplexerFast.java
@Override public boolean isOrderPreserving(Object msg) { if (!ORDER_PRESERVING_REQUESTS) return false; if (msg instanceof PaxosPacket) return ((PaxosPacket) msg).getType() == PaxosPacketType.REQUEST; if (msg instanceof byte[]) { ByteBuffer bbuf = ByteBuffer.wrap((byte[]) msg, 0, 8); int type; if (bbuf.getInt() == PaxosPacket.PaxosPacketType.PAXOS_PACKET.getInt()) { type = bbuf.getInt();//from w w w . j av a 2s . c o m if (type == PaxosPacket.PaxosPacketType.REQUEST.getInt()) return true; } } // else assert (msg instanceof net.minidev.json.JSONObject); // only preserve order for REQUEST or PROPOSAL packets PaxosPacketType type = PaxosPacket.PaxosPacketType.getPaxosPacketType( ((Integer) ((net.minidev.json.JSONObject) msg).get(PaxosPacket.Keys.PT.toString()))); return (type != null && type.equals(PaxosPacket.PaxosPacketType.REQUEST)); }
From source file:com.netflix.aegisthus.pig.AegisthusLoadCaster.java
private long getNumber(byte[] arg0) throws Exception { byte[] by = hex.decode(arg0); ByteBuffer bb = ByteBuffer.allocate(by.length); bb.put(by);/* w ww . ja v a2 s .c om*/ bb.position(0); switch (by.length) { case 1: return (long) bb.get(); case 2: return (long) bb.getShort(); case 4: return (long) bb.getInt(); case 8: return (long) bb.getLong(); } throw new UnexpectedException("couldn't determine datatype"); }
From source file:com.streamsets.pipeline.lib.util.AvroSchemaHelper.java
/** * Checks for a magic byte in the data and if present extracts the schemaId * @param data byte array representing a kafka message * @return parsed schema ID// w w w . j av a2 s. c om */ public Optional<Integer> detectSchemaId(byte[] data) { if (data.length < 5) { return Optional.empty(); } ByteBuffer wrapped = ByteBuffer.wrap(data); // 5 == MAGIC_BYTE + ID_SIZE if (wrapped.get() != MAGIC_BYTE) { return Optional.empty(); } return Optional.of(wrapped.getInt()); }
From source file:io.gomint.server.network.packet.PacketLogin.java
@Override public void deserialize(PacketBuffer buffer) { this.protocol = buffer.readInt(); // Decompress inner data (i don't know why you compress inside of a Batched Packet but hey) byte[] compressed = new byte[buffer.readInt()]; buffer.readBytes(compressed);/*ww w.j a v a2 s. c o m*/ Inflater inflater = new Inflater(); inflater.setInput(compressed); ByteArrayOutputStream bout = new ByteArrayOutputStream(); try { byte[] comBuffer = new byte[1024]; while (!inflater.finished()) { int read = inflater.inflate(comBuffer); bout.write(comBuffer, 0, read); } } catch (DataFormatException e) { System.out.println("Failed to decompress batch packet" + e); return; } // More data please ByteBuffer byteBuffer = ByteBuffer.wrap(bout.toByteArray()); byteBuffer.order(ByteOrder.LITTLE_ENDIAN); byte[] stringBuffer = new byte[byteBuffer.getInt()]; byteBuffer.get(stringBuffer); // Decode the json stuff try { JSONObject jsonObject = (JSONObject) new JSONParser().parse(new String(stringBuffer)); JSONArray chainArray = (JSONArray) jsonObject.get("chain"); if (chainArray != null) { this.validationKey = parseBae64JSON((String) chainArray.get(chainArray.size() - 1)); // First key in chain is last response in chain #brainfuck :D for (Object chainObj : chainArray) { decodeBase64JSON((String) chainObj); } } } catch (ParseException e) { e.printStackTrace(); } // Skin comes next this.skin = new byte[byteBuffer.getInt()]; byteBuffer.get(this.skin); }