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:byps.test.TestSerializePrimitiveTypes.java
/** * BBufferBin/BBufferJson re-allocate an internal ByteBuffer, * if the buffer supplied in the constructor is too small. * The bytes written so far have to be copied into the new Buffer. * @throws BException //from w w w . j ava 2 s . c o m */ @Test public void testBufferRealloc() throws BException { log.info("testBufferRealloc("); internalTestBufferRealloc(ByteOrder.BIG_ENDIAN); internalTestBufferRealloc(ByteOrder.LITTLE_ENDIAN); log.info(")testBufferRealloc"); }
From source file:org.apache.james.mailbox.backup.LongExtraField.java
@Override public byte[] getLocalFileDataData() { long value = this.value.orElseThrow(() -> new RuntimeException("Value must by initialized")); return ByteBuffer.allocate(Long.BYTES).order(ByteOrder.LITTLE_ENDIAN).putLong(value).array(); }
From source file:org.ros.internal.transport.tcp.TcpClientConnectionManager.java
public TcpClientConnectionManager(ScheduledExecutorService executorService) { this.executorService = executorService; channelFactory = new NioClientSocketChannelFactory(executorService, executorService); channelGroup = new DefaultChannelGroup(); channelBufferFactory = new HeapChannelBufferFactory(ByteOrder.LITTLE_ENDIAN); tcpClientConnections = Lists.newArrayList(); }
From source file:byps.test.TestUtils.java
public static BTransport createTransport(int flags, int bypsVersion, long version) { BWire wire = new MyWire(flags); BApiDescriptor apiDesc = new BApiDescriptor("TestSerialize", BApiDescriptor_Testser.instance().basePackage, version, BApiDescriptor_Testser.instance().uniqueObjects); if (protocol == BProtocolJson.BINARY_MODEL) { apiDesc.addRegistry(new JRegistry_Testser()); } else {//from w ww .ja va2 s . co m apiDesc.addRegistry(new BRegistry_Testser()); } BProtocol proto = null; if (protocol == BProtocolJson.BINARY_MODEL) { proto = new BProtocolJson(apiDesc); } else { proto = new BProtocolS(apiDesc, bypsVersion, version, ByteOrder.LITTLE_ENDIAN); } BTransport transport = new BTransport(apiDesc, wire, null); transport.setProtocol(proto); return transport; }
From source file:org.mycontroller.standalone.db.uidtag.ExecuteUidTag.java
private void executeUidTag() throws DecoderException { _logger.debug("UID TAG RX String:[{}]", sensorValue.getLastValue()); if (sensorValue.getLastValue().equalsIgnoreCase("NA")) { //Nothing to do, just return from here return;// ww w .j a v a2 s. c o m } UidTagStruct uidTagStruct = new UidTagStruct(); uidTagStruct.setByteBuffer(ByteBuffer.wrap(Hex.decodeHex(sensorValue.getLastValue().toCharArray())) .order(ByteOrder.LITTLE_ENDIAN), 0); _logger.debug("ByteBuffer:[{}]", Hex.encodeHexString(uidTagStruct.getByteBuffer().array())); _logger.debug("UID TAG:[{}]", uidTagStruct.toString()); RawMessage rawMessage = new RawMessage(sensor.getNode().getId(), sensor.getSensorId(), MESSAGE_TYPE.C_SET.ordinal(), //messageType 0, //ack MESSAGE_TYPE_SET_REQ.V_VAR5.ordinal(), //subType Hex.encodeHexString(uidTagStruct.getByteBuffer().array()), true);// isTxMessage UidTag uidTag = DaoUtils.getUidTagDao().get(uidTagStruct.getUid()); if (uidTagStruct.getStatus() == 0) { if (uidTag != null) { SensorValue sensorValueDes = DaoUtils.getSensorValueDao().get(uidTag.getSensor().getId(), uidTagStruct.getType()); if (sensorValueDes != null) { uidTagStruct.setStatus(1); //Set success //TODO: add support for string, payload might be anything, should not restrect with Integer uidTagStruct.setPayload(Integer.valueOf(sensorValueDes.getLastValue())); rawMessage.setPayload(Hex.encodeHexString(uidTagStruct.getByteBuffer().array())); } } } else if (uidTag != null) { RawMessage rawMessageToDevice = new RawMessage(uidTag.getSensor().getNode().getId(), uidTag.getSensor().getSensorId(), MESSAGE_TYPE.C_SET.ordinal(), //messageType 0, //ack MESSAGE_TYPE_SET_REQ.V_VAR5.ordinal(), //subType String.valueOf(uidTagStruct.getPayload()), true);// isTxMessage ObjectFactory.getRawMessageQueue().putMessage(rawMessageToDevice); } else { uidTagStruct.setStatus(0); rawMessage.setPayload(Hex.encodeHexString(uidTagStruct.getByteBuffer().array())); } ObjectFactory.getRawMessageQueue().putMessage(rawMessage); _logger.debug("Message Sent:[{}]", rawMessage.toString()); }
From source file:StreamUtility.java
/** * Converts little endian Unicode bytes to a String * @param value byte array of Unicode Little Endian * @return String value of the byte array *//*from w w w .jav a 2 s .co m*/ public static String littleEndianToString(byte[] value) { return ByteBuffer.wrap(value).order(ByteOrder.LITTLE_ENDIAN).asCharBuffer().toString(); }
From source file:ru.jts_dev.gameserver.movement.geoengine.GeoService.java
public void loadGeodata() { Path geodataDir = Paths.get("./data/geodata"); try (Stream<Path> pathStream = Files.walk(geodataDir)) { pathStream.forEach(path -> {//from w ww. j a v a2 s . c o m String name = path.getFileName().toString(); int x = Integer.parseInt(name.substring(0, 2)); int y = Integer.parseInt(name.substring(3, 5)); try (FileChannel fileChannel = FileChannel.open(path)) { MappedByteBuffer buffer = fileChannel.map(MapMode.READ_ONLY, 0, fileChannel.size()); buffer.order(ByteOrder.LITTLE_ENDIAN); loadRegion(x, y, buffer); } catch (IOException e) { e.printStackTrace(); } }); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.codestation.henkakuserver.HenkakuServer.java
private Pair<ArrayList<Integer>, List<Byte>> preprocessRop(byte[] urop) throws Exception { byte[] loader = new byte[urop.length + ((-urop.length) & 3)]; System.arraycopy(urop, 0, loader, 0, urop.length); ByteBuffer buf = ByteBuffer.wrap(loader).order(ByteOrder.LITTLE_ENDIAN); int header_size = 0x40; int dsize = buf.getInt(0x10); int csize = buf.getInt(0x20); int reloc_size = buf.getInt(0x30); int symtab_size = buf.getInt(0x38); if (csize % 4 != 0) { throw new Exception("csize % 4 != 0???"); }//from www .j ava 2 s . com int reloc_offset = header_size + dsize + csize; int symtab = reloc_offset + reloc_size; int symtab_n = symtab_size / 8; Map<Integer, String> reloc_map = new HashMap<>(); for (int x = 0; x < symtab_n; ++x) { int sym_id = buf.getInt(symtab + 8 * x); int str_offset = buf.getInt(symtab + 8 * x + 4); int end = str_offset; while (loader[end] != 0) { end += 1; } String name = new String(Arrays.copyOfRange(loader, str_offset, end)); reloc_map.put(sym_id, name); } Map<Pair<String, Integer>, Integer> reloc_type_map = new HashMap<>(); reloc_type_map.put(new Pair<>("rop.data", 0), 1); reloc_type_map.put(new Pair<>("SceWebKit", 0), 2); reloc_type_map.put(new Pair<>("SceLibKernel", 0), 3); reloc_type_map.put(new Pair<>("SceLibc", 0), 4); reloc_type_map.put(new Pair<>("SceLibHttp", 0), 5); reloc_type_map.put(new Pair<>("SceNet", 0), 6); reloc_type_map.put(new Pair<>("SceAppMgr", 0), 7); int want_len = 0x40 + dsize + csize; ArrayList<Integer> urop_js = new ArrayList<>(); byte[] relocs = new byte[want_len / 4]; int reloc_n = reloc_size / 8; for (int x = 0; x < reloc_n; ++x) { int reloc_type = buf.getShort(reloc_offset + 8 * x); int sym_id = buf.getShort(reloc_offset + 8 * x + 2); int offset = buf.getInt(reloc_offset + 8 * x + 4); if (offset % 4 != 0) { throw new Exception("offset % 4 != 0???"); } if (relocs[offset / 4] != 0) { throw new Exception("symbol relocated twice, not supported"); } Integer wk_reloc_type = reloc_type_map.get(new Pair<>(reloc_map.get(sym_id), reloc_type)); if (wk_reloc_type == null) { throw new Exception("unsupported relocation type"); } relocs[offset / 4] = wk_reloc_type.byteValue(); } for (int x = 0; x < want_len; x += 4) { urop_js.add(buf.getInt(x)); } List<Byte> relocsArray = Arrays.asList(ArrayUtils.toObject(relocs)); return new Pair<>(urop_js, relocsArray); }
From source file:org.mycontroller.standalone.provider.mycontroller.MyControllerExecutor.java
@Override public void executeFirmwareRequest() { McFirmwareRequest firmwareRequest = new McFirmwareRequest(); try {//from w w w . j av a 2s . c o m firmwareRequest.setByteBuffer(ByteBuffer.wrap(Hex.decodeHex(_message.getPayload().toCharArray())) .order(ByteOrder.LITTLE_ENDIAN), 0); _logger.debug("Firmware Request:[Type:{},Version:{},Block:{}]", firmwareRequest.getType(), firmwareRequest.getVersion(), firmwareRequest.getBlock()); FirmwareData firmwareData = FirmwareUtils.getFirmwareDataFromOfflineMap(firmwareRequest.getType(), firmwareRequest.getVersion()); if (firmwareData == null) { _logger.debug("selected firmware type/version not available"); return; } McFirmwareResponse firmwareResponse = new McFirmwareResponse(); firmwareResponse.setByteBufferPosition(0); firmwareResponse.setBlock(firmwareRequest.getBlock()); firmwareResponse.setVersion(firmwareRequest.getVersion()); firmwareResponse.setType(firmwareRequest.getType()); StringBuilder builder = new StringBuilder(); Integer blockSize = (Integer) firmwareData.getFirmware().getProperties() .get(Firmware.KEY_PROP_BLOCK_SIZE); Integer blocks = (Integer) firmwareData.getFirmware().getProperties().get(Firmware.KEY_PROP_BLOCKS); int fromIndex = firmwareRequest.getBlock() * blockSize; if (firmwareRequest.getBlock() >= blocks || firmwareRequest.getBlock() < 0) { _logger.warn("Requested firmware out of range. Accepted range[0~{}] FirmwareRequest({}), {}", blocks - 1, firmwareRequest, _message); return; } int toIndex = Math.min(fromIndex + blockSize, firmwareData.getData().size()); firmwareResponse.setSize(toIndex - fromIndex); firmwareResponse.setData(firmwareData.getData().subList(fromIndex, toIndex)); _message.setTxMessage(true); _message.setSubType(MESSAGE_TYPE_STREAM.ST_FIRMWARE_RESPONSE.getText()); _message.setPayload(Hex.encodeHexString(firmwareResponse.getByteBuffer().array()) + builder.toString()); _message.setTimestamp(System.currentTimeMillis()); addInQueue(_message); _logger.debug("FirmwareRespone:[Type:{},Version:{},Block:{}]", firmwareResponse.getType(), firmwareResponse.getVersion(), firmwareResponse.getBlock()); // update firmware status int responseBlock = firmwareResponse.getBlock() + 1; // adding +1 as it starts from 0 // firmware starts if (responseBlock == 1) { firmwareUpdateStart(blocks); } else if (responseBlock % 100 == 0) { updateFirmwareStatus(responseBlock); } else if (responseBlock == blocks) { updateFirmwareStatus(responseBlock); firmwareUpdateFinished(); } } catch (DecoderException ex) { _logger.error("Exception, ", ex); } }
From source file:com.netflix.suro.jackson.DefaultObjectMapper.java
@Inject public DefaultObjectMapper(final Injector injector, Set<TypeHolder> crossInjectable) { SimpleModule serializerModule = new SimpleModule("SuroServer default serializers"); serializerModule.addSerializer(ByteOrder.class, ToStringSerializer.instance); serializerModule.addDeserializer(ByteOrder.class, new JsonDeserializer<ByteOrder>() { @Override//from w w w . j ava 2 s. c o m public ByteOrder deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { if (ByteOrder.BIG_ENDIAN.toString().equals(jp.getText())) { return ByteOrder.BIG_ENDIAN; } return ByteOrder.LITTLE_ENDIAN; } }); registerModule(serializerModule); registerModule(new GuavaModule()); if (injector != null) { setInjectableValues(new InjectableValues() { @Override public Object findInjectableValue(Object valueId, DeserializationContext ctxt, BeanProperty forProperty, Object beanInstance) { LOG.info("Looking for " + valueId); try { return injector.getInstance( Key.get(forProperty.getType().getRawClass(), Names.named((String) valueId))); } catch (Exception e) { try { return injector.getInstance(forProperty.getType().getRawClass()); } catch (Exception ex) { LOG.info("No implementation found, returning null"); } return null; } } }); } configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); configure(MapperFeature.AUTO_DETECT_GETTERS, false); configure(MapperFeature.AUTO_DETECT_CREATORS, false); configure(MapperFeature.AUTO_DETECT_FIELDS, false); configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false); configure(MapperFeature.AUTO_DETECT_SETTERS, false); configure(SerializationFeature.INDENT_OUTPUT, false); if (crossInjectable != null) { for (TypeHolder entry : crossInjectable) { LOG.info("Registering subtype : " + entry.getName() + " -> " + entry.getRawType().getCanonicalName()); registerSubtypes(new NamedType(entry.getRawType(), entry.getName())); } } }