当前位置: 首页>>代码示例>>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;未经允许,请勿转载。