當前位置: 首頁>>代碼示例>>Java>>正文


Java DirectBuffer類代碼示例

本文整理匯總了Java中sun.nio.ch.DirectBuffer的典型用法代碼示例。如果您正苦於以下問題:Java DirectBuffer類的具體用法?Java DirectBuffer怎麽用?Java DirectBuffer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DirectBuffer類屬於sun.nio.ch包,在下文中一共展示了DirectBuffer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setBytes

import sun.nio.ch.DirectBuffer; //導入依賴的package包/類
public void setBytes(long memoryOffset, ByteBuffer buffer)
{
    if (buffer == null)
        throw new NullPointerException();
    else if (buffer.remaining() == 0)
        return;

    checkBounds(memoryOffset, memoryOffset + buffer.remaining());
    if (buffer.hasArray())
    {
        setBytes(memoryOffset, buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
    }
    else if (buffer instanceof DirectBuffer)
    {
        unsafe.copyMemory(((DirectBuffer) buffer).address() + buffer.position(), peer + memoryOffset, buffer.remaining());
    }
    else
        throw new IllegalStateException();
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:20,代碼來源:Memory.java

示例2: testAllocateSign

import sun.nio.ch.DirectBuffer; //導入依賴的package包/類
@Test
public void testAllocateSign() {
    int size = 256;
    int pageSize = size * 4;
    int allocTimes = 9;
    DirectByteBufferPool pool = new DirectByteBufferPool(pageSize, (short) 256, (short) 2);
    long start = System.currentTimeMillis();
    ByteBuffer byteBuffer = null;
    List<ByteBuffer> buffs = new ArrayList<ByteBuffer>();
    int i = 0;
    for (; i < allocTimes; i++) {
        byteBuffer = pool.allocate(size);
        if (byteBuffer == null || !(byteBuffer instanceof DirectBuffer)) {
            break;
        }
        buffs.add(byteBuffer);
    }
    for (ByteBuffer buff : buffs) {
        pool.recycle(buff);
    }

    Assert.assertEquals("Should out of memory when i = " + 8, i, 8);
}
 
開發者ID:actiontech,項目名稱:dble,代碼行數:24,代碼來源:TestDirectByteBufferPool.java

示例3: freeByteBuffer

import sun.nio.ch.DirectBuffer; //導入依賴的package包/類
public synchronized void freeByteBuffer(ByteBuffer byteBuffer) {
    long address = ((DirectBuffer) byteBuffer).address();
    int relativeAddress = (int) (address - bufAddress);
    int length = byteBuffer.capacity();

    int depth = maxOrder - 1 - log2(length / pageSize);
    int count = 0;
    int i;
    for (i = 0; i < depthMap.length; i++) {
        if (depthMap[i] == depth) {
            if (count == relativeAddress) {
                break;
            }
            count += length;
        }
        if (depthMap[i] > depth) {
            break;
        }
    }
    free(i);
}
 
開發者ID:huang-up,項目名稱:mycat-src-1.6.1-RELEASE,代碼行數:22,代碼來源:ByteBufferChunk.java

示例4: recycle

import sun.nio.ch.DirectBuffer; //導入依賴的package包/類
public void recycle(ByteBuffer theBuf) {
	if(!(theBuf instanceof DirectBuffer)){
		theBuf.clear();
		return;
	}

	final long size = theBuf.capacity();

    boolean recycled = false;
    DirectBuffer thisNavBuf = (DirectBuffer) theBuf;
    int chunkCount = theBuf.capacity() / chunkSize;
    DirectBuffer parentBuf = (DirectBuffer) thisNavBuf.attachment();
    int startChunk = (int) ((thisNavBuf.address() - parentBuf.address()) / this.chunkSize);
    for (int i = 0; i < allPages.length; i++) {
        if ((recycled = allPages[i].recycleBuffer((ByteBuffer) parentBuf, startChunk, chunkCount) == true)) {
            break;
        }
    }
    final long threadId = Thread.currentThread().getId();

    if (memoryUsage.containsKey(threadId)){
        memoryUsage.put(threadId,memoryUsage.get(threadId)-size);
    }
    if (recycled == false) {
        LOGGER.warn("warning ,not recycled buffer " + theBuf);
    }
}
 
開發者ID:huang-up,項目名稱:mycat-src-1.6.1-RELEASE,代碼行數:28,代碼來源:DirectByteBufferPool.java

示例5: testAllocateNullWhenOutOfMemory

import sun.nio.ch.DirectBuffer; //導入依賴的package包/類
@Test
public void testAllocateNullWhenOutOfMemory() {
    int size = 256;
    int pageSize = size * 4;
    int allocTimes = 9;
    DirectByteBufferPool pool = new DirectByteBufferPool(pageSize, (short) 256, (short) 2);
    long start = System.currentTimeMillis();
    ByteBuffer byteBuffer = null;
    List<ByteBuffer> buffs = new ArrayList<ByteBuffer>();
    int i = 0;
    for (; i < allocTimes; i++) {
        byteBuffer = pool.allocate(size);
        if (byteBuffer == null || !(byteBuffer instanceof DirectBuffer)) {
            break;
        }
        buffs.add(byteBuffer);
    }
    for (ByteBuffer buff : buffs) {
        pool.recycle(buff);
    }

    Assert.assertEquals("Should out of memory when i = " + 8, i, 8);
}
 
開發者ID:actiontech,項目名稱:dble,代碼行數:24,代碼來源:TestDirectByteBufferPool.java

示例6: update

import sun.nio.ch.DirectBuffer; //導入依賴的package包/類
/**
 * Updates the checksum with the bytes from the specified buffer.
 *
 * The checksum is updated using
 * buffer.{@link java.nio.Buffer#remaining() remaining()}
 * bytes starting at
 * buffer.{@link java.nio.Buffer#position() position()}
 * Upon return, the buffer's position will be updated to its
 * limit; its limit will not have been changed.
 *
 * @param buffer the ByteBuffer to update the checksum with
 * @since 1.8
 */
public void update(ByteBuffer buffer) {
    int pos = buffer.position();
    int limit = buffer.limit();
    assert (pos <= limit);
    int rem = limit - pos;
    if (rem <= 0)
        return;
    if (buffer instanceof DirectBuffer) {
        adler = updateByteBuffer(adler, ((DirectBuffer)buffer).address(), pos, rem);
    } else if (buffer.hasArray()) {
        adler = updateBytes(adler, buffer.array(), pos + buffer.arrayOffset(), rem);
    } else {
        byte[] b = new byte[rem];
        buffer.get(b);
        adler = updateBytes(adler, b, 0, b.length);
    }
    buffer.position(limit);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:32,代碼來源:Adler32.java

示例7: engineUpdate

import sun.nio.ch.DirectBuffer; //導入依賴的package包/類
protected void engineUpdate(ByteBuffer byteBuffer) {
    try {
        ensureInitialized();
        int len = byteBuffer.remaining();
        if (len <= 0) {
            return;
        }
        if (byteBuffer instanceof DirectBuffer == false) {
            super.engineUpdate(byteBuffer);
            return;
        }
        long addr = ((DirectBuffer)byteBuffer).address();
        int ofs = byteBuffer.position();
        token.p11.C_SignUpdate(session.id(), addr + ofs, null, 0, len);
        byteBuffer.position(ofs + len);
        state = S_UPDATE;
    } catch (PKCS11Exception e) {
        throw new ProviderException("update() failed", e);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:P11Mac.java

示例8: receive

import sun.nio.ch.DirectBuffer; //導入依賴的package包/類
private int receive(int fd,
                    ByteBuffer dst,
                    ResultContainer resultContainer)
        throws IOException {
    int pos = dst.position();
    int lim = dst.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);
    if (dst instanceof DirectBuffer && rem > 0)
        return receiveIntoNativeBuffer(fd, resultContainer, dst, rem, pos);

    /* Substitute a native buffer. */
    int newSize = Math.max(rem, 1);
    ByteBuffer bb = Util.getTemporaryDirectBuffer(newSize);
    try {
        int n = receiveIntoNativeBuffer(fd, resultContainer, bb, newSize, 0);
        bb.flip();
        if (n > 0 && rem > 0)
            dst.put(bb);
        return n;
    } finally {
        Util.releaseTemporaryDirectBuffer(bb);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:SctpMultiChannelImpl.java

示例9: sendFromNativeBuffer

import sun.nio.ch.DirectBuffer; //導入依賴的package包/類
private int sendFromNativeBuffer(int fd,
                                 ByteBuffer bb,
                                 SocketAddress target,
                                 int assocId,
                                 int streamNumber,
                                 boolean unordered,
                                 int ppid)
        throws IOException {
    InetAddress addr = null;     // no preferred address
    int port = 0;
    if (target != null) {
        InetSocketAddress isa = Net.checkAddress(target);
        addr = isa.getAddress();
        port = isa.getPort();
    }
    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
                        port, assocId, streamNumber, unordered, ppid);
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:27,代碼來源:SctpMultiChannelImpl.java

示例10: receive

import sun.nio.ch.DirectBuffer; //導入依賴的package包/類
private int receive(int fd,
                    ByteBuffer dst,
                    ResultContainer resultContainer,
                    boolean peek)
        throws IOException {
    int pos = dst.position();
    int lim = dst.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);
    if (dst instanceof DirectBuffer && rem > 0)
        return receiveIntoNativeBuffer(fd, resultContainer, dst, rem, pos, peek);

    /* Substitute a native buffer */
    int newSize = Math.max(rem, 1);
    ByteBuffer bb = Util.getTemporaryDirectBuffer(newSize);
    try {
        int n = receiveIntoNativeBuffer(fd, resultContainer, bb, newSize, 0, peek);
        bb.flip();
        if (n > 0 && rem > 0)
            dst.put(bb);
        return n;
    } finally {
        Util.releaseTemporaryDirectBuffer(bb);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:26,代碼來源:SctpChannelImpl.java

示例11: sendFromNativeBuffer

import sun.nio.ch.DirectBuffer; //導入依賴的package包/類
private int sendFromNativeBuffer(int fd,
                                 ByteBuffer bb,
                                 SocketAddress target,
                                 int streamNumber,
                                 boolean unordered,
                                 int ppid)
        throws IOException {
    InetAddress addr = null;     // no preferred address
    int port = 0;
    if (target != null) {
        InetSocketAddress isa = Net.checkAddress(target);
        addr = isa.getAddress();
        port = isa.getPort();
    }

    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
                        port, -1 /*121*/, streamNumber, unordered, ppid);
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:27,代碼來源:SctpChannelImpl.java

示例12: copy

import sun.nio.ch.DirectBuffer; //導入依賴的package包/類
/**
 * Copies specified number of bytes from given offset of {@code src} buffer into the {@code dest}
 * buffer.
 *
 * @param src
 * @param srcOffset
 * @param dest
 * @param destOffset
 * @param length
 */
public static void copy(ByteBuffer src, int srcOffset, ByteBuffer dest, int destOffset,
    int length) {
  long srcAddress, destAddress;
  Object srcBase = null, destBase = null;
  if (src.isDirect()) {
    srcAddress = srcOffset + ((DirectBuffer) src).address();
  } else {
    srcAddress = srcOffset + src.arrayOffset() + BYTE_ARRAY_BASE_OFFSET;
    srcBase = src.array();
  }
  if (dest.isDirect()) {
    destAddress = destOffset + ((DirectBuffer) dest).address();
  } else {
    destAddress = destOffset + BYTE_ARRAY_BASE_OFFSET + dest.arrayOffset();
    destBase = dest.array();
  }
  unsafeCopy(srcBase, srcAddress, destBase, destAddress, length);
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:29,代碼來源:UnsafeAccess.java

示例13: update

import sun.nio.ch.DirectBuffer; //導入依賴的package包/類
/**
 * Updates the checksum with the bytes from the specified buffer.
 *
 * The checksum is updated using
 * buffer.{@link java.nio.Buffer#remaining() remaining()}
 * bytes starting at
 * buffer.{@link java.nio.Buffer#position() position()}
 * Upon return, the buffer's position will
 * be updated to its limit; its limit will not have been changed.
 *
 * @param buffer the ByteBuffer to update the checksum with
 * @since 1.8
 */
public void update(ByteBuffer buffer) {
    int pos = buffer.position();
    int limit = buffer.limit();
    assert (pos <= limit);
    int rem = limit - pos;
    if (rem <= 0)
        return;
    if (buffer instanceof DirectBuffer) {
        crc = updateByteBuffer(crc, ((DirectBuffer)buffer).address(), pos, rem);
    } else if (buffer.hasArray()) {
        crc = updateBytes(crc, buffer.array(), pos + buffer.arrayOffset(), rem);
    } else {
        byte[] b = new byte[rem];
        buffer.get(b);
        crc = updateBytes(crc, b, 0, b.length);
    }
    buffer.position(limit);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:32,代碼來源:CRC32.java

示例14: engineUpdate

import sun.nio.ch.DirectBuffer; //導入依賴的package包/類
@Override
protected synchronized void engineUpdate(ByteBuffer in) {
    if (in == null || in.remaining() == 0) return;

    if (in instanceof DirectBuffer == false) {
        // cannot do better than default impl
        super.engineUpdate(in);
        return;
    }
    long inAddr = ((DirectBuffer)in).address();
    int inOfs = in.position();
    int inLen = in.remaining();

    int rv = update((inAddr + inOfs), inLen);
    if (rv < 0) {
        throw new UcryptoException(-rv);
    }
    in.position(inOfs + inLen);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:NativeRSASignature.java

示例15: update

import sun.nio.ch.DirectBuffer; //導入依賴的package包/類
/**
 * Updates the checksum with the bytes from the specified buffer.
 *
 * The checksum is updated with the remaining bytes in the buffer, starting
 * at the buffer's position. Upon return, the buffer's position will be
 * updated to its limit; its limit will not have been changed.
 *
 * @since 1.8
 */
@Override
public void update(ByteBuffer buffer) {
    int pos = buffer.position();
    int limit = buffer.limit();
    assert (pos <= limit);
    int rem = limit - pos;
    if (rem <= 0)
        return;
    if (buffer instanceof DirectBuffer) {
        adler = updateByteBuffer(adler, ((DirectBuffer)buffer).address(), pos, rem);
    } else if (buffer.hasArray()) {
        adler = updateBytes(adler, buffer.array(), pos + buffer.arrayOffset(), rem);
    } else {
        byte[] b = new byte[Math.min(buffer.remaining(), 4096)];
        while (buffer.hasRemaining()) {
            int length = Math.min(buffer.remaining(), b.length);
            buffer.get(b, 0, length);
            update(b, 0, length);
        }
    }
    buffer.position(limit);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:32,代碼來源:Adler32.java


注:本文中的sun.nio.ch.DirectBuffer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。