List of usage examples for java.nio ByteOrder LITTLE_ENDIAN
ByteOrder LITTLE_ENDIAN
To view the source code for java.nio ByteOrder LITTLE_ENDIAN.
Click Source Link
From source file:edu.udo.scaffoldhunter.model.db.StringProperty.java
/** * Extracts the BitFingerprint length from the first two bytes * /*from w ww. j a va 2 s .co m*/ * @param bitFingerprint * the bytes * @return the length */ private short bitFingerprintToLength(byte[] bitFingerprint) { Preconditions.checkArgument(bitFingerprint.length >= 3); ByteBuffer bb = ByteBuffer.allocate(2); bb.order(ByteOrder.LITTLE_ENDIAN); bb.put(bitFingerprint[0]); bb.put(bitFingerprint[1]); short length = bb.getShort(0); return length; }
From source file:org.ros.android.android_acm_serial.AcmDevice.java
public void setLineCoding(BitRate bitRate, StopBits stopBits, Parity parity, DataBits dataBits) { ByteBuffer buffer = ByteBuffer.allocate(7); buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.putInt(bitRate.getBitRate()); buffer.put(stopBits.getStopBits());// w w w. ja va 2s. c om buffer.put(parity.getParity()); buffer.put(dataBits.getDataBits()); setLineCoding(buffer.array()); }
From source file:nl.salp.warcraft4j.casc.cdn.local.LocalIndexFileParser.java
/** * Validate the index file header./* w w w .jav a2 s . co m*/ * * @param reader The reader to read the header data from. * * @throws CascParsingException When the header is invalid. * @throws DataReadingException When reading the entry data failed. * @throws DataParsingException When parsing the entry data failed. */ private void validateHeader(DataReader reader) throws CascParsingException, DataReadingException, DataParsingException { long position = reader.position(); int headerLen = (int) reader.readNext(DataTypeFactory.getUnsignedInteger(), ByteOrder.LITTLE_ENDIAN) .longValue(); int hash = reader.readNext(DataTypeFactory.getInteger(), ByteOrder.LITTLE_ENDIAN); byte[] data = reader.readNext(DataTypeFactory.getByteArray(headerLen)); int h2 = JenkinsHash.hashLittle2b(data, headerLen); if (hash != h2) { throw new CascParsingException(format("Invalid index header hash %X -> %X", hash, h2)); } reader.position(position); }
From source file:org.mycontroller.standalone.provider.mycontroller.MyControllerExecutor.java
@Override public void executeFirmwareConfigRequest() { McFirmwareConfig firmwareConfigRequest = new McFirmwareConfig(); try {//from w w w .java 2 s . c o m firmwareConfigRequest.setByteBuffer(ByteBuffer.wrap(Hex.decodeHex(_message.getPayload().toCharArray())) .order(ByteOrder.LITTLE_ENDIAN), 0); Firmware firmware = null; //Check firmware is configured for this particular node Node node = DaoUtils.getNodeDao().get(_message.getGatewayId(), _message.getNodeEui()); if (node != null && node.getFirmware() != null) { firmware = DaoUtils.getFirmwareDao().getById(node.getFirmware().getId()); _logger.debug("Firmware selected based on node configuration..."); } else if (firmwareConfigRequest.getType() == 65535 && firmwareConfigRequest.getVersion() == 65535) { if (AppProperties.getInstance().getMySensorsSettings().getDefaultFirmware() != null) { firmware = DaoUtils.getFirmwareDao() .getById(AppProperties.getInstance().getMySensorsSettings().getDefaultFirmware()); } else { _logger.warn("There is no default firmware set!"); } } else { firmware = DaoUtils.getFirmwareDao().get(firmwareConfigRequest.getType(), firmwareConfigRequest.getVersion()); } McFirmwareConfig firmwareConfigResponse = new McFirmwareConfig(); firmwareConfigResponse.setByteBufferPosition(0); if (firmware == null) {//Non bootloader command if (AppProperties.getInstance().getMySensorsSettings().getEnbaledDefaultOnNoFirmware()) { _logger.debug("If requested firmware is not available, " + "redirect to default firmware is set, Checking the default firmware"); if (AppProperties.getInstance().getMySensorsSettings().getDefaultFirmware() != null) { firmware = DaoUtils.getFirmwareDao() .getById(AppProperties.getInstance().getMySensorsSettings().getDefaultFirmware()); _logger.debug("Default firmware:[{}]", firmware.getFirmwareName()); } else { _logger.warn("There is no default firmware set!"); } } //Selected, default: No firmware available for this request if (firmware == null) { _logger.warn("Selected Firmware is not available, FirmwareConfigRequest:[{}]", firmwareConfigRequest); return; } } if (firmware != null) { firmwareConfigResponse.setType(firmware.getType().getId()); firmwareConfigResponse.setVersion(firmware.getVersion().getId()); firmwareConfigResponse.setBlocks((Integer) firmware.getProperties().get(Firmware.KEY_PROP_BLOCKS)); firmwareConfigResponse.setMd5Sum((String) firmware.getProperties().get(Firmware.KEY_PROP_MD5_HEX)); } _message.setTxMessage(true); _message.setSubType(MESSAGE_TYPE_STREAM.ST_FIRMWARE_CONFIG_RESPONSE.getText()); _message.setPayload(Hex.encodeHexString(firmwareConfigResponse.getByteBuffer().array()).toUpperCase()); _message.setTimestamp(System.currentTimeMillis()); addInQueue(_message); _logger.debug("FirmwareConfigRequest:[{}]", firmwareConfigRequest); _logger.debug("FirmwareConfigResponse:[{}]", firmwareConfigResponse); } catch (DecoderException ex) { _logger.error("Exception, ", ex); } }
From source file:com.topsem.common.net.IPSeeker.java
public IPSeeker(File ipFile) throws Exception { this.ipFile = new RandomAccessFile(ipFile, "r"); ipCache = new HashMap<String, IPLocation>(); FileChannel fc = this.ipFile.getChannel(); mbb = fc.map(FileChannel.MapMode.READ_ONLY, 0, ipFile.length()); mbb.order(ByteOrder.LITTLE_ENDIAN); ipBegin = readInt(0);//from w ww .j av a 2 s . co m ipEnd = readInt(4); if (ipBegin == -1 || ipEnd == -1) { throw new IOException("IP???IP"); } log.debug("IP?:" + ipFile.getAbsolutePath()); }
From source file:edu.udo.scaffoldhunter.model.db.StringProperty.java
/** * Set the length in the BitFingerprint (first two bytes) * //from w w w. j a va 2 s. c om * @param length * the length * @param bitFingerprint * the fingerprint */ private void lenghtToBitFingerprint(short length, byte[] bitFingerprint) { ByteBuffer bb = ByteBuffer.allocate(2); bb.order(ByteOrder.LITTLE_ENDIAN); bb.putShort(length); bitFingerprint[0] = bb.get(0); bitFingerprint[1] = bb.get(1); }
From source file:org.mycontroller.standalone.provider.mysensors.MySensorsExecutor.java
@Override public void executeFirmwareConfigRequest() { FirmwareConfigRequest firmwareConfigRequest = new FirmwareConfigRequest(); try {/*from w ww.j a v a 2 s .c om*/ firmwareConfigRequest.setByteBuffer(ByteBuffer.wrap(Hex.decodeHex(_message.getPayload().toCharArray())) .order(ByteOrder.LITTLE_ENDIAN), 0); boolean bootLoaderCommand = false; Firmware firmware = null; //Check firmware is configured for this particular node Node node = DaoUtils.getNodeDao().get(_message.getGatewayId(), _message.getNodeEui()); if (node != null && node.getEraseConfig() != null && node.getEraseConfig()) { bootLoaderCommand = true; _logger.debug("Erase EEPROM has been set..."); } else if (node != null && node.getFirmware() != null) { firmware = DaoUtils.getFirmwareDao().getById(node.getFirmware().getId()); _logger.debug("Firmware selected based on node configuration..."); } else if (firmwareConfigRequest.getType() == 65535 && firmwareConfigRequest.getVersion() == 65535) { if (AppProperties.getInstance().getMySensorsSettings().getDefaultFirmware() != null) { firmware = DaoUtils.getFirmwareDao() .getById(AppProperties.getInstance().getMySensorsSettings().getDefaultFirmware()); } else { _logger.warn("There is no default firmware set!"); } } else { firmware = DaoUtils.getFirmwareDao().get(firmwareConfigRequest.getType(), firmwareConfigRequest.getVersion()); } FirmwareConfigResponse firmwareConfigResponse = new FirmwareConfigResponse(); firmwareConfigResponse.setByteBufferPosition(0); if (bootLoaderCommand) {//If it is bootloader command if (node.getEraseConfig() != null && node.getEraseConfig()) { firmwareConfigResponse.loadEraseEepromCommand(); node.setEraseConfig(false); //Remove erase EEPROM flag and update in to database DaoUtils.getNodeDao().update(node); } else { _logger.warn("Selected booloader command is not available, FirmwareConfigRequest:[{}]", firmwareConfigRequest); return; } } else if (firmware == null) {//Non bootloader command if (AppProperties.getInstance().getMySensorsSettings().getEnbaledDefaultOnNoFirmware()) { _logger.debug("If requested firmware is not available, " + "redirect to default firmware is set, Checking the default firmware"); if (AppProperties.getInstance().getMySensorsSettings().getDefaultFirmware() != null) { firmware = DaoUtils.getFirmwareDao() .getById(AppProperties.getInstance().getMySensorsSettings().getDefaultFirmware()); _logger.debug("Default firmware:[{}]", firmware.getFirmwareName()); } else { _logger.warn("There is no default firmware set!"); } } //Selected, default: No firmware available for this request if (firmware == null) { _logger.warn("Selected Firmware is not available, FirmwareConfigRequest:[{}]", firmwareConfigRequest); return; } } if (firmware != null) { firmwareConfigResponse.setType(firmware.getType().getId()); firmwareConfigResponse.setVersion(firmware.getVersion().getId()); firmwareConfigResponse.setBlocks((Integer) firmware.getProperties().get(Firmware.KEY_PROP_BLOCKS)); firmwareConfigResponse.setCrc((Integer) firmware.getProperties().get(Firmware.KEY_PROP_CRC)); } _message.setTxMessage(true); _message.setSubType(MESSAGE_TYPE_STREAM.ST_FIRMWARE_CONFIG_RESPONSE.getText()); _message.setPayload(Hex.encodeHexString(firmwareConfigResponse.getByteBuffer().array()).toUpperCase()); _message.setTimestamp(System.currentTimeMillis()); addInQueue(_message); _logger.debug("FirmwareConfigRequest:[{}]", firmwareConfigRequest); _logger.debug("FirmwareConfigResponse:[{}]", firmwareConfigResponse); } catch (DecoderException ex) { _logger.error("Exception, ", ex); } }
From source file:com.google.flatbuffers.Table.java
/** * Get a whole vector as a ByteBuffer./*from w w w . j a va 2 s. c o m*/ * * This is efficient, since it only allocates a new {@link ByteBuffer} object, * but does not actually copy the data, it still refers to the same bytes * as the original ByteBuffer. Also useful with nested FlatBuffers, etc. * * @param vector_offset The position of the vector in the byte buffer * @param elem_size The size of each element in the array * @return The {@link ByteBuffer} for the array */ protected ByteBuffer __vector_as_bytebuffer(int vector_offset, int elem_size) { int o = __offset(vector_offset); if (o == 0) return null; ByteBuffer bb = this.bb.duplicate().order(ByteOrder.LITTLE_ENDIAN); int vectorstart = __vector(o); bb.position(vectorstart); bb.limit(vectorstart + __vector_len(o) * elem_size); return bb; }
From source file:com.codestation.henkakuserver.HenkakuServer.java
/** * Convert the exploit to a shellcode in binary format * * @param exploit payload compiled code// w w w. j ava2 s. c o m * @return the shellcode * @throws Exception */ private byte[] preprocessToBin(byte[] exploit) throws Exception { Pair<ArrayList<Integer>, List<Byte>> data = preprocessRop(exploit); int size = 4 + data.first.size() * 4 + data.second.size(); byte[] out = new byte[size + ((-size) & 3)]; ByteBuffer buf = ByteBuffer.wrap(out).order(ByteOrder.LITTLE_ENDIAN); buf.putInt(data.second.size()); for (Integer val : data.first) { buf.putInt(val); } for (Byte val : data.second) { buf.put(val); } return out; }
From source file:edu.umn.msi.tropix.proteomics.conversion.impl.ConversionUtils.java
public static double[] extractDoublesLittleEndian(final byte[] bytes, final boolean is64Bit) { double[] doubles; ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); byteBuffer.order(ByteOrder.LITTLE_ENDIAN); if (is64Bit) { doubles = new double[bytes.length / 8]; for (int i = 0; i < doubles.length; i++) { doubles[i] = byteBuffer.getDouble(); }/*from w w w . j ava2 s . co m*/ } else { doubles = new double[bytes.length / 4]; for (int i = 0; i < doubles.length; i++) { doubles[i] = byteBuffer.getFloat(); } } return doubles; }