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:nl.salp.warcraft4j.util.DataTypeUtil.java

/**
 * Create a fixed size 64-bit (8 byte) byte[] from the given long value using a big endian byte order.
 *
 * @param value The value./*from  w  w w .  jav  a2s  .c o m*/
 *
 * @return The byte[].
 */
public static byte[] toByteArray(long value) {
    return toByteArray(value, ByteOrder.BIG_ENDIAN);
}

From source file:com.palantir.atlasdb.keyvalue.rocksdb.impl.RocksDbKeyValueServices.java

static byte[] getKey(byte[] row, byte[] col, long timeStamp) {
    Preconditions.checkArgument(EncodingUtils.sizeOfVarLong(row.length) <= 2);
    byte[] rowSize = EncodingUtils.encodeVarLong(row.length);
    ArrayUtils.reverse(rowSize);//from   www. j  av  a  2  s . co  m

    byte[] key = new byte[row.length + col.length + 8 + rowSize.length];
    ByteBuffer.wrap(key).order(ByteOrder.BIG_ENDIAN).put(row).put(col).putLong(timeStamp).put(rowSize);
    return key;
}

From source file:eu.xworlds.util.raknet.protocol.OpenConnectionRequest1.java

@Override
public ByteBuf encode() {
    final ByteBuf result = Unpooled.buffer(1 + 16 + this.magic.length + 1 + this.mtuPayload.length);
    result.order(ByteOrder.BIG_ENDIAN);
    result.writeByte(ID);//w w w . j av a 2 s.  c om
    result.writeBytes(this.magic);
    result.writeByte(this.procotolVersion);
    result.writeBytes(this.mtuPayload);
    return result;
}

From source file:eu.xworlds.util.raknet.protocol.BaseMessage.java

/**
 * writes an unsigned medium to byte buf
 * /*from   w ww . j  a v  a 2s  .co m*/
 * @param target target byte buffer.
 * @param value the unsigned medium value.
 */
protected void writeUnsignedMedium(ByteBuf target, int value) {
    if (value < 0 || value > 0xffffff) {
        throw new IllegalArgumentException(value + " exceeds allowed size"); //$NON-NLS-1$
    }
    if (target.order() == ByteOrder.BIG_ENDIAN) {
        target.writeByte(value >> 16);
        target.writeByte(value >> 8);
        target.writeByte(value);
    } else {
        target.writeByte(value);
        target.writeByte(value >> 8);
        target.writeByte(value >> 16);
    }
}

From source file:org.mcisb.util.math.MathUtils.java

/**
 * /*from   w  w w .  j ava2 s .co  m*/
 * @param values
 * @param bigEndian
 * @return String
 */
public static byte[] getBytes(final double[] values, final boolean bigEndian) {
    final byte[] byteArray = new byte[values.length * DOUBLE_LENGTH];
    ByteBuffer buffer = ByteBuffer.wrap(byteArray);
    buffer = buffer.order(bigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);

    for (int i = 0; i < values.length; i++) {
        buffer.putDouble(values[i]);
    }

    return buffer.array();
}

From source file:ca.psiphon.ploggy.Robohash.java

public static Bitmap getRobohash(Context context, boolean cacheCandidate, byte[] data)
        throws Utils.ApplicationError {
    try {// w w w.  j  a v a2  s. co  m
        MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
        byte[] digest = sha1.digest(data);

        String key = Utils.formatFingerprint(digest);
        Bitmap cachedBitmap = mCache.get(key);
        if (cachedBitmap != null) {
            return cachedBitmap;
        }

        ByteBuffer byteBuffer = ByteBuffer.wrap(digest);
        byteBuffer.order(ByteOrder.BIG_ENDIAN);
        // TODO: SecureRandom SHA1PRNG (but not LinuxSecureRandom)
        Random random = new Random(byteBuffer.getLong());

        AssetManager assetManager = context.getAssets();

        if (mConfig == null) {
            mConfig = new JSONObject(loadAssetToString(assetManager, CONFIG_FILENAME));
        }

        int width = mConfig.getInt("width");
        int height = mConfig.getInt("height");

        JSONArray colors = mConfig.getJSONArray("colors");
        JSONArray parts = colors.getJSONArray(random.nextInt(colors.length()));

        Bitmap robotBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas robotCanvas = new Canvas(robotBitmap);

        for (int i = 0; i < parts.length(); i++) {
            JSONArray partChoices = parts.getJSONArray(i);
            String selection = partChoices.getString(random.nextInt(partChoices.length()));
            Bitmap partBitmap = loadAssetToBitmap(assetManager, selection);
            Rect rect = new Rect(0, 0, width, height);
            Paint paint = new Paint();
            paint.setAlpha(255);
            robotCanvas.drawBitmap(partBitmap, rect, rect, paint);
            partBitmap.recycle();
        }

        if (cacheCandidate) {
            mCache.set(key, robotBitmap);
        }

        return robotBitmap;

    } catch (IOException e) {
        throw new Utils.ApplicationError(LOG_TAG, e);
    } catch (JSONException e) {
        throw new Utils.ApplicationError(LOG_TAG, e);
    } catch (NoSuchAlgorithmException e) {
        throw new Utils.ApplicationError(LOG_TAG, e);
    }
}

