本文整理汇总了Java中java.nio.ByteOrder.BIG_ENDIAN属性的典型用法代码示例。如果您正苦于以下问题:Java ByteOrder.BIG_ENDIAN属性的具体用法?Java ByteOrder.BIG_ENDIAN怎么用?Java ByteOrder.BIG_ENDIAN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.nio.ByteOrder
的用法示例。
在下文中一共展示了ByteOrder.BIG_ENDIAN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeOrder
/**
* Convert the string to a {@link ByteOrder}
*
* @param string
* the string to convert
* @param defaultOrder
* the default data byte order to use when
* <code>string</string> is <code>null</code>
* @return the byte order
* @throws IllegalArgumentException
* if the string is neither <code>null</code>, "BIG_ENDIAN" nor
* "LITTLE_ENDIAN"
*/
public static ByteOrder makeOrder ( final String string, final ByteOrder defaultOrder )
{
if ( string == null )
{
return defaultOrder;
}
if ( ByteOrder.BIG_ENDIAN.toString ().equals ( string ) )
{
return ByteOrder.BIG_ENDIAN;
}
if ( ByteOrder.LITTLE_ENDIAN.toString ().equals ( string ) )
{
return ByteOrder.LITTLE_ENDIAN;
}
throw new IllegalArgumentException ( String.format ( "'%s' is not a valid byte order", string ) );
}
示例2: setupVarHandleSources
@Override
public void setupVarHandleSources() {
// Combinations of VarHandle byte[] or ByteBuffer
vhss = new ArrayList<>();
for (MemoryMode endianess : Arrays.asList(MemoryMode.BIG_ENDIAN, MemoryMode.LITTLE_ENDIAN)) {
ByteOrder bo = endianess == MemoryMode.BIG_ENDIAN
? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
VarHandleSource aeh = new VarHandleSource(
MethodHandles.byteArrayViewVarHandle(int[].class, bo),
endianess, MemoryMode.READ_WRITE);
vhss.add(aeh);
VarHandleSource bbh = new VarHandleSource(
MethodHandles.byteBufferViewVarHandle(int[].class, bo),
endianess, MemoryMode.READ_WRITE);
vhss.add(bbh);
}
}
示例3: bomStream
/**
* Convert stream to ByteArrayInputStream by given character set.
* @param charset target character set.
* @param file a file that contains no BOM head content.
* @return a ByteArrayInputStream contains BOM heads and bytes in original
* stream
* @throws IOException I/O operation failed or unsupported character set.
*/
public static InputStream bomStream(String charset, String file)
throws IOException {
String localCharset = charset;
if (charset.equals("UTF-16") || charset.equals("UTF-32")) {
localCharset
+= ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN ? "BE" : "LE";
}
if (!bom.containsKey(localCharset))
throw new UnsupportedCharsetException("Charset:" + localCharset);
byte[] content = Files.readAllLines(Paths.get(file)).stream().
collect(Collectors.joining()).getBytes(localCharset);
byte[] head = bom.get(localCharset);
ByteBuffer bb = ByteBuffer.allocate(content.length + head.length);
bb.put(head);
bb.put(content);
return new ByteArrayInputStream(bb.array());
}
示例4: handleData
protected void handleData ( final ReadResponse readResponse )
{
IoBuffer data = readResponse.getData ();
if ( this.dataOrder != ByteOrder.BIG_ENDIAN )
{
switch ( readResponse.getFunctionCode () )
{
case Constants.FUNCTION_CODE_READ_HOLDING_REGISTERS: //$FALL-THROUGH$
case Constants.FUNCTION_CODE_READ_INPUT_REGISTERS:
// only switch bytes if byte order is not BIG_ENDIAN and we do read analog registers
data = ModbusProtocol.convertData ( readResponse.getData (), this.dataOrder );
break;
}
}
handleData ( data );
}
示例5: readInt
private static int readInt(byte[] buf, int i)
{
if (NATIVE_BYTE_ORDER == ByteOrder.BIG_ENDIAN)
{
return readIntBE(buf, i);
}
else
{
return readIntLE(buf, i);
}
}
示例6: ReceiveUnsigned2ByteNumber
/**
* Reads an unsigned 2-byte number.
*/
@SimpleFunction(description = "Receive a unsigned 2-byte number from the connected " +
"Bluetooth device.")
public int ReceiveUnsigned2ByteNumber() {
byte[] bytes = read("ReceiveUnsigned2ByteNumber", 2);
if (bytes.length != 2) {
return 0; // an error occurred
}
if (byteOrder == ByteOrder.BIG_ENDIAN) {
return (bytes[1] & 0xFF) | ((bytes[0] & 0xFF) << 8);
} else {
return (bytes[0] & 0xFF) | ((bytes[1] & 0xFF) << 8);
}
}
示例7: getFormat
public static AudioFormat getFormat() {
float sampleRate = 8000;
int sampleSizeInBits = 16;
int channels = 1;
boolean signed = true;
// The platform default byte order
boolean bigEndian = ByteOrder.nativeOrder()==ByteOrder.BIG_ENDIAN;
return new AudioFormat(sampleRate, sampleSizeInBits, channels, signed, bigEndian);
}
示例8: pokeInt
public static void pokeInt(byte[] dst, int offset, int value, ByteOrder order) {
if (order == ByteOrder.BIG_ENDIAN) {
dst[offset++] = (byte) ((value >> 24) & 0xff);
dst[offset++] = (byte) ((value >> 16) & 0xff);
dst[offset++] = (byte) ((value >> 8) & 0xff);
dst[offset] = (byte) ((value >> 0) & 0xff);
} else {
dst[offset++] = (byte) ((value >> 0) & 0xff);
dst[offset++] = (byte) ((value >> 8) & 0xff);
dst[offset++] = (byte) ((value >> 16) & 0xff);
dst[offset] = (byte) ((value >> 24) & 0xff);
}
}
示例9: getShortFromBytes
static short getShortFromBytes(ByteBuffer bb, int i) {
int a = bb.get(i) & 0xFF;
int b = bb.get(i + 1) & 0xFF;
if (bb.order() == ByteOrder.BIG_ENDIAN) {
return (short) ((a << 8) | b);
}
else {
return (short) ((b << 8) | a);
}
}
示例10: UnsafeDirectLittleEndian
private UnsafeDirectLittleEndian(AbstractByteBuf buf, boolean fake) {
super(buf);
if (!NATIVE_ORDER || buf.order() != ByteOrder.BIG_ENDIAN) {
throw new IllegalStateException("Drill only runs on LittleEndian systems.");
}
wrapped = buf;
this.memoryAddress = buf.memoryAddress();
}
示例11: readShort
public short readShort() throws IOException {
if (read(byteBuf, 0, 2) != 2) {
throw new EOFException();
}
if (byteOrder == ByteOrder.BIG_ENDIAN) {
return (short)
(((byteBuf[0] & 0xff) << 8) | ((byteBuf[1] & 0xff) << 0));
} else {
return (short)
(((byteBuf[1] & 0xff) << 8) | ((byteBuf[0] & 0xff) << 0));
}
}
示例12: writeLong
public void writeLong(long v) throws IOException {
if (byteOrder == ByteOrder.BIG_ENDIAN) {
byteBuf[0] = (byte)(v >>> 56);
byteBuf[1] = (byte)(v >>> 48);
byteBuf[2] = (byte)(v >>> 40);
byteBuf[3] = (byte)(v >>> 32);
byteBuf[4] = (byte)(v >>> 24);
byteBuf[5] = (byte)(v >>> 16);
byteBuf[6] = (byte)(v >>> 8);
byteBuf[7] = (byte)(v >>> 0);
} else {
byteBuf[0] = (byte)(v >>> 0);
byteBuf[1] = (byte)(v >>> 8);
byteBuf[2] = (byte)(v >>> 16);
byteBuf[3] = (byte)(v >>> 24);
byteBuf[4] = (byte)(v >>> 32);
byteBuf[5] = (byte)(v >>> 40);
byteBuf[6] = (byte)(v >>> 48);
byteBuf[7] = (byte)(v >>> 56);
}
// REMIND: Once 6277756 is fixed, we should do a bulk write of all 8
// bytes here as we do in writeShort() and writeInt() for even better
// performance. For now, two bulk writes of 4 bytes each is still
// faster than 8 individual write() calls (see 6347575 for details).
write(byteBuf, 0, 4);
write(byteBuf, 4, 4);
}
示例13: readChunk
/**
* Reads an AIFF Chunk.
*
* @return {@code false}, if we were not able to read a valid chunk id
*/
private boolean readChunk(FileChannel fc, AiffAudioHeader aiffAudioHeader, String fileName) throws IOException, CannotReadException {
logger.config(fileName + " Reading Info Chunk");
final Chunk chunk;
final ChunkHeader chunkHeader = new ChunkHeader(ByteOrder.BIG_ENDIAN);
if (!chunkHeader.readHeader(fc)) {
return false;
}
logger.config(fileName + "Reading Next Chunk:" + chunkHeader.getID() + ":starting at:" + chunkHeader.getStartLocationInFile() + ":sizeIncHeader:" + (chunkHeader.getSize() + ChunkHeader.CHUNK_HEADER_SIZE));
chunk = createChunk(fc, chunkHeader, aiffAudioHeader);
if (chunk != null) {
if (!chunk.readChunk()) {
logger.severe(fileName + "ChunkReadFail:" + chunkHeader.getID());
return false;
}
} else {
if (chunkHeader.getSize() < 0) {
String msg = fileName + " Not a valid header, unable to read a sensible size:Header"
+ chunkHeader.getID() + "Size:" + chunkHeader.getSize();
logger.severe(msg);
throw new CannotReadException(msg);
}
fc.position(fc.position() + chunkHeader.getSize());
}
IffHeaderChunk.ensureOnEqualBoundary(fc, chunkHeader);
return true;
}
示例14: parseExifSegment
private static int parseExifSegment(RandomAccessReader segmentData) {
ByteOrder byteOrder;
int headerOffsetSize = JPEG_EXIF_SEGMENT_PREAMBLE.length();
short byteOrderIdentifier = segmentData.getInt16(headerOffsetSize);
if (byteOrderIdentifier == (short) 19789) {
byteOrder = ByteOrder.BIG_ENDIAN;
} else if (byteOrderIdentifier == (short) 18761) {
byteOrder = ByteOrder.LITTLE_ENDIAN;
} else {
if (Log.isLoggable(TAG, 3)) {
Log.d(TAG, "Unknown endianness = " + byteOrderIdentifier);
}
byteOrder = ByteOrder.BIG_ENDIAN;
}
segmentData.order(byteOrder);
int firstIfdOffset = segmentData.getInt32(headerOffsetSize + 4) + headerOffsetSize;
int tagCount = segmentData.getInt16(firstIfdOffset);
for (int i = 0; i < tagCount; i++) {
int tagOffset = calcTagOffset(firstIfdOffset, i);
int tagType = segmentData.getInt16(tagOffset);
if (tagType == ORIENTATION_TAG_TYPE) {
int formatCode = segmentData.getInt16(tagOffset + 2);
if (formatCode >= 1 && formatCode <= 12) {
int componentCount = segmentData.getInt32(tagOffset + 4);
if (componentCount >= 0) {
if (Log.isLoggable(TAG, 3)) {
Log.d(TAG, "Got tagIndex=" + i + " tagType=" + tagType + " " +
"formatCode=" + formatCode + " componentCount=" +
componentCount);
}
int byteCount = componentCount + BYTES_PER_FORMAT[formatCode];
if (byteCount <= 4) {
int tagValueOffset = tagOffset + 8;
if (tagValueOffset < 0 || tagValueOffset > segmentData.length()) {
if (Log.isLoggable(TAG, 3)) {
Log.d(TAG, "Illegal tagValueOffset=" + tagValueOffset + " " +
"tagType=" + tagType);
}
} else if (byteCount >= 0 && tagValueOffset + byteCount <=
segmentData.length()) {
return segmentData.getInt16(tagValueOffset);
} else {
if (Log.isLoggable(TAG, 3)) {
Log.d(TAG, "Illegal number of bytes for TI tag data tagType="
+ tagType);
}
}
} else if (Log.isLoggable(TAG, 3)) {
Log.d(TAG, "Got byte count > 4, not orientation, continuing, " +
"formatCode=" + formatCode);
}
} else if (Log.isLoggable(TAG, 3)) {
Log.d(TAG, "Negative tiff component count");
}
} else if (Log.isLoggable(TAG, 3)) {
Log.d(TAG, "Got invalid format code = " + formatCode);
}
}
}
return -1;
}
示例15: NBTInputStream
public NBTInputStream(InputStream stream) {
this(stream, ByteOrder.BIG_ENDIAN);
}