List of usage examples for java.nio ByteBuffer getInt
public abstract int getInt();
From source file:org.cloudata.core.commitlog.pipe.Bulk.java
private boolean readHeader(ByteBuffer buf) throws IOException { ByteBuffer headerBuf = buf.duplicate(); if (seq < 0 && headerBuf.limit() >= readBytesLength) { headerBuf.position(0);//from w ww. j a v a 2s.c om seq = headerBuf.getInt(); if (seq == Constants.PIPE_DISCONNECT) { LOG.debug("receive PIPE_DISCONNECT"); throw new PipeClosing(); } readBytesLength += 4; } if (dirNameBytes == null && headerBuf.limit() >= readBytesLength) { headerBuf.position(readBytesLength - 4); int len = headerBuf.getInt(); if (len > 1000000) { throw new IOException("dirName byte length is too long [" + len + "]"); } dirNameBytes = new byte[len]; readBytesLength += len; } if (dirNameBytes != null && headerBuf.limit() >= readBytesLength) { headerBuf.position(readBytesLength - dirNameBytes.length); headerBuf.get(dirNameBytes); readBytesLength += 4; } if (headerAndPayloadSize == 0 && headerBuf.limit() >= readBytesLength) { headerBuf.position(readBytesLength - 4); headerAndPayloadSize = headerBuf.getInt(); return true; } return false; }
From source file:org.openhab.binding.hexabus.internal.HexaBusBinding.java
/** * Gets the consumption of the targetted plug in Watt. * // w w w . j a v a2 s .co m * @param target_ip the ip of the targetted plug * * @return the power consumption in Watt * @throws IOException */ private int getConsumption(InetAddress target_ip) { jackdaw_sock.connect(target_ip, PLUG_PORT); byte[] bmsg = HexBin.decode(GET_MESSAGE); byte[] receiveData = new byte[1024]; DatagramPacket outgoing = new DatagramPacket(bmsg, bmsg.length); DatagramPacket incoming = new DatagramPacket(receiveData, HEXABUS_RESPONSE_LENGTH); try { jackdaw_sock.send(outgoing); } catch (IOException e) { logger.debug("Send failed on Jackdaw Socket while trying to GET consumption!"); e.printStackTrace(); } try { jackdaw_sock.receive(incoming); } catch (IOException e) { logger.debug("Receive failed on Jackdaw Socket while trying to GET consumption!"); e.printStackTrace(); } byte[] data = incoming.getData(); // checks if no data was received. if (data.length == 0) { logger.debug("No data was transmitted in getConsumption!"); } // the last four bytes contain the consumption integer byte[] temp = { data[11], data[12], data[13], data[14] }; ByteBuffer wrapped = ByteBuffer.wrap(temp); int val = wrapped.getInt(); logger.debug("Power Consumption of hpp: " + val); return val; }
From source file:com.sm.store.client.RemoteClientImpl.java
public int getSeqNoInt(Key key) { StoreParas paras = getSequence(OpType.GetSeqNoInt, key); ByteBuffer buf = ByteBuffer.wrap((byte[]) paras.getValue().getData()); return buf.getInt(); }
From source file:au.org.ala.spatial.util.RecordsSmall.java
public int[] getUniqueIdx() throws Exception { File f = new File(filename + "records.csv.small.pointsUniqueIdx"); int size = (int) f.length() / 4; int[] all = new int[size]; byte[] e = FileUtils.readFileToByteArray(f); ByteBuffer bb = ByteBuffer.wrap(e); for (int i = 0; i < size; i++) { all[i] = bb.getInt(); }//from w w w . j a v a 2 s .co m return all; }
From source file:com.sm.store.client.RemoteClientImpl.java
@Override public int getSeqNoBlockInt(Key key, int block) { StoreParas paras = getSequence(OpType.GetSeqNoBlockInt, key, block); ByteBuffer buf = ByteBuffer.wrap((byte[]) paras.getValue().getData()); return buf.getInt(); }
From source file:edu.umass.cs.gigapaxos.paxospackets.AcceptReplyPacket.java
/** * @param bbuf/*from w w w . j av a 2 s. co m*/ * @throws UnsupportedEncodingException * @throws UnknownHostException */ public AcceptReplyPacket(ByteBuffer bbuf) throws UnsupportedEncodingException, UnknownHostException { super(bbuf); int paxosIDLength = this.getPaxosID().getBytes(CHARSET).length; assert (bbuf.position() == SIZEOF_PAXOSPACKET_FIXED + paxosIDLength); this.acceptor = bbuf.getInt(); this.ballot = new Ballot(bbuf.getInt(), bbuf.getInt()); this.slotNumber = bbuf.getInt(); this.maxCheckpointedSlot = bbuf.getInt(); this.requestID = bbuf.getLong(); if (bbuf.get() == (byte) 1) this.setDigestRequest(); assert (bbuf.position() == SIZEOF_PAXOSPACKET_FIXED + paxosIDLength + SIZEOF_ACCEPTREPLY) : bbuf.position() + " != [" + SIZEOF_PAXOSPACKET_FIXED + " + " + paxosIDLength + " + " + SIZEOF_ACCEPTREPLY + "]"; }
From source file:xbird.storage.io.RemoteVarSegments.java
private byte[] recvResponse(final ByteChannel channel, final ByteBuffer rcvBuf) throws IOException { ByteBuffer tmpBuf = ByteBuffer.allocate(4); NIOUtils.readFully(channel, tmpBuf, 4); tmpBuf.flip();// www .j av a 2 s .c om int datalen = tmpBuf.getInt(); final ByteBuffer buf = truncateBuffer(rcvBuf, datalen); NIOUtils.readFully(channel, buf, datalen); buf.flip(); if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) { buf.order(ByteOrder.BIG_ENDIAN); } final byte[] b = new byte[datalen]; buf.get(b); if (buf != rcvBuf) { _rbufPool.returnObject(buf); } return b; }
From source file:net.jenet.Connect.java
@Override public void fromBuffer(ByteBuffer buffer) { super.fromBuffer(buffer); outgoingPeerID = buffer.getShort();//from www . j a va 2s . c o m mtu = buffer.getShort(); windowSize = buffer.getInt(); channelCount = buffer.getInt(); incomingBandwidth = buffer.getInt(); outgoingBandwidth = buffer.getInt(); packetThrottleInterval = buffer.getInt(); packetThrottleAcceleration = buffer.getInt(); packetThrottleDeceleration = buffer.getInt(); }
From source file:voldemort.store.cachestore.voldeimpl.StoreIterator.java
private boolean checkSignature(FileChannel channel) throws IOException { ByteBuffer intBytes = ByteBuffer.allocate(OFFSET); if (channel.size() == 0) { throw new StoreException("File size is 0"); } else {// w ww . ja va2 s. c o m channel.read(intBytes); intBytes.rewind(); if (intBytes.getInt() != MAGIC) throw new StoreException("Header mismatch expect " + MAGIC + " read " + intBytes.getInt()); } return true; }
From source file:shardableobjectids.ShardableObjectId.java
public ShardableObjectId(byte[] b) { if (b.length != 12) throw new IllegalArgumentException("need 12 bytes"); ByteBuffer bb = ByteBuffer.wrap(b); _machine = bb.getInt(); _time = bb.getInt();//from w w w .j a va 2s. c o m _inc = bb.getInt(); _new = false; }