List of usage examples for java.nio ByteOrder BIG_ENDIAN
ByteOrder BIG_ENDIAN
To view the source code for java.nio ByteOrder BIG_ENDIAN.
Click Source Link
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
byte[] encodeUploadComplete(int token) { final short LENGTH_UPLOADCOMPLETE = 5; ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_UPLOADCOMPLETE); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort(LENGTH_UPLOADCOMPLETE); buf.putShort(ENDPOINT_PUTBYTES);/*ww w . j a v a 2 s . com*/ buf.put(PUTBYTES_COMPLETE); buf.putInt(token); return buf.array(); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
byte[] encodeUploadCancel(int token) { final short LENGTH_UPLOADCANCEL = 5; ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_UPLOADCANCEL); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort(LENGTH_UPLOADCANCEL);/*from w w w . j a v a 2s . c o m*/ buf.putShort(ENDPOINT_PUTBYTES); buf.put(PUTBYTES_ABORT); buf.putInt(token); return buf.array(); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
private byte[] encodeSystemMessage(byte systemMessage) { final short LENGTH_SYSTEMMESSAGE = 2; ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_SYSTEMMESSAGE); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort(LENGTH_SYSTEMMESSAGE);/*from ww w. ja v a2s . c o m*/ buf.putShort(ENDPOINT_SYSTEMMESSAGE); buf.put((byte) 0); buf.put(systemMessage); return buf.array(); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
byte[] encodeAppRefresh(int index) { final short LENGTH_REFRESHAPP = 5; ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_REFRESHAPP); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort(LENGTH_REFRESHAPP);//from w w w .j a va 2 s .c o m buf.putShort(ENDPOINT_APPMANAGER); buf.put(APPMANAGER_REFRESHAPP); buf.putInt(index); return buf.array(); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
private byte[] encodeDatalog(byte handle, byte reply) { ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + 2); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort((short) 2); buf.putShort(ENDPOINT_DATALOG);//from w w w . j a v a 2 s . c o m buf.put(reply); buf.put(handle); return buf.array(); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
byte[] encodeApplicationMessageAck(UUID uuid, byte id) { if (uuid == null) { uuid = currentRunningApp;//w w w . ja v a 2s .com } ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + 18); // +ACK buf.order(ByteOrder.BIG_ENDIAN); buf.putShort((short) 18); buf.putShort(ENDPOINT_APPLICATIONMESSAGE); buf.put(APPLICATIONMESSAGE_ACK); buf.put(id); buf.putLong(uuid.getMostSignificantBits()); buf.putLong(uuid.getLeastSignificantBits()); return buf.array(); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
private byte[] encodePing(byte command, int cookie) { final short LENGTH_PING = 5; ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_PING); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort(LENGTH_PING);/* w ww . j a va 2 s . co m*/ buf.putShort(ENDPOINT_PING); buf.put(command); buf.putInt(cookie); return buf.array(); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
byte[] encodeEnableAppLogs(boolean enable) { final short LENGTH_APPLOGS = 1; ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_APPLOGS); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort(LENGTH_APPLOGS);//w w w .jav a2 s. co m buf.putShort(ENDPOINT_APPLOGS); buf.put((byte) (enable ? 1 : 0)); return buf.array(); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
byte[] encodeApplicationMessagePush(short endpoint, UUID uuid, ArrayList<Pair<Integer, Object>> pairs) { int length = LENGTH_UUID + 3; // UUID + (PUSH + id + length of dict) for (Pair<Integer, Object> pair : pairs) { if (pair.first == null || pair.second == null) continue; length += 7; // key + type + length if (pair.second instanceof Integer) { length += 4;/*from w ww . ja v a2 s .c o m*/ } else if (pair.second instanceof Short) { length += 2; } else if (pair.second instanceof Byte) { length += 1; } else if (pair.second instanceof String) { length += ((String) pair.second).getBytes().length + 1; } else if (pair.second instanceof byte[]) { length += ((byte[]) pair.second).length; } else { LOG.warn("unknown type: " + pair.second.getClass().toString()); } } ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + length); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort((short) length); buf.putShort(endpoint); // 48 or 49 buf.put(APPLICATIONMESSAGE_PUSH); buf.put(++last_id); buf.putLong(uuid.getMostSignificantBits()); buf.putLong(uuid.getLeastSignificantBits()); buf.put((byte) pairs.size()); buf.order(ByteOrder.LITTLE_ENDIAN); for (Pair<Integer, Object> pair : pairs) { if (pair.first == null || pair.second == null) continue; buf.putInt(pair.first); if (pair.second instanceof Integer) { buf.put(TYPE_INT); buf.putShort((short) 4); // length buf.putInt((int) pair.second); } else if (pair.second instanceof Short) { buf.put(TYPE_INT); buf.putShort((short) 2); // length buf.putShort((short) pair.second); } else if (pair.second instanceof Byte) { buf.put(TYPE_INT); buf.putShort((short) 1); // length buf.put((byte) pair.second); } else if (pair.second instanceof String) { String str = (String) pair.second; buf.put(TYPE_CSTRING); buf.putShort((short) (str.getBytes().length + 1)); buf.put(str.getBytes()); buf.put((byte) 0); } else if (pair.second instanceof byte[]) { byte[] bytes = (byte[]) pair.second; buf.put(TYPE_BYTEARRAY); buf.putShort((short) bytes.length); buf.put(bytes); } } return buf.array(); }
From source file:cn.nukkit.Server.java
public void saveOfflinePlayerData(String name, CompoundTag tag, boolean async) { if (this.shouldSavePlayerData()) { try {// w w w.j a v a 2s . c om if (async) { this.getScheduler().scheduleAsyncTask( new FileWriteTask(this.getDataPath() + "players/" + name.toLowerCase() + ".dat", NBTIO.writeGZIPCompressed(tag, ByteOrder.BIG_ENDIAN))); } else { Utils.writeFile(this.getDataPath() + "players/" + name.toLowerCase() + ".dat", new ByteArrayInputStream(NBTIO.writeGZIPCompressed(tag, ByteOrder.BIG_ENDIAN))); } } catch (Exception e) { this.logger.critical(this.getLanguage().translateString("nukkit.data.saveError", new String[] { name, e.getMessage() })); if (Nukkit.DEBUG > 1) { this.logger.logException(e); } } } }