Example usage for java.nio ByteOrder BIG_ENDIAN

List of usage examples for java.nio ByteOrder BIG_ENDIAN

Introduction

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

Prototype

ByteOrder BIG_ENDIAN

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

Click Source Link

Document

This constant represents big endian.

Usage

From source file:edu.hawaii.soest.kilonalu.adam.AdamParser.java

/**
 * A method that gets the channel six data as a converted decimal float
 *
 * @return channelSix - the 2 bytes of the channelSix data as a float
 *///from  ww  w  . j ava  2  s . c  o  m
public float getChannelSix() {
    this.channelSix.flip();
    int channelData = (int) this.channelSix.order(ByteOrder.BIG_ENDIAN).getShort();

    return getVoltage(channelData);
}

From source file:edu.mbl.jif.imaging.mmtiff.MultipageTiffReader.java

private long readHeader() throws IOException {
    ByteBuffer tiffHeader = ByteBuffer.allocate(8);
    fileChannel_.read(tiffHeader, 0);// ww w  .  j  a  v  a  2s.  com
    char zeroOne = tiffHeader.getChar(0);
    if (zeroOne == 0x4949) {
        byteOrder_ = ByteOrder.LITTLE_ENDIAN;
    } else if (zeroOne == 0x4d4d) {
        byteOrder_ = ByteOrder.BIG_ENDIAN;
    } else {
        throw new IOException("Error reading Tiff header");
    }
    tiffHeader.order(byteOrder_);
    short twoThree = tiffHeader.getShort(2);
    if (twoThree != 42) {
        throw new IOException("Tiff identifier code incorrect");
    }
    return unsignInt(tiffHeader.getInt(4));
}

From source file:edu.hawaii.soest.kilonalu.adam.AdamParser.java

/**
 * A method that gets the channel seven data as a converted decimal float
 *
 * @return channelSeven - the 2 bytes of the channelSeven data as a float
 *//*from  w  w  w . jav  a 2  s  . c o m*/
public float getChannelSeven() {
    this.channelSeven.flip();
    int channelData = (int) this.channelSeven.order(ByteOrder.BIG_ENDIAN).getShort();

    return getVoltage(channelData);
}

From source file:com.kactech.otj.Utils.java

