<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    I/O View ByteBuffer - Primitive Types

    The ByteBuffer is produced by "wrapping" an eight-byte array, which is then displayed via view buffers of all the different primitive types. You can see in the following diagram the way the data appears differently when read from the different types of buffers:

    package think.in.java.io;

    import java.nio.ByteBuffer;
    import java.nio.CharBuffer;
    import java.nio.DoubleBuffer;
    import java.nio.FloatBuffer;
    import java.nio.IntBuffer;
    import java.nio.LongBuffer;
    import java.nio.ShortBuffer;

    public class ViewBuffers {

        
    public static void main(String[] args) {
            
    //-------------ByteBuffer-----------
            ByteBuffer bb = ByteBuffer.wrap(new byte[]{0,0,0,0,0,0,0,'a'});
            bb.rewind();
            System.out.println(
    "-----Byte Buffer-----");
            
    while(bb.hasRemaining()){
                System.out.println(bb.position() 
    + " -> " + bb.get() + "");
            }
            
    //-------------CharBuffer-----------
            CharBuffer cb = ((ByteBuffer)bb.rewind()).asCharBuffer();
            System.out.println(
    "-----Char Buffer-----");
            
    while(cb.hasRemaining()){
                System.out.println(cb.position() 
    + " -> " + cb.get() + "");
            }
            
    //-------------FloatBuffer-----------
            FloatBuffer fb = ((ByteBuffer)bb.rewind()).asFloatBuffer();
            System.out.println(
    "-----Float Buffer-----");
            
    while(fb.hasRemaining()){
                System.out.println(fb.position() 
    + " -> " + fb.get() + "");
            }
            
    //-------------IntBuffer-----------
            IntBuffer ib = ((ByteBuffer)bb.rewind()).asIntBuffer();
            System.out.println(
    "-----Int Buffer-----");
            
    while(ib.hasRemaining()){
                System.out.println(ib.position() 
    + " -> " + ib.get() + "");
            }
            
    //-------------LongBuffer-----------
            LongBuffer lb = ((ByteBuffer)bb.rewind()).asLongBuffer();
            System.out.println(
    "-----Long Buffer-----");
            
    while(lb.hasRemaining()){
                System.out.println(lb.position() 
    + " -> " + lb.get() + "");
            }
            
    //-------------ShortBuffer-----------
            ShortBuffer sb = ((ByteBuffer)bb.rewind()).asShortBuffer();
            System.out.println(
    "-----Short Buffer-----");
            
    while(sb.hasRemaining()){
                System.out.println(sb.position() 
    + " -> " + sb.get() + "");
            }
            
    //-------------DoubleBuffer-----------
            DoubleBuffer db = ((ByteBuffer)bb.rewind()).asDoubleBuffer();
            System.out.println(
    "-----Double Buffer-----");
            
    while(db.hasRemaining()){
                System.out.println(db.position() 
    + " -> " + db.get() + "");
            }
            
        }

    }

    // Output:
    -----Byte Buffer-----
    0 -> 0
    1 -> 0
    2 -> 0
    3 -> 0
    4 -> 0
    5 -> 0
    6 -> 0
    7 -> 97
    -----Char Buffer-----
    0 -> ,
    1 -> ,
    2 -> ,
    3 -> a,
    -----Float Buffer-----
    0 -> 0.0
    1 -> 1.36E-43
    -----Int Buffer-----
    0 -> 0
    1 -> 97
    -----Long Buffer-----
    0 -> 97
    -----Short Buffer-----
    0 -> 0
    1 -> 0
    2 -> 0
    3 -> 97
    -----Double Buffer-----
    0 -> 4.8E-322,



    A ByteBuffer stores data in bug endian form, and data sent over a network always uses big endian order.
    You can change the endian-ness of ByteBuffer using order() with an argument of ByteOrder.BIG_ENDIAN or ByteBOrder.LITTLE_ENDIAN.



    If you want to write a byte array to a file, then you wrap  the byte array using the ByteBuffer.wrap() method, open a channel on the FileOutputStream using the getChannel() method, and then write data into FileChannel from this ByteBuffer.




















    posted on 2012-11-07 10:46 鹽城小土包 閱讀(198) 評論(0)  編輯  收藏 所屬分類: J2EE

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導航

    統(tǒng)計

    常用鏈接

    留言簿

    隨筆檔案(14)

    文章分類(18)

    文章檔案(18)

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲AV无码片一区二区三区| 99久久免费国产香蕉麻豆| 亚洲国产视频久久| 亚洲永久精品ww47| 日本免费v片一二三区| 久草视频免费在线| 无码人妻久久一区二区三区免费| 永久免费精品影视网站| 亚洲日韩国产二区无码| 亚洲国产日韩在线| 久久精品亚洲一区二区三区浴池 | 亚洲综合激情六月婷婷在线观看| 亚洲一区二区视频在线观看| 免费特级黄毛片在线成人观看| 国产91色综合久久免费| 美丽姑娘免费观看在线观看中文版| 国产日韩久久免费影院| h视频在线免费观看| 免费福利资源站在线视频| 亚洲欧美日韩综合久久久| 国产精品亚洲四区在线观看| 亚洲日本香蕉视频观看视频| 久久亚洲AV成人无码| 亚洲综合在线观看视频| 亚洲宅男永久在线| 亚洲国产一区二区a毛片| 亚洲av无码片在线播放| 亚洲AV日韩AV天堂久久| 久久精品国产96精品亚洲| 亚洲AV无码国产在丝袜线观看| 久久久久久久综合日本亚洲| 亚洲成av人片天堂网| 久久精品国产精品亚洲色婷婷| 久久精品亚洲一区二区| 亚洲天天在线日亚洲洲精| 日韩亚洲Av人人夜夜澡人人爽| 亚洲经典在线中文字幕| 亚洲一级片在线播放| 亚洲男人的天堂网站| 看亚洲a级一级毛片| 永久免费无码网站在线观看个|