From source file:com.linkedin.databus.client.pub.TestUnifiedClientStats.java

private DbusEvent createEvent(long timestampNs) {
    DbusEventInfo eventInfo = new DbusEventInfo(DbusOpcode.UPSERT, 6004L, // SCN
            (short) 1, // physical partition ID
            (short) 1, // logical partition ID
            timestampNs, (short) 1, // srcId
            SOURCE1_SCHEMAID, // payloadSchemaMd5
            SOURCE1_PAYLOAD, // payload
            false, // enableTracing
            true); // autocommit
    DbusEventKey key = new DbusEventKey("myKey".getBytes(Charset.forName("UTF-8")));
    ByteBuffer buf = ByteBuffer.allocate(1000).order(ByteOrder.BIG_ENDIAN);
    try {/*from   www  .  jav  a 2s . co  m*/
        DbusEventFactory.serializeEvent(key, buf, eventInfo);
    } catch (KeyTypeNotImplementedException ex) {
        fail("string key type not supported by DbusEventV2Factory?!? " + ex.getLocalizedMessage());
    }
    return _eventFactory.createReadOnlyDbusEventFromBuffer(buf, 0);
}

From source file:xbird.server.services.RemotePagingService.java

public RemotePagingService() {
    super(SRV_NAME);
    this._fdCacheMap = new FinalizableSoftValueReferenceMap<String, FileChannel>(
            new ReferentFinalizer<FileChannel>() {
                public void finalize(FileChannel reclaimed) {
                    IOUtils.closeQuietly(reclaimed);
                }/*from   w  w w  .  j a v  a 2 s.  c om*/
            });
    this._directoryCache = new ReferenceMap<String, IDescriptor>(ReferenceType.STRONG, ReferenceType.SOFT);
    if (SystemUtils.isSendfileSupported()) {
        this._sndBufSegm = null;
        this._sndBufDTM = null;
    } else {
        this._sndBufSegm = ByteBuffer.allocateDirect(SND_BUFSIZE);
        _sndBufSegm.order(ByteOrder.BIG_ENDIAN);
        this._sndBufDTM = ByteBuffer.allocateDirect(SND_BUFSIZE);
        _sndBufDTM.order(ByteOrder.LITTLE_ENDIAN);
    }
}

From source file:nl.salp.warcraft4j.util.DataTypeUtil.java

/**
 * Create a fixed-size 64-bit (8 byte) byte[] from an int value using a byte order.
 *
 * @param value     The value./*from ww w .j  a  v  a  2 s  .  c  o m*/
 * @param byteOrder The byte order, using {@code ByteOrder#BIG_ENDIAN} when the byte order is {@code null}.
 *
 * @return The byte[].
 */
public static byte[] toByteArray(long value, ByteOrder byteOrder) {
    byte[] longArray = new byte[Long.BYTES];
    ByteBuffer.wrap(longArray).order(Optional.ofNullable(byteOrder).orElse(ByteOrder.BIG_ENDIAN))
            .putLong(value);
    return longArray;
}

From source file:org.esa.s2tbx.dataio.spot.dimap.SpotViewMetadataTest.java

@Test
public void testGetRasterJavaByteOrder() throws Exception {
    assertEquals(ByteOrder.BIG_ENDIAN, metadata.getRasterJavaByteOrder());
}