Example usage for java.nio ByteOrder LITTLE_ENDIAN

List of usage examples for java.nio ByteOrder LITTLE_ENDIAN

Introduction

In this page you can find the example usage for java.nio ByteOrder LITTLE_ENDIAN.

Prototype

ByteOrder LITTLE_ENDIAN

To view the source code for java.nio ByteOrder LITTLE_ENDIAN.

Click Source Link

Document

This constant represents little endian.

Usage

From source file:cfa.vo.interop.EncodeDoubleArray.java

public static double[] decodeBase64(String dataString, boolean swapByteOrder) throws IOException {

    byte[] encodedData = dataString.getBytes();

    Base64 codec = new Base64();
    byte[] decodedData = codec.decode(encodedData);

    if (swapByteOrder) {
        ByteBuffer buf = ByteBuffer.wrap(decodedData);
        buf = buf.order(ByteOrder.LITTLE_ENDIAN);
        buf.get(decodedData);/*w  w w.  j ava  2s.  co  m*/
    }

    double[] result = byteToDouble(decodedData);

    return result;
}

From source file:ja.lingo.readers.sdictionary.SDictionaryDriver.java

public SDictionaryDriver(String fileName) throws IOException {
    Arguments.assertNotNull("fileName", fileName);
    this.fileName = fileName;

    try {/*  ww  w.j  a v  a  2s .c o m*/
        wrapper = new MappedByteBufferWrapper(fileName);

        buffer = wrapper.getMappedByteBuffer();
        buffer.order(ByteOrder.LITTLE_ENDIAN);

        signature = readUtf8(0x00, 4);

        // TODO check signature

        inputLanguage = readUtf8(0x04, 2);
        outputLanguage = readUtf8(0x07, 2);
        compression = readByte(0x0A);
        capacity = readInt(0x0B);
        shortIndexLength = readInt(0x0F);

        titleUnitOffset = readInt(0x13);
        copyrightUnitOffset = readInt(0x17);
        versionUnitOffset = readInt(0x1B);
        shortIndexOffset = readInt(0x1F);
        fullIndexOffset = readInt(0x23);
        articlesOffset = readInt(0x27);

        // bits 0-3 stands for compression method
        switch ((byte) (compression & 0x0F)) {
        case 0:
            compressor = Compressors.none();
            break;
        case 1:
            compressor = Compressors.gzip();
            break;
        case 2:
            compressor = Compressors.bzip2();
            break;
        default:
            Arguments.doThrow("Unknown compression menthod: " + compression);
        }
    } catch (IOException e) {
        if (wrapper != null) {
            try {
                wrapper.close();
            } catch (IOException e1) {
                LOG.error("Exception caught when tried to close wrapper", e1);
            }
        }
        throw e;
    }
}

From source file:org.onosproject.drivers.barefoot.TofinoPipelineProgrammable.java

private ByteBuffer nameBuffer(PiPipeconf pipeconf) {
    // Length of the name + name.
    String name = pipeconf.id().toString();
    return ByteBuffer.allocate(Integer.BYTES + name.length()).order(ByteOrder.LITTLE_ENDIAN)
            .putInt(name.length()).put(name.getBytes(StandardCharsets.UTF_8));
}

From source file:org.mycontroller.standalone.mysensors.structs.FirmwareConfigResponse.java

public ByteOrder byteOrder() {
    return ByteOrder.LITTLE_ENDIAN;
}

From source file:ru.jts.authserver.network.clientpackets.CM_AUTH_BY_PASS.java

