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


C# ByteBuffer.position方法代码示例

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


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

示例1: Blob

        /// <summary>
        /// Create a new Blob from an existing ByteBuffer.  IMPORTANT: If copy is
        /// false, after calling this constructor, if you keep a pointer to the buffer
        /// then you must treat it as immutable and promise not to change it.
        /// </summary>
        ///
        /// <param name="buffer"></param>
        /// <param name="copy"></param>
        public Blob(ByteBuffer buffer, bool copy)
        {
            this.haveHashCode_ = false;
            if (buffer != null) {
                if (copy) {
                    buffer_ = ILOG.J2CsMapping.NIO.ByteBuffer.allocate(buffer.remaining());

                    // Put updates buffer.position(), so save and restore it.
                    int savePosition = buffer.position();
                    buffer_.put(buffer);
                    buffer.position(savePosition);

                    buffer_.flip();
                } else
                    buffer_ = buffer.slice();
            } else
                buffer_ = null;
        }
开发者ID:named-data,项目名称:ndn-dot-net,代码行数:26,代码来源:Blob.cs

示例2: Write

	private void Write(ByteBuffer buffer, int size)
	{
		buffer.position(0);
		buffer.limit(size);

		if (Channel != null)
		{
			Channel.write(buffer);
		}
		else if (ResultBuffer != null)
		{
			ResultBuffer.put(buffer);
		}

		TotalSize += size;
	}
开发者ID:Kelindar,项目名称:misakai-storage-sbe,代码行数:16,代码来源:IrEncoder.cs

示例3: slice

            /* slices a read only contiguous buffer of chunkLength */
            private ByteBuffer slice(int chunkLength)
            {
                int len = chunkLength;
                long oldOffset = currentOffset;
                ByteBuffer slice;
                if (compressed.remaining() >= len)
                {
                    slice = compressed.slice();
                    // simple case
                    slice.limit(len);
                    currentOffset += len;
                    compressed.position(compressed.position() + len);
                    return slice;
                }
                else if (currentRange >= (bytes.Count - 1))
                {
                    // nothing has been modified yet
                    throw new IOException("EOF in " + this + " while trying to read " +
                        chunkLength + " bytes");
                }

                if (LOG.isDebugEnabled())
                {
                    LOG.debug(String.Format(
                        "Crossing into next BufferChunk because compressed only has %d bytes (needs %d)",
                        compressed.remaining(), len));
                }

                // we need to consolidate 2 or more buffers into 1
                // first copy out compressed buffers
                ByteBuffer copy = allocateBuffer(chunkLength, compressed.isDirect());
                currentOffset += compressed.remaining();
                len -= compressed.remaining();
                copy.put(compressed);

                for (int i = currentRange; i < bytes.Count && len > 0; i++)
                {
                    ++currentRange;
                    if (LOG.isDebugEnabled())
                    {
                        LOG.debug(String.Format("Read slow-path, >1 cross block reads with {0}", this.ToString()));
                    }
                    DiskRange range = bytes[i];
                    compressed = range.getData().duplicate();
                    if (compressed.remaining() >= len)
                    {
                        slice = compressed.slice();
                        slice.limit(len);
                        copy.put(slice);
                        currentOffset += len;
                        compressed.position(compressed.position() + len);
                        return copy;
                    }
                    currentOffset += compressed.remaining();
                    len -= compressed.remaining();
                    copy.put(compressed);
                }

                // restore offsets for exception clarity
                seek(oldOffset);
                throw new IOException("EOF in " + this + " while trying to read " +
                    chunkLength + " bytes");
            }
开发者ID:CurtHagenlocher,项目名称:OrcSharp,代码行数:64,代码来源:InStream.cs

示例4: onReceivedData

        /// <summary>
        /// Continue to read data until the end of an element, then call
        /// elementListener.onReceivedElement(element ). The buffer passed to
        /// onReceivedElement is only valid during this call.  If you need the data
        /// later, you must copy.
        /// </summary>
        ///
        /// <param name="data"></param>
        /// <exception cref="EncodingException">For invalid encoding.</exception>
        public void onReceivedData(ByteBuffer data)
        {
            // We may repeatedly set data to a slice as we read elements.
            data = data.slice();

            // Process multiple objects in the data.
            while (true) {
                bool gotElementEnd;
                int offset;

                try {
                    if (!usePartialData_) {
                        // This is the beginning of an element.
                        if (data.remaining() <= 0)
                            // Wait for more data.
                            return;
                    }

                    // Scan the input to check if a whole TLV object has been read.
                    tlvStructureDecoder_.seek(0);
                    gotElementEnd = tlvStructureDecoder_.findElementEnd(data);
                    offset = tlvStructureDecoder_.getOffset();
                } catch (EncodingException ex) {
                    // Reset to read a new element on the next call.
                    usePartialData_ = false;
                    tlvStructureDecoder_ = new TlvStructureDecoder();

                    throw ex;
                }

                if (gotElementEnd) {
                    // Got the remainder of an element.  Report to the caller.
                    ByteBuffer element;
                    if (usePartialData_) {
                        // We have partial data from a previous call, so append this data and point to partialData.
                        partialData_.ensuredPut(data, 0, offset);

                        element = partialData_.flippedBuffer();
                        // Assume we don't need to use partialData anymore until needed.
                        usePartialData_ = false;
                    } else {
                        // We are not using partialData, so just point to the input data buffer.
                        element = data.duplicate();
                        element.limit(offset);
                    }

                    // Reset to read a new object. Do this before calling onReceivedElement
                    // in case it throws an exception.
                    data.position(offset);
                    data = data.slice();
                    tlvStructureDecoder_ = new TlvStructureDecoder();

                    elementListener_.onReceivedElement(element);
                    if (data.remaining() <= 0)
                        // No more data in the packet.
                        return;

                    // else loop back to decode.
                } else {
                    // Save remaining data for a later call.
                    if (!usePartialData_) {
                        usePartialData_ = true;
                        partialData_.position(0);
                    }

                    if (partialData_.buffer().position() + data.remaining() > net.named_data.jndn.util.Common.MAX_NDN_PACKET_SIZE) {
                        // Reset to read a new element on the next call.
                        usePartialData_ = false;
                        tlvStructureDecoder_ = new TlvStructureDecoder();

                        throw new EncodingException(
                                "The incoming packet exceeds the maximum limit Face.getMaxNdnPacketSize()");
                    }

                    partialData_.ensuredPut(data);
                    return;
                }
            }
        }
开发者ID:named-data,项目名称:ndn-dot-net,代码行数:88,代码来源:ElementReader.cs

示例5: seek

 public void seek(long desired)
 {
     if (desired == 0 && bytes.Count == 0)
     {
         logEmptySeek(name);
         return;
     }
     int i = 0;
     foreach (DiskRange curRange in bytes)
     {
         if (desired == 0 && curRange.getData().remaining() == 0)
         {
             logEmptySeek(name);
             return;
         }
         if (curRange.getOffset() <= desired &&
             (desired - curRange.getOffset()) < curRange.getLength())
         {
             currentOffset = desired;
             currentRange = i;
             this.range = curRange.getData().duplicate();
             int pos = range.position();
             pos += (int)(desired - curRange.getOffset()); // this is why we duplicate
             this.range.position(pos);
             return;
         }
         ++i;
     }
     // if they are seeking to the precise end, go ahead and let them go there
     int segments = bytes.Count;
     if (segments != 0 && desired == bytes[segments - 1].getEnd())
     {
         currentOffset = desired;
         currentRange = segments - 1;
         DiskRange curRange = bytes[currentRange];
         this.range = curRange.getData().duplicate();
         int pos = range.position();
         pos += (int)(desired - curRange.getOffset()); // this is why we duplicate
         this.range.position(pos);
         return;
     }
     throw new ArgumentException("Seek in " + name + " to " +
       desired + " is outside of the data");
 }
开发者ID:CurtHagenlocher,项目名称:OrcSharp,代码行数:44,代码来源:InStream.cs

示例6: ensuredPut

 /// <summary>
 /// Call ensureCapacity to ensure there is capacity for buffer.remaining() more
 /// bytes and use buffer().put to copy.
 /// This increments the position by buffer.remaining().
 /// This does update buffer's position to its limit.
 /// </summary>
 ///
 /// <param name="buffer"></param>
 public void ensuredPut(ByteBuffer buffer)
 {
     ensureRemainingCapacity(buffer.remaining());
     int savePosition = buffer.position();
     buffer_.put(buffer);
     buffer.position(savePosition);
 }
开发者ID:named-data,项目名称:ndn-dot-net,代码行数:15,代码来源:DynamicByteBuffer.cs

示例7: writeBuffer

        /// <summary>
        /// Write the buffer from its position() to limit() to the output just
        /// before getLength() from the back. Advance getLength() of the output. This
        /// does NOT change buffer.position(). Note that this does not encode a type
        /// and length; for that see writeBlobTlv.
        /// </summary>
        ///
        /// <param name="buffer"></param>
        public void writeBuffer(ByteBuffer buffer)
        {
            if (buffer == null)
                return;

            // Write backwards.
            int position = output_.setRemainingFromBack(output_.remaining()
                    + buffer.remaining());
            int saveBufferValuePosition = buffer.position();
            output_.buffer().put(buffer);
            // Restore positions after put.
            output_.position(position);
            buffer.position(saveBufferValuePosition);
        }
开发者ID:named-data,项目名称:ndn-dot-net,代码行数:22,代码来源:TlvEncoder.cs

示例8: parse

 /// <summary>
 /// Parse the data from the input buffer recursively and return the root as an
 /// object of a subclass of DerNode.
 /// </summary>
 ///
 /// <param name="inputBuf"></param>
 /// <returns>An object of a subclass of DerNode.</returns>
 public static DerNode parse(ByteBuffer inputBuf)
 {
     return parse(inputBuf, inputBuf.position());
 }
开发者ID:named-data,项目名称:ndn-dot-net,代码行数:11,代码来源:DerNode.cs

示例9: toEscapedString

 /// <summary>
 /// Write the value to result, escaping characters according to the NDN URI
 /// Scheme.
 /// This also adds "..." to a value with zero or more ".".
 /// This does not add a type code prefix such as "sha256digest=".
 /// </summary>
 ///
 /// <param name="value"></param>
 /// <param name="result">The StringBuffer to write to.</param>
 public static void toEscapedString(ByteBuffer value_ren, StringBuilder result)
 {
     bool gotNonDot = false;
     for (int i = value_ren.position(); i < value_ren.limit(); ++i) {
         if (value_ren.get(i) != 0x2e) {
             gotNonDot = true;
             break;
         }
     }
     if (!gotNonDot) {
         // Special case for component of zero or more periods.  Add 3 periods.
         result.append("...");
         for (int i_0 = value_ren.position(); i_0 < value_ren.limit(); ++i_0)
             result.append('.');
     } else {
         for (int i_1 = value_ren.position(); i_1 < value_ren.limit(); ++i_1) {
             int x = ((int) value_ren.get(i_1) & 0xff);
             // Check for 0-9, A-Z, a-z, (+), (-), (.), (_)
             if (x >= 0x30 && x <= 0x39 || x >= 0x41 && x <= 0x5a
                     || x >= 0x61 && x <= 0x7a || x == 0x2b || x == 0x2d
                     || x == 0x2e || x == 0x5f)
                 result.append((char) x);
             else {
                 result.append('%');
                 if (x < 16)
                     result.append('0');
                 result.append(ILOG.J2CsMapping.Util.IlNumber.ToString(x,16).ToUpper());
             }
         }
     }
 }
开发者ID:named-data,项目名称:ndn-dot-net,代码行数:40,代码来源:Name.cs

示例10: toHex

 /// <summary>
 /// Write a hex string of the contents of buffer from position to limit to the
 /// output.
 /// </summary>
 ///
 /// <param name="buffer">The buffer.</param>
 /// <returns>A string of hex bytes.</returns>
 /// <param name="output">The StringBuffer to write to.</param>
 public static void toHex(ByteBuffer buffer, StringBuilder output)
 {
     for (int i = buffer.position(); i < buffer.limit(); ++i) {
         String hex = ILOG.J2CsMapping.Util.IlNumber.ToString((int) buffer.get(i) & 0xff,16);
         if (hex.Length <= 1)
             // Append the leading zero.
             output.append("0");
         output.append(hex);
     }
 }
开发者ID:named-data,项目名称:ndn-dot-net,代码行数:18,代码来源:Blob.cs

示例11: output

 public void output(ByteBuffer buffer)
 {
     _output.Write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
 }
开发者ID:CurtHagenlocher,项目名称:OrcSharp,代码行数:4,代码来源:WriterImpl.cs

示例12: readByteBuffer

 private static int readByteBuffer(Stream file, ByteBuffer dest)
 {
     int pos = dest.position();
     int result = dest.readRemaining(file);
     if (result > 0)
     {
         // Ensure this explicitly since versions before 2.7 read doesn't do it.
         dest.position(pos + result);
     }
     return result;
 }
开发者ID:CurtHagenlocher,项目名称:OrcSharp,代码行数:11,代码来源:RecordReaderUtils.cs

示例13: readDirect

 public static void readDirect(Stream file, int len, ByteBuffer directBuf)
 {
     // TODO: HDFS API is a mess, so handle all kinds of cases.
     // Before 2.7, read() also doesn't adjust position correctly, so track it separately.
     int pos = directBuf.position(), startPos = pos, endPos = pos + len;
     try
     {
         while (pos < endPos)
         {
             int count = readByteBuffer(file, directBuf);
             if (count < 0) throw new EndOfStreamException();
             Debug.Assert(count != 0, "0-length read: " + (endPos - pos) + "@" + (pos - startPos));
             pos += count;
             Debug.Assert(pos <= endPos, "Position " + pos + " > " + endPos + " after reading " + count);
             directBuf.position(pos);
         }
     }
     catch (NotSupportedException)
     {
         Debug.Assert(pos == startPos);
         // Happens in q files and such.
         RecordReaderImpl.LOG.error("Stream does not support direct read; we will copy.");
         byte[] buffer = new byte[len];
         file.readFully(buffer, 0, buffer.Length);
         directBuf.put(buffer);
     }
     directBuf.position(startPos);
     directBuf.limit(startPos + len);
 }
开发者ID:CurtHagenlocher,项目名称:OrcSharp,代码行数:29,代码来源:RecordReaderUtils.cs

示例14: computeHmacWithSha256

        /// <summary>
        /// Compute the HMAC with SHA-256 of data, as defined in
        /// http://tools.ietf.org/html/rfc2104#section-2 .
        /// </summary>
        ///
        /// <param name="key">The key byte array.</param>
        /// <param name="data">The input byte buffer. This does not change the position.</param>
        /// <returns>The HMAC result.</returns>
        public static byte[] computeHmacWithSha256(byte[] key, ByteBuffer data)
        {
            using (var hmac = new HMACSHA256(key)) {
            // Copy the buffer to an array.
            var array = new byte[data.remaining()];
            int savePosition = data.position();
            data.get(array);
            data.position(savePosition);

            return hmac.ComputeHash(array);
              }
        }
开发者ID:named-data,项目名称:ndn-dot-net,代码行数:20,代码来源:util-common.cs

示例15: digestSha256

        /// <summary>
        /// Compute the sha-256 digest of data.
        /// </summary>
        ///
        /// <param name="data">The input byte buffer. This does not change the position.</param>
        /// <returns>The digest.</returns>
        public static byte[] digestSha256(ByteBuffer data)
        {
            // Copy the buffer to an array.
              var array = new byte[data.remaining()];
              int savePosition = data.position();
              data.get(array);
              data.position(savePosition);

              return sha256_.ComputeHash(array);
        }
开发者ID:named-data,项目名称:ndn-dot-net,代码行数:16,代码来源:util-common.cs


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