当前位置: 首页>>代码示例>>Java>>正文


Java ByteBuffer.hasArray方法代码示例

本文整理汇总了Java中java.nio.ByteBuffer.hasArray方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.hasArray方法的具体用法?Java ByteBuffer.hasArray怎么用?Java ByteBuffer.hasArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.ByteBuffer的用法示例。


在下文中一共展示了ByteBuffer.hasArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createPreviewBuffer

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Creates one buffer for the camera preview callback.  The size of the buffer is based off of
 * the camera preview size and the format of the camera image.
 *
 * @return a new preview buffer of the appropriate size for the current camera settings
 */
private byte[] createPreviewBuffer(Size previewSize) {
    int bitsPerPixel = ImageFormat.getBitsPerPixel(ImageFormat.NV21);
    long sizeInBits = previewSize.getHeight() * previewSize.getWidth() * bitsPerPixel;
    int bufferSize = (int) Math.ceil(sizeInBits / 8.0d) + 1;

    //
    // NOTICE: This code only works when using play services v. 8.1 or higher.
    //

    // Creating the byte array this way and wrapping it, as opposed to using .allocate(),
    // should guarantee that there will be an array to work with.
    byte[] byteArray = new byte[bufferSize];
    ByteBuffer buffer = ByteBuffer.wrap(byteArray);
    if (!buffer.hasArray() || (buffer.array() != byteArray)) {
        // I don't think that this will ever happen.  But if it does, then we wouldn't be
        // passing the preview content to the underlying detector later.
        throw new IllegalStateException("Failed to create valid buffer for camera source.");
    }

    mBytesToByteBuffer.put(byteArray, buffer);
    return byteArray;
}
 
开发者ID:dvdciri,项目名称:DeepImagePreview-Project,代码行数:29,代码来源:CameraSource.java

示例2: create

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Creates a WaveData container from the specified ByetBuffer. If the buffer
 * is backed by an array, it will be used directly, else the contents of the
 * buffer will be copied using get(byte[]).
 * 
 * @param buffer
 *            ByteBuffer containing sound file
 * @return WaveData containing data, or null if a failure occured
 */
