Java ByteBuffer Get getAddressFromDirectByteBuffer(ByteBuffer buffer)

Here you can find the source of getAddressFromDirectByteBuffer(ByteBuffer buffer)

Description

Gets the address value for the memory that backs a direct byte buffer.

License

Apache License

Parameter

Parameter Description
buffer a parameter

Return

The system address for the buffers

Declaration

public static long getAddressFromDirectByteBuffer(ByteBuffer buffer) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Field;
import java.nio.Buffer;
import java.nio.ByteBuffer;

public class Main {
    /**/*w w  w  .  ja  v a 2 s  . c o  m*/
     * Gets the address value for the memory that backs a direct byte buffer.
     *
     * @param buffer
     * @return The system address for the buffers
     */
    public static long getAddressFromDirectByteBuffer(ByteBuffer buffer) {
        try {
            Field addressField = Buffer.class.getDeclaredField("address");
            addressField.setAccessible(true);
            return addressField.getLong(buffer);
        } catch (Exception e) {
            throw new RuntimeException("Unable to address field from ByteBuffer", e);
        }
    }
}

Related

  1. get3ByteInt(ByteBuffer buffer)
  2. getActiveArray(ByteBuffer buffer)
  3. getAddress(ByteBuffer buf)
  4. getAddress(ByteBuffer buffer)
  5. getAddress(ByteBuffer buffer)
  6. getArray(ByteBuffer buffer)
  7. getAsByteBuffer()
  8. getAsBytes(List buffers)
  9. getAscii(ByteBuffer bytes)