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:edu.hawaii.soest.kilonalu.adam.AdamParser.java
/** * A method that gets the channel zero data as a converted decimal float * * @return channelZero - the 2 bytes of the channelZero data as a float *//* www.j a v a2s . co m*/ public float getChannelZero() { this.channelZero.flip(); int channelData = (int) this.channelZero.order(ByteOrder.BIG_ENDIAN).getShort(); return getVoltage(channelData); }
From source file:de.tum.frm2.nicos_android.nicos.NicosClient.java
public void event_handler() { DataInputStream din = new DataInputStream(eventSocketIn); while (true) { try {/*from w ww .j av a 2 s . co m*/ // receive STX (1 byte) + eventcode (2) + length (4) byte[] start = new byte[7]; try { //noinspection ResultOfMethodCallIgnored din.read(start); } catch (IOException e) { if (!disconnecting) { signal("broken", "Server connection broken."); _close(); } return; } if (start[0] != daemon.STX) { // Every event starts with STX. Else, something's wrong. if (!disconnecting) { signal("broken", "Server connection broken."); _close(); } return; } byte[] slice = Arrays.copyOfRange(start, 3, 7); ByteBuffer bb = ByteBuffer.wrap(slice); bb.order(ByteOrder.BIG_ENDIAN); // Get length, allocate byte buffer. int length = bb.getInt(); byte[] buf = new byte[length]; // Read length bytes and store them in buf. din.readFully(buf, 0, length); boolean should_signal = true; String event = null; Object data = null; try { // Stackoverflow magic to convert 2 bytes to int which can be compared in // daemon.command2event(). int eventcode = ((start[1] & 0xff) << 8) | (start[2] & 0x00ff); event = daemon.command2event(eventcode); // serialized or raw data? if (daemon.eventNeedsUnserialize(event)) { Unpickler unpickler = new Unpickler(); data = unpickler.loads(buf); } else { data = buf; } } catch (Exception e) { // Garbled event should_signal = false; } if (should_signal) { signal(event, data); } } catch (Exception e) { if (!disconnecting) { signal("broken", "Server connection broken."); _close(); } return; } } }
From source file:edu.hawaii.soest.kilonalu.adam.AdamParser.java
/** * A method that gets the channel one data as a converted decimal float * * @return channelOne - the 2 bytes of the channelOne data as a float *///from www .j a v a2 s . c o m public float getChannelOne() { this.channelOne.flip(); int channelData = (int) this.channelOne.order(ByteOrder.BIG_ENDIAN).getShort(); return getVoltage(channelData); }
From source file:com.linkedin.databus.core.DbusEventV1.java
/** * Serializes an End-Of-Period Marker onto the ByteBuffer passed in. * @param serializationBuffer - The ByteBuffer to serialize the event in. The buffer must have enough space to accommodate * the event. (76 bytes) * @param eventInfo - The timestamp to use for the EOP marker * @return the number of bytes written/*from ww w .j a v a 2s.co m*/ */ public static int serializeEndOfPeriodMarker(ByteBuffer serializationBuffer, DbusEventInfo eventInfo) { byte[] attributes = (serializationBuffer.order() == ByteOrder.BIG_ENDIAN) ? EmptyAttributesBigEndian : EmptyAttributesLittleEndian; return serializeFullEvent(DbusEventInternalWritable.EOPMarkerKey.getLongKey(), serializationBuffer, eventInfo, attributes); }
From source file:edu.hawaii.soest.kilonalu.adam.AdamParser.java
/** * A method that gets the channel two data as a converted decimal float * * @return channelTwo - the 2 bytes of the channelTwo data as a float *//*from w ww .j av a2 s. c o m*/ public float getChannelTwo() { this.channelTwo.flip(); int channelData = (int) this.channelTwo.order(ByteOrder.BIG_ENDIAN).getShort(); return getVoltage(channelData); }
From source file:com.kactech.otj.Utils.java
public static ByteBuffer seal(String msg, String nymID, PublicKey nymKey, SecretKeySpec aesSecret, IvParameterSpec vector) throws InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException { ByteBuffer buff = ByteBuffer.allocate(msg.length() + 500);//donno? buff.order(ByteOrder.BIG_ENDIAN); buff.putShort((short) 1);//asymmetric buff.putInt(1);//array size buff.putInt(nymID.length() + 1);//from ww w .j av a 2s . c o m buff.put(bytes(nymID + '\0', US_ASCII)); // create encoded key and message Cipher cipher; try { cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); } catch (Exception e) { throw new RuntimeException(e); } cipher.init(Cipher.ENCRYPT_MODE, aesSecret, vector); byte[] encrypted = cipher.doFinal(bytes(msg + '\0', UTF8)); try { cipher = Cipher.getInstance(WRAP_ALGO); } catch (Exception e) { throw new RuntimeException(e); } cipher.init(Cipher.WRAP_MODE, nymKey); byte[] encKeyBytes = cipher.wrap(aesSecret); buff.putInt(encKeyBytes.length); buff.put(encKeyBytes); buff.putInt(vector.getIV().length); buff.put(vector.getIV()); buff.put(encrypted); buff.flip(); return buff; }
From source file:edu.hawaii.soest.kilonalu.adam.AdamParser.java
/** * A method that gets the channel three data as a converted decimal float * * @return channelThree - the 2 bytes of the channelThree data as a float *//*from www.j a va2 s . c o m*/ public float getChannelThree() { this.channelThree.flip(); int channelData = (int) this.channelThree.order(ByteOrder.BIG_ENDIAN).getShort(); return getVoltage(channelData); }
From source file:it.unimi.di.big.mg4j.index.DiskBasedIndex.java
/** Parses a {@link ByteOrder} value. * /*from w w w .j a va 2 s. c o m*/ * @param s a string (either <samp>BIG_ENDIAN</samp> or <samp>LITTLE_ENDIAN</samp>). * @return the corresponding byte order ({@link ByteOrder#BIG_ENDIAN} or {@link ByteOrder#LITTLE_ENDIAN}). */ public static ByteOrder byteOrder(final String s) { if (s.equals(ByteOrder.BIG_ENDIAN.toString())) return ByteOrder.BIG_ENDIAN; if (s.equals(ByteOrder.LITTLE_ENDIAN.toString())) return ByteOrder.LITTLE_ENDIAN; throw new IllegalArgumentException("Unknown byte order " + s); }
From source file:edu.hawaii.soest.kilonalu.adam.AdamParser.java
/** * A method that gets the channel four data as a converted decimal float * * @return channelFour - the 2 bytes of the channelFour data as a float *///from ww w. ja v a 2 s . co m public float getChannelFour() { this.channelFour.flip(); int channelData = (int) this.channelFour.order(ByteOrder.BIG_ENDIAN).getShort(); return getVoltage(channelData); }
From source file:edu.hawaii.soest.kilonalu.adam.AdamParser.java
/** * A method that gets the channel five data as a converted decimal float * * @return channelFive - the 2 bytes of the channelFive data as a float *//*from www . ja v a2 s.c om*/ public float getChannelFive() { this.channelFive.flip(); int channelData = (int) this.channelFive.order(ByteOrder.BIG_ENDIAN).getShort(); return getVoltage(channelData); }