public static WaveData create(ByteBuffer buffer)
{
	try
	{
		byte[] bytes = null;

		if (buffer.hasArray())
		{
			bytes = buffer.array();
		}
		else
		{
			bytes = new byte[buffer.capacity()];
			buffer.get(bytes);
		}
		return create(bytes);
	}
	catch (Exception e)
	{
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:TheRemote,项目名称:Spark,代码行数:33,代码来源:WaveData.java

示例3: copy

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public void copy(ByteBuffer srcBuf, int srcPosition, ByteBuffer trgBuf, int trgPosition, int length)
{
    Object src;
    long srcOffset;
    if (srcBuf.hasArray())
    {
        src = srcBuf.array();
        srcOffset = BYTE_ARRAY_BASE_OFFSET + srcBuf.arrayOffset();
    }
    else
    {
        src = null;
        srcOffset = theUnsafe.getLong(srcBuf, DIRECT_BUFFER_ADDRESS_OFFSET);
    }
    copy(src, srcOffset + srcPosition, trgBuf, trgPosition, length);
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:17,代码来源:FastByteOperations.java

示例4: decode

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Decodes all bytes from the input byte buffer using the {@link Base64}
 * encoding scheme, writing the results into a newly-allocated ByteBuffer.
 *
 * <p> Upon return, the source buffer's position will be updated to
 * its limit; its limit will not have been changed. The returned
 * output buffer's position will be zero and its limit will be the
 * number of resulting decoded bytes
 *
 * <p> {@code IllegalArgumentException} is thrown if the input buffer
 * is not in valid Base64 encoding scheme. The position of the input
 * buffer will not be advanced in this case.
 *
 * @param   buffer
 *          the ByteBuffer to decode
 *
 * @return  A newly-allocated byte buffer containing the decoded bytes
 *
 * @throws  IllegalArgumentException
 *          if {@code src} is not in valid Base64 scheme.
 */
public ByteBuffer decode(ByteBuffer buffer) {
    int pos0 = buffer.position();
    try {
        byte[] src;
        int sp, sl;
        if (buffer.hasArray()) {
            src = buffer.array();
            sp = buffer.arrayOffset() + buffer.position();
            sl = buffer.arrayOffset() + buffer.limit();
            buffer.position(buffer.limit());
        } else {
            src = new byte[buffer.remaining()];
            buffer.get(src);
            sp = 0;
            sl = src.length;
        }
        byte[] dst = new byte[outLength(src, sp, sl)];
        return ByteBuffer.wrap(dst, 0, decode0(src, sp, sl, dst));
    } catch (IllegalArgumentException iae) {
        buffer.position(pos0);
        throw iae;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:45,代码来源:Base64.java

示例5: decodeLoop

import java.nio.ByteBuffer; //导入方法依赖的package包/类
protected CoderResult decodeLoop(ByteBuffer src,
                                 CharBuffer dst)
{
    if (src.hasArray() && dst.hasArray())
        return decodeArrayLoop(src, dst);
    else
        return decodeBufferLoop(src, dst);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:UTF_8.java

示例6: copy

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static void copy(Object src, long srcOffset, ByteBuffer trgBuf, int trgPosition, int length)
{
    if (trgBuf.hasArray())
        copy(src, srcOffset, trgBuf.array(), trgBuf.arrayOffset() + trgPosition, length);
    else
        copy(src, srcOffset, null, trgPosition + theUnsafe.getLong(trgBuf, DIRECT_BUFFER_ADDRESS_OFFSET), length);
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:8,代码来源:FastByteOperations.java

示例7: toByteArray

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * gets the contents of this stream as a byte[]. The stream should not be written to past this
 * point until it has been reset.
 */
public final byte[] toByteArray() {
  ByteBuffer bb = toByteBuffer();
  if (bb.hasArray() && bb.arrayOffset() == 0 && bb.limit() == bb.capacity()) {
    return bb.array();
  } else {
    // create a new buffer of just the right size and copy the old buffer into it
    ByteBuffer tmp = ByteBuffer.allocate(bb.remaining());
    tmp.put(bb);
    tmp.flip();
    this.buffer = tmp;
    return this.buffer.array();
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:18,代码来源:HeapDataOutputStream.java

示例8: supplyInput

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static boolean supplyInput(Inflater inflater, ByteBuffer buf)
{
    if (buf.remaining() <= 0)
    {
        if (LOG.isDebugEnabled())
        {
            LOG.debug("No data left left to supply to Inflater");
        }
        return false;
    }

    byte input[];
    int inputOffset;
    int len;

    if (buf.hasArray())
    {
        // no need to create a new byte buffer, just return this one.
        len = buf.remaining();
        input = buf.array();
        inputOffset = buf.position() + buf.arrayOffset();
        buf.position(buf.position() + len);
    }
    else
    {
        // Only create an return byte buffer that is reasonable in size
        len = Math.min(INPUT_MAX_BUFFER_SIZE,buf.remaining());
        input = new byte[len];
        inputOffset = 0;
        buf.get(input,0,len);
    }

    inflater.setInput(input,inputOffset,len);
    if (LOG.isDebugEnabled())
    {
        LOG.debug("Supplied {} input bytes: {}",input.length,toDetail(inflater));
    }
    return true;
}
 
开发者ID:AnywhereSoftware,项目名称:B4J_Server,代码行数:40,代码来源:CompressExtension.java

示例9: encodeLoop

import java.nio.ByteBuffer; //导入方法依赖的package包/类
protected CoderResult encodeLoop(CharBuffer src,
                                 ByteBuffer dst)
{
    if (src.hasArray() && dst.hasArray())
        return encodeArrayLoop(src, dst);
    else
        return encodeBufferLoop(src, dst);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:ISO2022.java

示例10: copyFromBufferToBuffer

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Copy from one buffer to another from given offset. This will be absolute positional copying and
 * won't affect the position of any of the buffers.
 * @param out
 * @param in
 * @param sourceOffset
 * @param destinationOffset
 * @param length
 */
public static void copyFromBufferToBuffer(ByteBuffer out, ByteBuffer in, int sourceOffset,
    int destinationOffset, int length) {
  if (in.hasArray() && out.hasArray()) {
    System.arraycopy(in.array(), sourceOffset + in.arrayOffset(), out.array(), out.arrayOffset()
        + destinationOffset, length);
  } else {
    for (int i = 0; i < length; ++i) {
      out.put((destinationOffset + i), in.get(sourceOffset + i));
    }
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:21,代码来源:ByteBufferUtils.java

示例11: deserialize

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
@SneakyThrows
public T deserialize(ByteBuffer buffer) {
    byte[] array;
    if (buffer.hasArray() && buffer.arrayOffset() == 0 && buffer.position() == 0 && buffer.limit() == buffer.capacity()) {
        array = buffer.array();
    } else {
        array = new byte[buffer.remaining()];
        buffer.get(array);
    }

    return deserializationSchema.deserialize(array);
}
 
开发者ID:pravega,项目名称:flink-connectors,代码行数:14,代码来源:FlinkPravegaUtils.java

示例12: encodeLoop

import java.nio.ByteBuffer; //导入方法依赖的package包/类
protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) {
    if (true && src.hasArray() && dst.hasArray())
        return encodeArrayLoop(src, dst);
    else
        return encodeBufferLoop(src, dst);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:DBCS_IBM_EBCDIC_Encoder.java

示例13: b

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static boolean b(ByteBuffer byteBuffer) {
    return byteBuffer.hasArray() && byteBuffer.position() == 0 && byteBuffer.arrayOffset() == 0 && byteBuffer.remaining() == byteBuffer.capacity();
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:4,代码来源:ca.java

示例14: decodeLoop

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public CoderResult decodeLoop(ByteBuffer src, CharBuffer dst) {
    if (src.hasArray() && dst.hasArray())
        return decodeArrayLoop(src, dst);
    else
        return decodeBufferLoop(src, dst);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:7,代码来源:EUC_JP.java

示例15: newDefaultChannel

import java.nio.ByteBuffer; //导入方法依赖的package包/类
protected WritableByteChannel newDefaultChannel()
{
    return new WritableByteChannel()
    {

        @Override
        public boolean isOpen()
        {
            return true;
        }

        @Override
        public void close()
        {
        }

        @Override
        public int write(ByteBuffer src) throws IOException
        {
            int toWrite = src.remaining();

            if (src.hasArray())
            {
                DataOutputStreamPlus.this.write(src.array(), src.arrayOffset() + src.position(), src.remaining());
                src.position(src.limit());
                return toWrite;
            }

            if (toWrite < 16)
            {
                int offset = src.position();
                for (int i = 0 ; i < toWrite ; i++)
                    DataOutputStreamPlus.this.write(src.get(i + offset));
                src.position(src.limit());
                return toWrite;
            }

            byte[] buf = retrieveTemporaryBuffer(toWrite);

            int totalWritten = 0;
            while (totalWritten < toWrite)
            {
                int toWriteThisTime = Math.min(buf.length, toWrite - totalWritten);

                ByteBufferUtil.arrayCopy(src, src.position() + totalWritten, buf, 0, toWriteThisTime);

                DataOutputStreamPlus.this.write(buf, 0, toWriteThisTime);

                totalWritten += toWriteThisTime;
            }

            src.position(src.limit());
            return totalWritten;
        }

    };
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:58,代码来源:DataOutputStreamPlus.java


注:本文中的java.nio.ByteBuffer.hasArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。