@Override
public void runImpl() {
    //Account account = AccountsDAO.getInstance().restoreByLogin(jsonMap.get(JSON_LOGIN));

    getClient().setBlowFishKey(blowFishKey);
    getClient().setRandomKey(Rnd.nextInt());

    ByteBuf buf = Unpooled.buffer().order(ByteOrder.LITTLE_ENDIAN);

    buf.writeBytes(new byte[] { (byte) 192, (byte) 168, (byte) 1, (byte) 100 });
    buf.writeInt(20015);/*from   www. j  av a2 s .  co  m*/

    buf.writeInt(getClient().getRandomKey());

    Map<String, String> jsonMapp = new HashMap<>();
    //jsonMap.put("security_msg", "old_pass");
    jsonMapp.put("token2", getClient().generateToken2());

    ObjectMapper mapper = new ObjectMapper();
    String json = null;
    try {
        json = mapper.writeValueAsString(jsonMapp);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
        return;
    }
    buf.writeByte(json.length());
    buf.writeBytes(json.getBytes());

    byte[] cryptedData = CryptEngine.getInstance().encrypt(buf.copy().array(), getClient().getBlowFishKey(),
            CryptEngine.ZERO_TRAILING_MODE);

    State state = AccountController.getInstance().accountLogin(jsonMap, password);
    switch (state) {
    case AUTHED: {
        getClient().sendPacket(new SM_AUTH_RESPONSE(sessionId, SM_AUTH_RESPONSE.LOGIN_OK, cryptedData));
        break;
    }
    case ALREADY_AUTHED: {
        getClient().sendPacket(new SM_AUTH_RESPONSE(sessionId,
                SM_AUTH_RESPONSE.LOGIN_REJECTED_ALREADY_LOGGED_IN, cryptedData));
        break;
    }
    default: {
    }
    }
}

From source file:org.apache.james.mailbox.backup.LongExtraField.java

@Override
public void parseFromLocalFileData(byte[] buffer, int offset, int length) throws ZipException {
    if (length != Long.BYTES) {
        throw new ZipException(
                "Unexpected data length for ExtraField. Expected " + Long.BYTES + " but got " + length + ".");
    }// ww w  .ja v a  2  s  .c  om
    value = Optional.of(ByteBuffer.wrap(buffer, offset, Long.BYTES).order(ByteOrder.LITTLE_ENDIAN).getLong());
}

From source file:org.ros.internal.transport.tcp.TcpClient.java

public TcpClient(ChannelGroup channelGroup, HashedWheelTimer nettyTimer, Executor executor) {
    this.channelGroup = channelGroup;
    this.nettyTimer = nettyTimer;
    channelFactory = new NioClientSocketChannelFactory(new NioClientBossPool(executor, 1),
            new NioWorkerPool(executor, Runtime.getRuntime().availableProcessors() * 2));
    channelBufferFactory = new HeapChannelBufferFactory(ByteOrder.LITTLE_ENDIAN);
    bootstrap = new ClientBootstrap(channelFactory);
    bootstrap.setOption("bufferFactory", channelBufferFactory);
    setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT_DURATION, DEFAULT_CONNECTION_TIMEOUT_UNIT);
    setKeepAlive(DEFAULT_KEEP_ALIVE);// ww w.j av a 2 s.  co m
    namedChannelHandlers = Lists.newArrayList();
}

From source file:org.ros.internal.transport.tcp.TcpRosClient.java

public TcpRosClient(ChannelGroup channelGroup, HashedWheelTimer nettyTimer, Executor executor) {
    this.channelGroup = channelGroup;
    this.nettyTimer = nettyTimer;
    channelFactory = new NioClientSocketChannelFactory(new NioClientBossPool(executor, 1),
            new NioWorkerPool(executor, Runtime.getRuntime().availableProcessors() * 2));
    channelBufferFactory = new HeapChannelBufferFactory(ByteOrder.LITTLE_ENDIAN);
    bootstrap = new ClientBootstrap(channelFactory);
    bootstrap.setOption("bufferFactory", channelBufferFactory);
    setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT_DURATION, DEFAULT_CONNECTION_TIMEOUT_UNIT);
    setKeepAlive(DEFAULT_KEEP_ALIVE);/*from   w ww.  ja  va 2  s .  c  o m*/
    namedChannelHandlers = Lists.newArrayList();
}

