当前位置: 首页>>代码示例>>Java>>正文


Java ByteOrder类代码示例

本文整理汇总了Java中java.nio.ByteOrder的典型用法代码示例。如果您正苦于以下问题:Java ByteOrder类的具体用法?Java ByteOrder怎么用?Java ByteOrder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ByteOrder类属于java.nio包,在下文中一共展示了ByteOrder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import java.nio.ByteOrder; //导入依赖的package包/类
public void run() {
    try {
        DatagramChannel dc = DatagramChannel.open();
        ByteBuffer bb = ByteBuffer.allocateDirect(12);
        bb.order(ByteOrder.BIG_ENDIAN);
        bb.putInt(1).putLong(1);
        bb.flip();
        InetAddress address = InetAddress.getLocalHost();
        InetSocketAddress isa = new InetSocketAddress(address, port);
        dc.connect(isa);
        clientISA = dc.getLocalAddress();
        dc.write(bb);
    } catch (Exception ex) {
        e = ex;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:Sender.java

示例2: update

import java.nio.ByteOrder; //导入依赖的package包/类
/**
 * Create header using headerdata, expected to find header at headerdata current position
 *
 * Note after processing adjusts position to immediately after header
 *
 * @param headerData
 */
public void update(ByteBuffer headerData)
{
    //Read header data into byte array
    byte[] b = new byte[HEADER_LENGTH];
    headerData.get(b);
    //Keep reference to copy of RawData
    dataBuffer = ByteBuffer.wrap(b);
    dataBuffer.order(ByteOrder.BIG_ENDIAN);

    //Calculate box size and id
    this.length = dataBuffer.getInt();
    this.id = Utils.readFourBytesAsChars(dataBuffer);

    logger.finest("Mp4BoxHeader id:"+id+":length:"+length);
    if (id.equals("\0\0\0\0"))
    {
        throw new NullBoxIdException(ErrorMessage.MP4_UNABLE_TO_FIND_NEXT_ATOM_BECAUSE_IDENTIFIER_IS_INVALID.getMsg(id));
    }

    if(length<HEADER_LENGTH)
    {
        throw new InvalidBoxHeaderException(ErrorMessage.MP4_UNABLE_TO_FIND_NEXT_ATOM_BECAUSE_IDENTIFIER_IS_INVALID.getMsg(id,length));
    }
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:32,代码来源:Mp4BoxHeader.java

示例3: setupVarHandleSources

import java.nio.ByteOrder; //导入依赖的package包/类
@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(short[].class, bo),
                endianess, MemoryMode.READ_WRITE);
        vhss.add(aeh);

        VarHandleSource bbh = new VarHandleSource(
                MethodHandles.byteBufferViewVarHandle(short[].class, bo),
                endianess, MemoryMode.READ_WRITE);
        vhss.add(bbh);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:VarHandleTestByteArrayAsShort.java

示例4: wrap

import java.nio.ByteOrder; //导入依赖的package包/类
public static NativeByteBuffer wrap(int address) {
    NativeByteBuffer result = addressWrapper.get();
    if (address != 0) {
        if (!result.reused) {
            FileLog.e("tmessages", "forgot to reuse?");
        }
        result.address = address;
        result.reused = false;
        result.buffer = native_getJavaByteBuffer(address);
        result.buffer.limit(native_limit(address));
        int position = native_position(address);
        if (position <= result.buffer.limit()) {
            result.buffer.position(position);
        }
        result.buffer.order(ByteOrder.LITTLE_ENDIAN);
    }
    return result;
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:19,代码来源:NativeByteBuffer.java

示例5: and_B_with_A

import java.nio.ByteOrder; //导入依赖的package包/类
@Override
public void and_B_with_A ( AT_Machine_State state ) {
	ByteBuffer a = ByteBuffer.allocate(32);
	a.order( ByteOrder.LITTLE_ENDIAN );
	a.put(state.get_A1());
	a.put(state.get_A2());
	a.put(state.get_A3());
	a.put(state.get_A4());
	a.clear();
	
	ByteBuffer b = ByteBuffer.allocate(32);
	b.order( ByteOrder.LITTLE_ENDIAN );
	b.put(state.get_B1());
	b.put(state.get_B2());
	b.put(state.get_B3());
	b.put(state.get_B4());
	b.clear();
	
	state.set_B1(AT_API_Helper.getByteArray(a.getLong(0) & b.getLong(0)));
	state.set_B2(AT_API_Helper.getByteArray(a.getLong(8) & b.getLong(8)));
	state.set_B3(AT_API_Helper.getByteArray(a.getLong(16) & b.getLong(16)));
	state.set_B4(AT_API_Helper.getByteArray(a.getLong(24) & b.getLong(24)));
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:24,代码来源:AT_API_Impl.java

示例6: getInstance

import java.nio.ByteOrder; //导入依赖的package包/类
/**
 * Get an instance of a (Direct)ByteBuffer for the current thread
 *
 * @return Allocated (Direct)ByteBuffer
 */
public ByteBuffer getInstance() {
    int threadId = (int) Thread.currentThread().getId();

    if (threadId > m_pool.length) {
        // Copying without lock might result in lost allocations but this can be ignored
        ByteBuffer[] tmp = new ByteBuffer[m_pool.length + INITIAL_POOL_SIZE];
        System.arraycopy(m_pool, 0, tmp, 0, m_pool.length);
        m_pool = tmp;
    }

    if (m_pool[threadId] == null) {
        m_pool[threadId] = ByteBuffer.allocateDirect(m_dataSize);
        // consider native byte order (most likely little endian)
        m_pool[threadId].order(ByteOrder.nativeOrder());
    }

    return m_pool[threadId];
}
 
开发者ID:hhu-bsinfo,项目名称:dxram,代码行数:24,代码来源:IBSendWorkParameterPool.java

示例7: binarySearch

import java.nio.ByteOrder; //导入依赖的package包/类
public int binarySearch(PartitionPosition key)
{
    // We will be comparing non-native Keys, so use a buffer with appropriate byte order
    ByteBuffer hollow = MemoryUtil.getHollowDirectByteBuffer().order(ByteOrder.BIG_ENDIAN);
    int low = 0, mid = offsetCount, high = mid - 1, result = -1;
    while (low <= high)
    {
        mid = (low + high) >> 1;
        fillTemporaryKey(mid, hollow);
        result = -DecoratedKey.compareTo(partitioner, hollow, key);
        if (result > 0)
        {
            low = mid + 1;
        }
        else if (result == 0)
        {
            return mid;
        }
        else
        {
            high = mid - 1;
        }
    }

    return -mid - (result < 0 ? 1 : 2);
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:27,代码来源:IndexSummary.java

示例8: verifyPFB

import java.nio.ByteOrder; //导入依赖的package包/类
private void verifyPFB(ByteBuffer bb) throws FontFormatException {

        int pos = 0;
        while (true) {
            try {
                int segType = bb.getShort(pos) & 0xffff;
                if (segType == 0x8001 || segType == 0x8002) {
                    bb.order(ByteOrder.LITTLE_ENDIAN);
                    int segLen = bb.getInt(pos+2);
                    bb.order(ByteOrder.BIG_ENDIAN);
                    if (segLen <= 0) {
                        throw new FontFormatException("bad segment length");
                    }
                    pos += segLen+6;
                } else if (segType == 0x8003) {
                    return;
                } else {
                    throw new FontFormatException("bad pfb file");
                }
            } catch (BufferUnderflowException bue) {
                throw new FontFormatException(bue.toString());
            } catch (Exception e) {
                throw new FontFormatException(e.toString());
            }
        }
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:Type1Font.java

示例9: test

import java.nio.ByteOrder; //导入依赖的package包/类
public void test() throws Exception {
    CustomPlugin plugin = new CustomPlugin();
    PluginRepository.registerPlugin(plugin);
    List<Plugin> plugins = new ArrayList<>();
    plugins.add(createPlugin(CustomPlugin.NAME));
    ImagePluginStack stack = ImagePluginConfiguration.parseConfiguration(new Jlink.PluginsConfiguration(plugins,
            null, null));
    ResourcePoolManager inResources = new ResourcePoolManager(ByteOrder.nativeOrder(), new CustomStringTable());
    inResources.add(ResourcePoolEntry.create("/aaa/bbb/res1.class", new byte[90]));
    inResources.add(ResourcePoolEntry.create("/aaa/bbb/res2.class", new byte[90]));
    inResources.add(ResourcePoolEntry.create("/aaa/bbb/res3.class", new byte[90]));
    inResources.add(ResourcePoolEntry.create("/aaa/ddd/res1.class", new byte[90]));
    inResources.add(ResourcePoolEntry.create("/aaa/res1.class", new byte[90]));
    ResourcePool outResources = stack.visitResources(inResources);
    Collection<String> input = inResources.entries()
            .map(Object::toString)
            .collect(Collectors.toList());
    Collection<String> output = outResources.entries()
            .map(Object::toString)
            .collect(Collectors.toList());
    if (!input.equals(output)) {
        throw new AssertionError("Input and output resources differ: input: "
                + input + ", output: " + output);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:PrevisitorTest.java

示例10: ChunkRequestTask

import java.nio.ByteOrder; //导入依赖的package包/类
public ChunkRequestTask(Level level, Chunk chunk) {
    this.levelId = level.getId();
    this.chunk = chunk.toFastBinary();
    this.chunkX = chunk.getX();
    this.chunkZ = chunk.getZ();

    byte[] buffer = new byte[0];

    for (BlockEntity blockEntity : chunk.getBlockEntities().values()) {
        if (blockEntity instanceof BlockEntitySpawnable) {
            try {
                buffer = Binary.appendBytes(buffer, NBTIO.write(((BlockEntitySpawnable) blockEntity).getSpawnCompound(), ByteOrder.BIG_ENDIAN, true));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

        }
    }

    this.blockEntities = buffer;
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:22,代码来源:ChunkRequestTask.java

示例11: testAsMemory

import java.nio.ByteOrder; //导入依赖的package包/类
@Test
public void testAsMemory() {
  ByteBuffer bb = ByteBuffer.allocate(64).order(ByteOrder.nativeOrder());

  Byte b = 0;
  while (bb.hasRemaining()) {
    bb.put(b);
    b++;
  }
  bb.position(10);

  Buffer buffer = Buffer.wrap(bb);
  Memory memory = buffer.asMemory();

  assertEquals(buffer.getCapacity(), memory.getCapacity());

  while(buffer.hasRemaining()){
    assertEquals(memory.getByte(buffer.getPosition()), buffer.getByte());
  }
}
 
开发者ID:DataSketches,项目名称:memory,代码行数:21,代码来源:BufferTest2.java

示例12: testCanReadValidHeaderAndLSD

import java.nio.ByteOrder; //导入依赖的package包/类
@Test
public void testCanReadValidHeaderAndLSD() {
  final int width = 10;
  final int height = 20;
  ByteBuffer buffer =
      ByteBuffer.allocate(GifBytesTestUtil.HEADER_LENGTH).order(ByteOrder.LITTLE_ENDIAN);
  GifBytesTestUtil.writeHeaderAndLsd(buffer, width, height, false, 0);

  parser.setData(buffer.array());
  GifHeader header = parser.parseHeader();
  assertEquals(width, header.width);
  assertEquals(height, header.height);
  assertFalse(header.gctFlag);
  // 2^(1+0) == 2^1 == 2.
  assertEquals(2, header.gctSize);
  assertEquals(0, header.bgIndex);
  assertEquals(0, header.pixelAspect);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:GifHeaderParserTest.java

示例13: convertAudioBytes

import java.nio.ByteOrder; //导入依赖的package包/类
/**
 * Convert the audio bytes into the stream
 * 
 * @param audio_bytes The audio byts
 * @param two_bytes_data True if we using double byte data
 * @return The byte bufer of data
 */
private static ByteBuffer convertAudioBytes(byte[] audio_bytes, boolean two_bytes_data) {
	ByteBuffer dest = ByteBuffer.allocateDirect(audio_bytes.length);
	dest.order(ByteOrder.nativeOrder());
	ByteBuffer src = ByteBuffer.wrap(audio_bytes);
	src.order(ByteOrder.LITTLE_ENDIAN);
	if (two_bytes_data) {
		ShortBuffer dest_short = dest.asShortBuffer();
		ShortBuffer src_short = src.asShortBuffer();
		while (src_short.hasRemaining())
			dest_short.put(src_short.get());
	} else {
		while (src.hasRemaining())
			dest.put(src.get());
	}
	dest.rewind();
	return dest;
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:25,代码来源:WaveData.java

示例14: testCanParseMultipleFrames

import java.nio.ByteOrder; //导入依赖的package包/类
@Test
public void testCanParseMultipleFrames() {
  final int lzwMinCodeSize = 2;
  final int expectedFrames = 3;

  final int frameSize = GifBytesTestUtil.IMAGE_DESCRIPTOR_LENGTH + GifBytesTestUtil
      .getImageDataSize(lzwMinCodeSize);
  ByteBuffer buffer =
      ByteBuffer.allocate(GifBytesTestUtil.HEADER_LENGTH + expectedFrames * frameSize)
          .order(ByteOrder.LITTLE_ENDIAN);

  GifBytesTestUtil.writeHeaderAndLsd(buffer, 1, 1, false, 0);
  for (int i = 0; i < expectedFrames; i++) {
    GifBytesTestUtil.writeImageDescriptor(buffer, 0, 0, 1, 1, false /*hasLct*/, 0 /*numColors*/);
    GifBytesTestUtil.writeFakeImageData(buffer, 2);
  }

  parser.setData(buffer.array());
  GifHeader header = parser.parseHeader();
  assertEquals(expectedFrames, header.frameCount);
  assertEquals(expectedFrames, header.frames.size());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:GifHeaderParserTest.java

示例15: testIsNotAnimatedOneFrame

import java.nio.ByteOrder; //导入依赖的package包/类
@Test
public void testIsNotAnimatedOneFrame() {
  final int lzwMinCodeSize = 2;

  final int frameSize =
      GifBytesTestUtil.IMAGE_DESCRIPTOR_LENGTH
          + GifBytesTestUtil.getImageDataSize(lzwMinCodeSize);

  ByteBuffer buffer =
      ByteBuffer.allocate(GifBytesTestUtil.HEADER_LENGTH + frameSize)
          .order(ByteOrder.LITTLE_ENDIAN);

  GifBytesTestUtil.writeHeaderAndLsd(buffer, 1, 1, false, 0);
  GifBytesTestUtil.writeImageDescriptor(buffer, 0, 0, 1, 1, false /*hasLct*/, 0 /*numColors*/);
  GifBytesTestUtil.writeFakeImageData(buffer, 2);

  parser.setData(buffer.array());
  assertFalse(parser.isAnimated());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:GifHeaderParserTest.java


注:本文中的java.nio.ByteOrder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。