List of usage examples for java.lang Long reverseBytes
@HotSpotIntrinsicCandidate public static long reverseBytes(long i)
From source file:org.apache.hadoop.hbase.util.UnsafeAccess.java
/** * Converts a byte array to a long value considering it was written in big-endian format. * @param bytes byte array//from w w w . j a v a 2s .com * @param offset offset into array * @return the long value */ public static long toLong(byte[] bytes, int offset) { if (littleEndian) { return Long.reverseBytes(theUnsafe.getLong(bytes, offset + BYTE_ARRAY_BASE_OFFSET)); } else { return theUnsafe.getLong(bytes, offset + BYTE_ARRAY_BASE_OFFSET); } }
From source file:org.apache.hadoop.hbase.util.UnsafeAccess.java
/** * Put a long value out to the specified byte array position in big-endian format. * @param bytes the byte array//from w ww. ja v a2 s . co m * @param offset position in the array * @param val long to write out * @return incremented offset */ public static int putLong(byte[] bytes, int offset, long val) { if (littleEndian) { val = Long.reverseBytes(val); } theUnsafe.putLong(bytes, offset + BYTE_ARRAY_BASE_OFFSET, val); return offset + Bytes.SIZEOF_LONG; }
From source file:org.apache.hadoop.hbase.util.UnsafeAccess.java
/** * Reads a long value at the given buffer's offset considering it was written in big-endian * format./*from w w w . j a va 2 s . c o m*/ * * @param buf * @param offset * @return long value at offset */ public static long toLong(ByteBuffer buf, int offset) { if (littleEndian) { return Long.reverseBytes(getAsLong(buf, offset)); } return getAsLong(buf, offset); }
From source file:org.apache.hadoop.hbase.util.UnsafeAccess.java
/** * Put a long value out to the specified BB position in big-endian format. * @param buf the byte buffer/*from w w w. j av a 2s .c o m*/ * @param offset position in the buffer * @param val long to write out * @return incremented offset */ public static int putLong(ByteBuffer buf, int offset, long val) { if (littleEndian) { val = Long.reverseBytes(val); } if (buf.isDirect()) { theUnsafe.putLong(((DirectBuffer) buf).address() + offset, val); } else { theUnsafe.putLong(buf.array(), BYTE_ARRAY_BASE_OFFSET + buf.arrayOffset() + offset, val); } return offset + Bytes.SIZEOF_LONG; }
From source file:org.apache.kylin.common.util.Bytes.java
/** * Put a long value out to the specified byte array position (Unsafe). * * @param bytes the byte array//from w w w . j a v a 2 s .com * @param offset position in the array * @param val long to write out * @return incremented offset */ public static int putLongUnsafe(byte[] bytes, int offset, long val) { if (org.apache.kylin.common.util.Bytes.LexicographicalComparerHolder.UnsafeComparer.littleEndian) { val = Long.reverseBytes(val); } org.apache.kylin.common.util.Bytes.LexicographicalComparerHolder.UnsafeComparer.theUnsafe.putLong(bytes, (long) offset + org.apache.kylin.common.util.Bytes.LexicographicalComparerHolder.UnsafeComparer.BYTE_ARRAY_BASE_OFFSET, val); return offset + SIZEOF_LONG; }
From source file:org.apache.kylin.common.util.Bytes.java
/** * Converts a byte array to an long value (Unsafe version) * * @param bytes byte array//from w w w .j av a2s . co m * @param offset offset into array * @return the long value */ public static long toLongUnsafe(byte[] bytes, int offset) { if (org.apache.kylin.common.util.Bytes.LexicographicalComparerHolder.UnsafeComparer.littleEndian) { return Long.reverseBytes( org.apache.kylin.common.util.Bytes.LexicographicalComparerHolder.UnsafeComparer.theUnsafe .getLong(bytes, (long) offset + org.apache.kylin.common.util.Bytes.LexicographicalComparerHolder.UnsafeComparer.BYTE_ARRAY_BASE_OFFSET)); } else { return org.apache.kylin.common.util.Bytes.LexicographicalComparerHolder.UnsafeComparer.theUnsafe .getLong(bytes, (long) offset + org.apache.kylin.common.util.Bytes.LexicographicalComparerHolder.UnsafeComparer.BYTE_ARRAY_BASE_OFFSET); } }
From source file:org.nuras.mcpha.Client.java
/** * Get timer value in seconds which is derived from the 64-bit unsigned * integer value returned from the server, that is the number of counts * at 125MHz from the start of the acquisition. * /*from w w w .ja v a2 s.c o m*/ * @param chan * @return the timer value in seconds since the start of acquisition * @throws java.io.IOException */ synchronized public static double mcphaGetTimerValue(long chan) throws IOException { sendCommand(MCPHA_COMMAND_READ_TIMER, chan, 0L); // read response DataInputStream in = new DataInputStream(deviceSocket.getInputStream()); long number = Long.reverseBytes(in.readLong()); return (double) number * TIME_PER_TICK; }
From source file:org.nuras.mcpha.Client.java
/** * Send command to device// ww w. j a v a 2s . com * * @param code * @param chan * @param data */ private static void sendCommand(long code, long chan, long data) throws IOException { logDebugMessage("sendCommand - code=" + code + ", chan=" + chan + ", data=" + data); DataOutputStream out = new DataOutputStream(deviceSocket.getOutputStream()); long b = (long) (code << SHIFT_CODE) | (validateChannel(chan) << SHIFT_CHAN) | data; out.writeLong(Long.reverseBytes(b)); }
From source file:srebrinb.compress.sevenzip.SevenZFile.java
private StartHeader readStartHeader(final long startHeaderCrc) throws IOException { final StartHeader startHeader = new StartHeader(); // using Stream rather than ByteBuffer for the benefit of the // built-in CRC check try (DataInputStream dataInputStream = new DataInputStream(new CRC32VerifyingInputStream( new BoundedSeekableByteChannelInputStream(channel, 20), 20, startHeaderCrc))) { startHeader.nextHeaderOffset = Long.reverseBytes(dataInputStream.readLong()); startHeader.nextHeaderSize = Long.reverseBytes(dataInputStream.readLong()); startHeader.nextHeaderCrc = 0xffffFFFFL & Integer.reverseBytes(dataInputStream.readInt()); return startHeader; }//from w w w. ja v a 2 s . c o m }
From source file:tudarmstadt.lt.ABSentiment.featureExtractor.util.GloVeSpace.java
/** * Read a Vector - Array from binary file * @param ds input data stream//from w ww.j a v a2s .co m * @param vectorSize length of each word vector * @return an array of float containing the word vector representation */ private static float[] readFloatVector(DataInputStream ds, int vectorSize) throws IOException { float[] vector = new float[vectorSize]; for (int j = 0; j < vectorSize; j++) { long l = ds.readLong(); float d = (float) (Long.reverseBytes(l)); vector[j] = d; } return vector; }