⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e162. getting and setting non-byte java types in a bytebuffer.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
The ByteBuffer class provides convenience methods for getting and putting other multibyte Java primitive types. There are two issues to be aware of when using these methods. First, ensure that values will be stored using the desired byte ordering; see e165 Setting the Byte Ordering for a ByteBuffer for more information. Second, the hasRemaining() method cannot be used to determine if the buffer has room for a multibyte put. If your application needs to know this information, see e163 Creating a Non-Byte Java Type Buffer on a ByteBuffer for an example that can provide this information. 
    // Obtain a ByteBuffer; see also e158 Creating a ByteBuffer
    ByteBuffer buf = ByteBuffer.allocate(100);
    
    // Put values of different types
    buf.putChar((char)123);
    buf.putShort((short)123);
    buf.putInt(123);
    buf.putLong(123L);
    buf.putFloat(12.3F);
    buf.putDouble(12.3D);
    
    // Reset position for reading
    buf.flip();
    
    // Retrieve the values
    char c = buf.getChar();
    short s = buf.getShort();
    int i = buf.getInt();
    long l = buf.getLong();
    float f = buf.getFloat();
    double d = buf.getDouble();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -