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


Java ByteBuffer.slice方法代码示例

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


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

示例1: demuxAnnexb

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public SrsFlvFrameBytes demuxAnnexb(ByteBuffer bb, int size, boolean isOnlyChkHeader) {
  SrsFlvFrameBytes tbb = new SrsFlvFrameBytes();
  if (bb.position() < size - 4) {
    // each frame must prefixed by annexb format.
    // about annexb, @see H.264-AVC-ISO_IEC_14496-10.pdf, page 211.
    SrsAnnexbSearch tbbsc =
        isOnlyChkHeader ? searchStartcode(bb, size) : searchAnnexb(bb, size);
    // tbbsc.nb_start_code always 4 , after 00 00 00 01
    if (!tbbsc.match || tbbsc.nb_start_code < 3) {
      Log.e(TAG, "annexb not match.");
    } else {
      // the start codes.
      for (int i = 0; i < tbbsc.nb_start_code; i++) {
        bb.get();
      }

      // find out the frame size.
      tbb.data = bb.slice();
      tbb.size = size - bb.position();
    }
  }
  return tbb;
}
 
开发者ID:pedroSG94,项目名称:rtmp-rtsp-stream-client-java,代码行数:24,代码来源:SrsFlvMuxer.java

示例2: allocate

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/** Allocates an empty I420Buffer suitable for an image of the given dimensions. */
public static JavaI420Buffer allocate(int width, int height) {
  int chromaHeight = (height + 1) / 2;
  int strideUV = (width + 1) / 2;
  int yPos = 0;
  int uPos = yPos + width * height;
  int vPos = uPos + strideUV * chromaHeight;

  ByteBuffer buffer = ByteBuffer.allocateDirect(width * height + 2 * strideUV * chromaHeight);

  buffer.position(yPos);
  buffer.limit(uPos);
  ByteBuffer dataY = buffer.slice();

  buffer.position(uPos);
  buffer.limit(vPos);
  ByteBuffer dataU = buffer.slice();

  buffer.position(vPos);
  buffer.limit(vPos + strideUV * chromaHeight);
  ByteBuffer dataV = buffer.slice();

  return new JavaI420Buffer(
      width, height, dataY, width, dataU, strideUV, dataV, strideUV, null /* releaseCallback */);
}
 
开发者ID:Piasy,项目名称:AppRTC-Android,代码行数:26,代码来源:JavaI420Buffer.java

示例3: create

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Creates a new dex from the contents of {@code bytes}. This API supports
 * both {@code .dex} and {@code .odex} input. Calling this constructor
 * transfers ownership of {@code bytes} to the returned Dex: it is an error
 * to access the buffer after calling this method.
 */
public static Dex create(ByteBuffer data) throws IOException {
    data.order(ByteOrder.LITTLE_ENDIAN);

    // if it's an .odex file, set position and limit to the .dex section
    if (data.get(0) == 'd' && data.get(1) == 'e' && data.get(2) == 'y' && data.get(3) == '\n') {
        data.position(8);
        int offset = data.getInt();
        int length = data.getInt();
        data.position(offset);
        data.limit(offset + length);
        data = data.slice();
    }

    return new Dex(data);
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:22,代码来源:Dex.java

示例4: Mp4MeanBox

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * @param header     parentHeader info
 * @param dataBuffer data of box (doesnt include parentHeader data)
 */
public Mp4MeanBox(Mp4BoxHeader header, ByteBuffer dataBuffer) {
    this.header = header;

    //Double check
    if (!header.getId().equals(IDENTIFIER)) {
        throw new RuntimeException("Unable to process data box because identifier is:" + header.getId());
    }

    //Make slice so operations here don't effect position of main buffer
    this.dataBuffer = dataBuffer.slice();

    //issuer
    this.issuer = Utils.getString(this.dataBuffer, PRE_DATA_LENGTH, header.getDataLength() - PRE_DATA_LENGTH, header.getEncoding());

}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:20,代码来源:Mp4MeanBox.java

示例5: Mp4MeanBox

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * @param header     parentHeader info
 * @param dataBuffer data of box (doesnt include parentHeader data)
 */
public Mp4MeanBox(Mp4BoxHeader header, ByteBuffer dataBuffer)
{
    this.header = header;

    //Double check
    if (!header.getId().equals(IDENTIFIER))
    {
        throw new RuntimeException("Unable to process data box because identifier is:" + header.getId());
    }

    //Make slice so operations here don't effect position of main buffer
    this.dataBuffer = dataBuffer.slice();

    //issuer
    this.issuer = Utils.getString(this.dataBuffer, PRE_DATA_LENGTH, header.getDataLength() - PRE_DATA_LENGTH, header.getEncoding());

}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:22,代码来源:Mp4MeanBox.java

示例6: getFirstKeyInBlock

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public ByteBuffer getFirstKeyInBlock(ByteBuffer block) {
  int keyLength = block.getInt(Bytes.SIZEOF_INT);
  ByteBuffer dup = block.duplicate();
  int pos = 3 * Bytes.SIZEOF_INT;
  dup.position(pos);
  dup.limit(pos + keyLength);
  return dup.slice();
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:10,代码来源:CopyKeyDataBlockEncoder.java

示例7: moveBufferToChunks

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void moveBufferToChunks() {
  final ByteBuffer oldBuffer = this.buffer;
  if (this.chunks == null) {
    this.chunks = new LinkedList<ByteBuffer>();
  }
  if (oldBuffer.position() == 0) {
    // if position is zero then nothing has been written (yet) to buffer so no need to move it to
    // chunks
    return;
  }
  oldBuffer.flip();
  this.size += oldBuffer.remaining();
  ByteBuffer bufToAdd = oldBuffer.slice();
  this.chunks.add(bufToAdd);
  int newPos = oldBuffer.limit();
  if ((oldBuffer.capacity() - newPos) <= 0) {
    this.buffer = ByteBuffer.allocate(MIN_CHUNK_SIZE);
  } else {
    oldBuffer.limit(oldBuffer.capacity());
    oldBuffer.position(newPos);
    this.buffer = oldBuffer.slice();
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:24,代码来源:HeapDataOutputStream.java

示例8: read

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void read(ByteBuffer byteBuffer) throws TagException {
    int size;
    if (!seek(byteBuffer)) {
        throw new TagNotFoundException("ID3v2.20 tag not found");
    }
    logger.config(getLoggingFilename() + ":" + "Reading tag from file");

    //Read the flags
    readHeaderFlags(byteBuffer);

    // Read the size
    size = ID3SyncSafeInteger.bufferToValue(byteBuffer);

    //Slice Buffer, so position markers tally with size (i.e do not include tagheader)
    ByteBuffer bufferWithoutHeader = byteBuffer.slice();

    //We need to synchronize the buffer
    if (unsynchronization) {
        bufferWithoutHeader = ID3Unsynchronization.synchronize(bufferWithoutHeader);
    }
    readFrames(bufferWithoutHeader, size);
    logger.config(getLoggingFilename() + ":" + "Loaded Frames,there are:" + frameMap.keySet().size());
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:28,代码来源:ID3v22Tag.java

示例9: selectMappedBuffer

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public SelectMappedBufferResult selectMappedBuffer(int pos, int size) {
    int readPosition = getReadPosition();
    if ((pos + size) <= readPosition) {

        if (this.hold()) {
            ByteBuffer byteBuffer = this.mappedByteBuffer.slice();
            byteBuffer.position(pos);
            ByteBuffer byteBufferNew = byteBuffer.slice();
            byteBufferNew.limit(size);
            return new SelectMappedBufferResult(this.fileFromOffset + pos, byteBufferNew, size, this);
        } else {
            log.warn("matched, but hold failed, request pos: " + pos + ", fileFromOffset: "
                + this.fileFromOffset);
        }
    } else {
        log.warn("selectMappedBuffer request pos invalid, request pos: " + pos + ", size: " + size
            + ", fileFromOffset: " + this.fileFromOffset);
    }

    return null;
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:22,代码来源:MappedFile.java

示例10: isVbriFrame

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * IS this a VBRI frame
 *
 * @param bb
 * @param mpegFrameHeader
 * @return raw header if this is a VBRI frame
 */
public static ByteBuffer isVbriFrame(ByteBuffer bb, MPEGFrameHeader mpegFrameHeader) {

    //We store this so can return here after scanning through buffer
    int startPosition = bb.position();
    MP3File.logger.finest("Checking VBRI Frame at" + startPosition);

    bb.position(startPosition + VBRI_OFFSET);

    //Create header from here
    ByteBuffer header = bb.slice();

    // Return Buffer to start Point
    bb.position(startPosition);

    //Check Identifier
    byte[] identifier = new byte[VBRI_IDENTIFIER_BUFFER_SIZE];
    header.get(identifier);
    if ((!Arrays.equals(identifier, VBRI_VBR_ID))) {
        return null;
    }
    MP3File.logger.finest("Found VBRI Frame");
    return header;
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:31,代码来源:VbriFrame.java

示例11: nextByteBuffer

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static ByteBuffer nextByteBuffer(int size)
{
    ByteBuffer bytebuffer = bigBuffer;
    int i = bytebuffer.limit();
    bytebuffer.position(i).limit(i + size);
    return bytebuffer.slice();
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:8,代码来源:Shaders.java

示例12: read

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void read(ByteBuffer buffer) throws TagException
{
    int size;
    if (!seek(buffer))
    {
        throw new TagNotFoundException(getIdentifier() + " tag not found");
    }
    logger.config(getLoggingFilename() + ":" + "Reading ID3v23 tag");

    readHeaderFlags(buffer);

    // Read the size, this is size of tag not including the tag header
    size = ID3SyncSafeInteger.bufferToValue(buffer);
    logger.config(ErrorMessage.ID_TAG_SIZE.getMsg(getLoggingFilename(),size));

    //Extended Header
    if (extended)
    {
        readExtendedHeader(buffer, size);
    }

    //Slice Buffer, so position markers tally with size (i.e do not include tagHeader)
    ByteBuffer bufferWithoutHeader = buffer.slice();
    //We need to synchronize the buffer
    if (isUnsynchronization())
    {
        bufferWithoutHeader = ID3Unsynchronization.synchronize(bufferWithoutHeader);
    }

    readFrames(bufferWithoutHeader, size);
    logger.config(getLoggingFilename() + ":Loaded Frames,there are:" + frameMap.keySet().size());

}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:38,代码来源:ID3v23Tag.java

示例13: sliceFromTo

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Returns new byte buffer whose content is a shared subsequence of this buffer's content
 * between the specified start (inclusive) and end (exclusive) positions. As opposed to
 * {@link ByteBuffer#slice()}, the returned buffer's byte order is the same as the source
 * buffer's byte order.
 */
private static ByteBuffer sliceFromTo(final ByteBuffer source, final int start, final int end) {
    if (start < 0) {
        throw new IllegalArgumentException("start: " + start);
    }
    if (end < start) {
        throw new IllegalArgumentException("end < start: " + end + " < " + start);
    }
    final int capacity = source.capacity();
    if (end > source.capacity()) {
        throw new IllegalArgumentException("end > capacity: " + end + " > " + capacity);
    }
    final int originalLimit = source.limit();
    final int originalPosition = source.position();
    try {
        source.position(0);
        source.limit(end);
        source.position(start);
        final ByteBuffer result = source.slice();
        result.order(source.order());
        return result;
    } finally {
        source.position(0);
        source.limit(originalLimit);
        source.position(originalPosition);
    }
}
 
开发者ID:Meituan-Dianping,项目名称:walle,代码行数:33,代码来源:ApkUtil.java

示例14: _parseDetails

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
protected void _parseDetails(ByteBuffer content) {
    parseVersionAndFlags(content);
    if (this.getVersion() != 1) {
        throw new RuntimeException("SampleGroupDescriptionBox are only supported in version 1");
    }
    groupingType = IsoTypeReader.read4cc(content);
    if (this.getVersion() == 1) {
        defaultLength = l2i(IsoTypeReader.readUInt32(content));
    }
    long entryCount = IsoTypeReader.readUInt32(content);
    while (entryCount-- > 0) {
        int length = defaultLength;
        if (this.getVersion() == 1) {
            if (defaultLength == 0) {
                descriptionLength = l2i(IsoTypeReader.readUInt32(content));
                length = descriptionLength;
            }
        } else {
            throw new RuntimeException("This should be implemented");
        }
        int finalPos = content.position() + length;
        ByteBuffer parseMe = content.slice();
        parseMe.limit(length);
        groupEntries.add(parseGroupEntry(parseMe, groupingType));
        content.position(finalPos);
    }

}
 
开发者ID:lisnstatic,项目名称:live_master,代码行数:30,代码来源:SampleGroupDescriptionBox.java

示例15: cloneBuffer

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static ByteBuffer cloneBuffer(final ByteBuffer original, final int begin, final int end) {
    final ByteBuffer clone = ByteBuffer.allocateDirect(original.capacity());
    original.rewind();//copy from the beginning
    clone.put(original);
    original.rewind();
    clone.flip();
    clone.position(begin);
    clone.limit(end);
    return clone.slice();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:NativeArrayBuffer.java


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