本文整理汇总了Java中java.nio.ByteBuffer.array方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.array方法的具体用法?Java ByteBuffer.array怎么用?Java ByteBuffer.array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.array方法的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;
}
示例2: decodeArrayLoop
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private CoderResult decodeArrayLoop(ByteBuffer src, CharBuffer dst) {
byte[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
char[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
CoderResult cr = CoderResult.UNDERFLOW;
if ((dl - dp) < (sl - sp)) {
sl = sp + (dl - dp);
cr = CoderResult.OVERFLOW;
}
while (sp < sl) {
char c = decode(sa[sp]);
if (c == UNMAPPABLE_DECODING) {
return withResult(CoderResult.unmappableForLength(1),
src, sp, dst, dp);
}
da[dp++] = c;
sp++;
}
return withResult(cr, src, sp, dst, dp);
}
示例3: buildRowKeyArray
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private byte[] buildRowKeyArray() {
final byte[] rowKey = new byte[RowKey.calculateRowKeyLength(3)];
final ByteBuffer buffer = ByteBuffer.wrap(rowKey);
buffer.put(STAT_TYPE_ID.getUidBytes());
buffer.put(ROLL_UP_BIT_MASK);
buffer.put(PARTIAL_TIMESTAMP);
buffer.put(TAG_2.getUidBytes());
buffer.put(VALUE_2.getUidBytes());
buffer.put(TAG_1.getUidBytes());
buffer.put(VALUE_1.getUidBytes());
buffer.put(TAG_3.getUidBytes());
buffer.put(VALUE_3.getUidBytes());
return buffer.array();
}
示例4: serialize
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public byte[] serialize(String topic, ByteBuffer data) {
if (data == null)
return null;
data.rewind();
if (data.hasArray()) {
byte[] arr = data.array();
if (data.arrayOffset() == 0 && arr.length == data.remaining()) {
return arr;
}
}
byte[] ret = new byte[data.remaining()];
data.get(ret, 0, ret.length);
data.rewind();
return ret;
}
示例5: cryptoticket
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@GET
@Path("/cryptoticket")
@Produces(MediaType.APPLICATION_XML)
public String cryptoticket() {
byte[] helloPacket = { 10, 11, 12, 13 };
ByteBuffer byteBuffer = ByteBuffer.allocate(32);
byteBuffer.put(helloPacket);
byte[] cryptoTicketBytes = byteBuffer.array();
String cryptoTicketBase64 = Base64.getEncoder().encodeToString(cryptoTicketBytes);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("<ClientServerCryptoTicket>\n");
stringBuilder.append("<CryptoTicket>");
stringBuilder.append(cryptoTicketBase64);
stringBuilder.append("</CryptoTicket>\n");
stringBuilder.append("<SessionKey>AAAAAAAAAAAAAAAAAAAAAA==</SessionKey>\n");
stringBuilder.append("<TicketIv>AAAAAAAAAAAAAAAAAAAAAA==</TicketIv>\n");
stringBuilder.append("</ClientServerCryptoTicket>");
return stringBuilder.toString();
}
示例6: 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);
}
示例7: readGetMessageResult
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private byte[] readGetMessageResult(final GetMessageResult getMessageResult, final String group, final String topic, final int queueId) {
final ByteBuffer byteBuffer = ByteBuffer.allocate(getMessageResult.getBufferTotalSize());
long storeTimestamp = 0;
try {
List<ByteBuffer> messageBufferList = getMessageResult.getMessageBufferList();
for (ByteBuffer bb : messageBufferList) {
byteBuffer.put(bb);
storeTimestamp = bb.getLong(MessageDecoder.MESSAGE_STORE_TIMESTAMP_POSTION);
}
} finally {
getMessageResult.release();
}
this.brokerController.getBrokerStatsManager().recordDiskFallBehindTime(group, topic, queueId, this.brokerController.getMessageStore().now() - storeTimestamp);
return byteBuffer.array();
}
示例8: getBlockLightArray
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public byte[] getBlockLightArray() {
ByteBuffer buffer = ByteBuffer.allocate(2048 * SECTION_COUNT);
for (int y = 0; y < SECTION_COUNT; y++) {
buffer.put(this.sections[y].getLightArray());
}
return buffer.array();
}
示例9: buildPsshAtom
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Builds a PSSH atom for a given {@link UUID} containing the given scheme specific data.
*
* @param uuid The UUID of the scheme.
* @param data The scheme specific data.
* @return The PSSH atom.
*/
public static byte[] buildPsshAtom(UUID uuid, byte[] data) {
int psshBoxLength = Atom.FULL_HEADER_SIZE + 16 /* UUID */ + 4 /* DataSize */ + data.length;
ByteBuffer psshBox = ByteBuffer.allocate(psshBoxLength);
psshBox.putInt(psshBoxLength);
psshBox.putInt(Atom.TYPE_pssh);
psshBox.putInt(0 /* version=0, flags=0 */);
psshBox.putLong(uuid.getMostSignificantBits());
psshBox.putLong(uuid.getLeastSignificantBits());
psshBox.putInt(data.length);
psshBox.put(data);
return psshBox.array();
}
示例10: decodeArrayLoop
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private CoderResult decodeArrayLoop(ByteBuffer src,
CharBuffer dst)
{
byte[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
assert (sp <= sl);
sp = (sp <= sl ? sp : sl);
char[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
assert (dp <= dl);
dp = (dp <= dl ? dp : dl);
try {
while (sp < sl) {
byte b = sa[sp];
if (dp >= dl)
return CoderResult.OVERFLOW;
da[dp++] = (char)(b & 0xff);
sp++;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}
示例11: getBlockIdColumn
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public byte[] getBlockIdColumn(int x, int z) {
ByteBuffer buffer = ByteBuffer.allocate(256);
for (int y = 0; y < SECTION_COUNT; y++) {
buffer.put(this.sections[y].getBlockIdColumn(x, z));
}
return buffer.array();
}
示例12: wrapExtData
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static byte[] wrapExtData(byte[] extData) {
int bufferLen = (extData != null ? extData.length : 0) + 4;
ByteBuffer bb = ByteBuffer.allocate(bufferLen);
bb.putShort((short)ExtensionType.EXT_STATUS_REQUEST.id);
bb.putShort((short)(extData != null ? extData.length: 0));
if (extData != null) {
bb.put(extData);
}
return bb.array();
}
示例13: readBytes
import java.nio.ByteBuffer; //导入方法依赖的package包/类
byte[] readBytes(int offset, int length) {
ByteBuffer buffer = readBlock(offset, length);
if (buffer.hasArray()) {
return buffer.array();
} else {
byte[] bufferBytes = new byte[buffer.limit()];
buffer.get(bufferBytes);
return bufferBytes;
}
}
示例14: encodeArrayLoop
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private CoderResult encodeArrayLoop(CharBuffer src,
ByteBuffer dst)
{
char[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
assert (sp <= sl);
sp = (sp <= sl ? sp : sl);
byte[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
assert (dp <= dl);
dp = (dp <= dl ? dp : dl);
int outputSize = 0;
byte[] outputByte;
int inputSize = 0; // Size of input
byte[] tmpBuf = new byte[3];
try {
while (sp < sl) {
outputByte = tmpBuf;
char c = sa[sp];
if (Character.isSurrogate(c)) {
if (sgp.parse(c, sa, sp, sl) < 0)
return sgp.error();
return sgp.unmappableResult();
}
outputSize = encodeSingle(c, outputByte);
if (outputSize == 0) { // DoubleByte
int ncode = encodeDouble(c);
if (ncode != 0 ) {
if ((ncode & 0xFF0000) == 0) {
outputByte[0] = (byte) ((ncode & 0xff00) >> 8);
outputByte[1] = (byte) (ncode & 0xff);
outputSize = 2;
} else {
outputByte[0] = (byte) 0x8f;
outputByte[1] = (byte) ((ncode & 0xff00) >> 8);
outputByte[2] = (byte) (ncode & 0xff);
outputSize = 3;
}
} else {
return CoderResult.unmappableForLength(1);
}
}
if (dl - dp < outputSize)
return CoderResult.OVERFLOW;
// Put the byte in the output buffer
for (int i = 0; i < outputSize; i++) {
da[dp++] = outputByte[i];
}
sp++;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}
示例15: encodeGetRequest
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public byte[] encodeGetRequest(URI requestURI, String[] names, String[] values) {
// Any changes to this method should result in the getEncodeRequestSize method below
// to get accurate length of the buffer that needs to be allocated.
LOG.entering(CLASS_NAME, "encodeGetRequest", new Object[] {requestURI, names, values});
int requestSize = getEncodeRequestSize(requestURI, names, values);
ByteBuffer buf = ByteBuffer.allocate(requestSize);
// Encode Request line
buf.put(GET_BYTES);
buf.put(SPACE_BYTES);
String path = requestURI.getPath();
if (requestURI.getQuery() != null) {
path += "?" + requestURI.getQuery();
}
buf.put(path.getBytes());
buf.put(SPACE_BYTES);
buf.put(HTTP_1_1_BYTES);
buf.put(CRLF_BYTES);
// Encode headers
for (int i = 0; i < names.length; i++) {
String headerName = names[i];
String headerValue = values[i];
if (headerName != null && headerValue != null) {
buf.put(headerName.getBytes());
buf.put(COLON_BYTES);
buf.put(SPACE_BYTES);
buf.put(headerValue.getBytes());
buf.put(CRLF_BYTES);
}
}
// Encoding cookies, content length and content not done here as we
// don't have it in the initial GET request.
buf.put(CRLF_BYTES);
buf.flip();
return buf.array();
}