public static String open(byte[] encryptedEnvelope, PrivateKey privateKey)
        throws InvalidKeyException, NoSuchAlgorithmException, InvalidAlgorithmParameterException,
        IllegalBlockSizeException, BadPaddingException {
    String str;/*ww  w  . jav a  2s  .c  o  m*/
    byte[] by;
    ByteBuffer buff = ByteBuffer.wrap(encryptedEnvelope);
    buff.order(ByteOrder.BIG_ENDIAN);
    int envType = buff.getShort();// expected 1(asymmetric)
    if (envType != 1)
        throw new UnsupportedOperationException("unexpected envelope type " + envType);
    int arraySize = buff.getInt();// can result in negative integer but not expecting it here
    if (arraySize != 1)//TODO
        throw new UnsupportedOperationException("current code doesn't support multi-nym response");
    byte[] encKeyBytes = null;
    byte[] vectorBytes = null;
    for (int i = 0; i < arraySize; i++) {
        int nymIDLen = buff.getInt();
        by = new byte[nymIDLen];
        buff.get(by);
        String nymID;
        try {
            nymID = new String(by, 0, by.length - 1, Utils.US_ASCII);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        } // take nymID W/O trailing \0
          //TODO nymID matching!
        int keyLength = buff.getInt();
        encKeyBytes = new byte[keyLength];
        buff.get(encKeyBytes);
        int vectorLength = buff.getInt();
        vectorBytes = new byte[vectorLength];
        buff.get(vectorBytes);

    }
    byte[] encryptedMsg = new byte[buff.remaining()];
    buff.get(encryptedMsg);

    Cipher cipher;
    try {
        cipher = Cipher.getInstance(WRAP_ALGO);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    cipher.init(Cipher.UNWRAP_MODE, privateKey);
    SecretKeySpec aesKey = (SecretKeySpec) cipher.unwrap(encKeyBytes, "AES", Cipher.SECRET_KEY);
    try {
        cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    cipher.init(Cipher.DECRYPT_MODE, aesKey, new IvParameterSpec(vectorBytes));
    by = cipher.doFinal(encryptedMsg);
    try {
        str = new String(by, 0, by.length - 1, Utils.UTF8);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    } // w/o trailing \0
    return str;
}

From source file:com.linkedin.databus.core.DbusEventV1.java

private static int serializeLongKeyEvent(long key, ByteBuffer serializationBuffer, DbusEventInfo eventInfo) {
    byte[] attributes = null;

    // Event without explicit opcode specified should always be considered UPSERT or existing code will break
    if (eventInfo.getOpCode() == DbusOpcode.DELETE) {
        if (serializationBuffer.order() == ByteOrder.BIG_ENDIAN)
            attributes = DeleteLongKeyAttributesBigEndian.clone();
        else/*  w  w  w.  j a v a2 s.c o  m*/
            attributes = DeleteLongKeyAttributesLittleEndian.clone();
    } else {
        if (serializationBuffer.order() == ByteOrder.BIG_ENDIAN)
            attributes = UpsertLongKeyAttributesBigEndian.clone();
        else
            attributes = UpsertLongKeyAttributesLittleEndian.clone();
    }

    if (eventInfo.isEnableTracing()) {
        setTraceFlag(attributes, serializationBuffer.order());
    }
    if (eventInfo.isReplicated())
        setExtReplicationFlag(attributes, serializationBuffer.order());

    return serializeFullEvent(key, serializationBuffer, eventInfo, attributes);
}

From source file:edu.hawaii.soest.kilonalu.adam.AdamParser.java

/**
 * A method that gets the channel average data as a converted decimal float
 *
 * @return channelAverage - the 2 bytes of the channelAverage data as a float
 *//*from w  w  w . j a va  2s .  c  o  m*/
public float getChannelAverage() {
    this.channelAverage.flip();
    int channelData = (int) this.channelAverage.order(ByteOrder.BIG_ENDIAN).getShort();

    return getVoltage(channelData);
}

From source file:edu.hawaii.soest.kilonalu.adam.AdamParser.java

/**
 * A method that gets the channel zero maximum data as a converted decimal float
 *
 * @return channelZeroMax  - the 2 bytes of the channelZeroMax data as a float
 *//*from   ww w  .  j ava2  s  .  c om*/
public float getChannelZeroMax() {
    this.channelZeroMax.flip();
    int channelData = (int) this.channelZeroMax.order(ByteOrder.BIG_ENDIAN).getShort();

    return getVoltage(channelData);
}

From source file:de.tum.frm2.nicos_android.nicos.NicosClient.java

public void _write(String command, Object args) throws IOException {
    // Write a command to the server
    // Format: ENQ + commandcode + length + payload
    Pickler pickler = new Pickler();
    byte[] data = pickler.dumps(args);

    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    buffer.write(daemon.ENQ);/*from  ww  w .  jav  a  2s .co m*/
    // frame format requires: length of (ENQ + commandcode) == 3 bytes
    // That's why an empty byte gets inserted here.
    buffer.write((byte) 0x00);
    buffer.write(daemon.command2code(command));
    ByteBuffer bb = ByteBuffer.allocate(4);
    bb.order(ByteOrder.BIG_ENDIAN);
    bb.putInt(data.length);
    buffer.write(bb.array());
    buffer.write(data);
    socketOut.write(buffer.toByteArray());
    socketOut.flush();
}

From source file:edu.hawaii.soest.kilonalu.adam.AdamParser.java

/**
 * A method that gets the channel one data maximum as a converted decimal float
 *
 * @return channelOneMax - the 2 bytes of the channelOneMax data as a float
 *///from w ww.j a  v  a2  s. c om
public float getChannelOneMax() {
    this.channelOneMax.flip();
    int channelData = (int) this.channelOneMax.order(ByteOrder.BIG_ENDIAN).getShort();

    return getVoltage(channelData);
}

From source file:com.linkedin.databus.core.DbusEventV1.java

/**
 * Exposing this method only until we fix DDSDBUS-2282 is fixed.
 * DO NOT USE THIS METHOD EVEN IN TESTS.
 *///from w ww  .  j  a  v  a2s .com
protected static int serializeFullEventWithEmptyAttributes(long key, ByteBuffer buf, DbusEventInfo eventInfo) {
    return serializeFullEvent(key, buf, eventInfo,
            (buf.order() == ByteOrder.BIG_ENDIAN) ? EmptyAttributesBigEndian : EmptyAttributesLittleEndian);
}