From source file:org.obm.push.protocol.data.TZDecoder.java

public TimeZone decode(String b64) {
    // Doc : [MS-ASDTYPE] 2.7 TimeZone
    // Doc about types :
    // http://msdn.microsoft.com/fr-fr/library/bb469811.aspx
    // 1 LONG = 4 bytes
    // 1 WCHAR = 2 bytes
    // 1 SYSTEMTIME = 8 SHORT = 8 X 2 bytes
    // TOTAL TIMEZONE STRUCT must be 172 bytes

    byte tzstruct[] = Base64.decodeBase64(b64);

    ByteBuffer bfBias = ByteBuffer.wrap(tzstruct, 0, 4);
    // NOT YET USED
    ////from   ww  w . j ava  2  s . c  o m
    // ByteBuffer bfStandardName = ByteBuffer.wrap(tzstruct, 4, 64);
    // ByteBuffer bfStandardDate = ByteBuffer.wrap(tzstruct, 68, 16);
    // ByteBuffer bfStandardBias = ByteBuffer.wrap(tzstruct, 84, 4);
    // ByteBuffer bfDaylightName = ByteBuffer.wrap(tzstruct, 88, 64);
    // ByteBuffer bfDaylightDate = ByteBuffer.wrap(tzstruct, 152, 16);
    // ByteBuffer bfDaylightBias = ByteBuffer.wrap(tzstruct, 168, 4);

    bfBias.order(ByteOrder.LITTLE_ENDIAN);
    int bias = bfBias.getInt(); // Java integer is 4-bytes-long

    // NOT YET USED
    //
    // bfStandardBias.order(ByteOrder.LITTLE_ENDIAN);
    // int standardBias = bfStandardBias.getInt();
    //      
    // bfDaylightBias.order(ByteOrder.LITTLE_ENDIAN);
    // int daylightBias = bfDaylightBias.getInt();

    TimeZone timezone = TimeZone.getDefault();
    timezone.setRawOffset(bias * 60 * 1000);

    String timezones[] = TimeZone.getAvailableIDs(bias * 60 * 1000);
    if (timezones.length > 0) {
        timezone = TimeZone.getTimeZone(timezones[0]);
    }

    // USEFUL DEBUG LINES
    //
    // StringBuffer sb = new StringBuffer();
    // for (int i = 0; i < 172; i+=1) {
    // sb.append(Byte.valueOf(tzstruct[i]).intValue());
    // }
    //      
    // logger.info("b64: " + b64);
    // logger.info("tzstruct: "+ sb.toString());
    // logger.info("bias: " + bias);
    // logger.info("standardbias: " + standardBias);
    // logger.info("standardname: " +
    // bfStandardName.asCharBuffer().toString());
    // logger.info("daylightBias: " + daylightBias);

    return timezone;
}

From source file:org.mycontroller.standalone.provider.mysensors.MySensorsExecutor.java

@Override
public void executeFirmwareRequest() {
    FirmwareRequest firmwareRequest = new FirmwareRequest();
    try {/* ww  w .  j a v a2  s . co  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.warn(
                    "Requested firmware is not available in MyController server. "
                            + "FirmwareRequest[typeId:{}, versionId:{}, block:{}]",
                    firmwareRequest.getType(), firmwareRequest.getVersion(), firmwareRequest.getBlock());
            return;
        }

        FirmwareResponse firmwareResponse = new FirmwareResponse();
        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;
        for (int index = fromIndex; index < fromIndex + blockSize; index++) {
            builder.append(String.format("%02X", firmwareData.getData().get(index)));
        }

        _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 % 50 == 0) {
            updateFirmwareStatus(responseBlock);
        } else if (responseBlock == blocks) {
            updateFirmwareStatus(responseBlock);
            firmwareUpdateFinished();
        }
    } catch (DecoderException ex) {
        _logger.error("Exception, ", ex);
    }

}