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


C# InputStream.Read方法代码示例

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


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

示例1: CopyStream

 /// <exception cref="System.IO.IOException"></exception>
 public static void CopyStream(InputStream @is, OutputStream os)
 {
     int n;
     byte[] buffer = new byte[16384];
     while ((n = @is.Read(buffer)) > -1)
     {
         os.Write(buffer, 0, n);
     }
     os.Close();
     @is.Close();
 }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:12,代码来源:StreamUtils.cs

示例2: CopyStreamToFile

 /// <exception cref="System.IO.IOException"></exception>
 public static void CopyStreamToFile(InputStream @is, FilePath file)
 {
     OutputStream os = new FileOutputStream(file);
     int n;
     byte[] buffer = new byte[16384];
     while ((n = @is.Read(buffer)) > -1)
     {
         os.Write(buffer, 0, n);
     }
     os.Close();
     @is.Close();
 }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:13,代码来源:StreamUtils.cs

示例3: Read

		/// <exception cref="System.IO.IOException"></exception>
		public static byte[] Read(InputStream @is)
		{
			int initialCapacity = 1024;
			ByteArrayBuffer byteArrayBuffer = new ByteArrayBuffer(initialCapacity);
			byte[] bytes = new byte[512];
			int offset = 0;
			int numRead = 0;
			while ((numRead = @is.Read(bytes, offset, bytes.Length - offset)) >= 0)
			{
				byteArrayBuffer.Append(bytes, 0, numRead);
				offset += numRead;
			}
			return byteArrayBuffer.ToByteArray();
		}
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:15,代码来源:TextUtils.cs

示例4: ByteBuffer

 /// <summary>Loads the stream into a buffer.</summary>
 /// <param name="in">an InputStream</param>
 /// <exception cref="System.IO.IOException">If the stream cannot be read.</exception>
 public ByteBuffer(InputStream @in)
 {
     // load stream into buffer
     int chunk = 16384;
     this.length = 0;
     this.buffer = new sbyte[chunk];
     int read;
     while ((read = @in.Read(this.buffer, this.length, chunk)) > 0)
     {
         this.length += read;
         if (read == chunk)
         {
             EnsureCapacity(length + chunk);
         }
         else
         {
             break;
         }
     }
 }
开发者ID:Sicos1977,项目名称:n-metadata-extractor,代码行数:23,代码来源:ByteBuffer.cs

示例5: DirCacheEntry

        /// <exception cref="System.IO.IOException"></exception>
        internal DirCacheEntry(byte[] sharedInfo, MutableInteger infoAt, InputStream @in, 
			MessageDigest md)
        {
            // private static final int P_CTIME_NSEC = 4;
            // private static final int P_MTIME_NSEC = 12;
            // private static final int P_DEV = 16;
            // private static final int P_INO = 20;
            // private static final int P_UID = 28;
            // private static final int P_GID = 32;
            info = sharedInfo;
            infoOffset = infoAt.value;
            IOUtil.ReadFully(@in, info, infoOffset, INFO_LEN);
            int len;
            if (IsExtended)
            {
                len = INFO_LEN_EXTENDED;
                IOUtil.ReadFully(@in, info, infoOffset + INFO_LEN, INFO_LEN_EXTENDED - INFO_LEN);
                if ((GetExtendedFlags() & ~EXTENDED_FLAGS) != 0)
                {
                    throw new IOException(MessageFormat.Format(JGitText.Get().DIRCUnrecognizedExtendedFlags
                        , GetExtendedFlags().ToString()));
                }
            }
            else
            {
                len = INFO_LEN;
            }
            infoAt.value += len;
            md.Update(info, infoOffset, len);
            int pathLen = NB.DecodeUInt16(info, infoOffset + P_FLAGS) & NAME_MASK;
            int skipped = 0;
            if (pathLen < NAME_MASK)
            {
                path = new byte[pathLen];
                IOUtil.ReadFully(@in, path, 0, pathLen);
                md.Update(path, 0, pathLen);
            }
            else
            {
                ByteArrayOutputStream tmp = new ByteArrayOutputStream();
                {
                    byte[] buf = new byte[NAME_MASK];
                    IOUtil.ReadFully(@in, buf, 0, NAME_MASK);
                    tmp.Write(buf);
                }
                for (; ; )
                {
                    int c = @in.Read();
                    if (c < 0)
                    {
                        throw new EOFException(JGitText.Get().shortReadOfBlock);
                    }
                    if (c == 0)
                    {
                        break;
                    }
                    tmp.Write(c);
                }
                path = tmp.ToByteArray();
                pathLen = path.Length;
                skipped = 1;
                // we already skipped 1 '\0' above to break the loop.
                md.Update(path, 0, pathLen);
                md.Update(unchecked((byte)0));
            }
            // Index records are padded out to the next 8 byte alignment
            // for historical reasons related to how C Git read the files.
            //
            int actLen = len + pathLen;
            int expLen = (actLen + 8) & ~7;
            int padLen = expLen - actLen - skipped;
            if (padLen > 0)
            {
                IOUtil.SkipFully(@in, padLen);
                md.Update(nullpad, 0, padLen);
            }
        }
开发者ID:sharwell,项目名称:ngit,代码行数:78,代码来源:DirCacheEntry.cs

示例6: Read

		internal virtual void Read(InputStream inputStream)
		{
			byte[] buffer = new byte[1024];
			int len;
			length = 0;
			try
			{
				while ((len = inputStream.Read(buffer)) != -1)
				{
					outStream.Write(buffer, 0, len);
					sha1Digest.Update(buffer);
					md5Digest.Update(buffer);
					length += len;
				}
			}
			catch (IOException e)
			{
				throw new RuntimeException("Unable to read from stream.", e);
			}
			finally
			{
				try
				{
					inputStream.Close();
				}
				catch (IOException e)
				{
					Log.W(Database.Tag, "Exception closing input stream", e);
				}
			}
		}
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:31,代码来源:BlobStoreWriter.cs

示例7: _put

		/// <exception cref="NSch.SftpException"></exception>
		public virtual void _put(InputStream src, string dst, SftpProgressMonitor monitor
			, int mode)
		{
			try
			{
				byte[] dstb = Util.Str2byte(dst, fEncoding);
				long skip = 0;
				if (mode == RESUME || mode == APPEND)
				{
					try
					{
						SftpATTRS attr = _stat(dstb);
						skip = attr.GetSize();
					}
					catch (Exception)
					{
					}
				}
				//System.err.println(eee);
				if (mode == RESUME && skip > 0)
				{
					long skipped = src.Skip(skip);
					if (skipped < skip)
					{
						throw new SftpException(SSH_FX_FAILURE, "failed to resume for " + dst);
					}
				}
				if (mode == OVERWRITE)
				{
					SendOPENW(dstb);
				}
				else
				{
					SendOPENA(dstb);
				}
				ChannelHeader header = new ChannelHeader(this);
				header = Header(buf, header);
				int length = header.length;
				int type = header.type;
				Fill(buf, length);
				if (type != SSH_FXP_STATUS && type != SSH_FXP_HANDLE)
				{
					throw new SftpException(SSH_FX_FAILURE, "invalid type=" + type);
				}
				if (type == SSH_FXP_STATUS)
				{
					int i = buf.GetInt();
					ThrowStatusError(buf, i);
				}
				byte[] handle = buf.GetString();
				// handle
				byte[] data = null;
				bool dontcopy = true;
				if (!dontcopy)
				{
					data = new byte[buf.buffer.Length - (5 + 13 + 21 + handle.Length + 32 + 20)];
				}
				// padding and mac
				long offset = 0;
				if (mode == RESUME || mode == APPEND)
				{
					offset += skip;
				}
				int startid = seq;
				int _ackid = seq;
				int ackcount = 0;
				while (true)
				{
					int nread = 0;
					int s = 0;
					int datalen = 0;
					int count = 0;
					if (!dontcopy)
					{
						datalen = data.Length - s;
					}
					else
					{
						data = buf.buffer;
						s = 5 + 13 + 21 + handle.Length;
						datalen = buf.buffer.Length - s - 32 - 20;
					}
					do
					{
						// padding and mac
						nread = src.Read(data, s, datalen);
						if (nread > 0)
						{
							s += nread;
							datalen -= nread;
							count += nread;
						}
					}
					while (datalen > 0 && nread > 0);
					if (count <= 0)
					{
						break;
					}
					int _i = count;
//.........这里部分代码省略.........
开发者ID:yayanyang,项目名称:monodevelop,代码行数:101,代码来源:ChannelSftp.cs

示例8: ReadSome

		/// <exception cref="System.IO.IOException"></exception>
		private static int ReadSome(InputStream @in, byte[] hdr, int off, int cnt)
		{
			int avail = 0;
			while (0 < cnt)
			{
				int n = @in.Read(hdr, off, cnt);
				if (n < 0)
				{
					break;
				}
				avail += n;
				off += n;
				cnt -= n;
			}
			return avail;
		}
开发者ID:nocache,项目名称:monodevelop,代码行数:17,代码来源:UnpackedObject.cs

示例9: IdFor

 /// <summary>Compute the name of an object, without inserting it.</summary>
 /// <remarks>Compute the name of an object, without inserting it.</remarks>
 /// <param name="objectType">type code of the object to store.</param>
 /// <param name="length">
 /// number of bytes to scan from
 /// <code>in</code>
 /// .
 /// </param>
 /// <param name="in">
 /// stream providing the object content. The caller is responsible
 /// for closing the stream.
 /// </param>
 /// <returns>the name of the object.</returns>
 /// <exception cref="System.IO.IOException">the source stream could not be read.</exception>
 public virtual ObjectId IdFor(int objectType, long length, InputStream @in)
 {
     MessageDigest md = Digest();
     md.Update(Constants.EncodedTypeString(objectType));
     md.Update(unchecked((byte)' '));
     md.Update(Constants.EncodeASCII(length));
     md.Update(unchecked((byte)0));
     byte[] buf = Buffer();
     while (length > 0)
     {
         int n = @in.Read(buf, 0, (int)Math.Min(length, buf.Length));
         if (n < 0)
         {
             throw new EOFException("Unexpected end of input");
         }
         md.Update(buf, 0, n);
         length -= n;
     }
     return ObjectId.FromRaw(md.Digest());
 }
开发者ID:sharwell,项目名称:ngit,代码行数:34,代码来源:ObjectInserter.cs

示例10: Hash

		/// <exception cref="System.IO.IOException"></exception>
		/// <exception cref="NGit.Diff.SimilarityIndex.TableFullException"></exception>
		internal virtual void Hash(InputStream @in, long remaining)
		{
			byte[] buf = new byte[4096];
			int ptr = 0;
			int cnt = 0;
			while (0 < remaining)
			{
				int hash = 5381;
				// Hash one line, or one block, whichever occurs first.
				int n = 0;
				do
				{
					if (ptr == cnt)
					{
						ptr = 0;
						cnt = @in.Read(buf, 0, buf.Length);
						if (cnt <= 0)
						{
							throw new EOFException();
						}
					}
					n++;
					int c = buf[ptr++] & unchecked((int)(0xff));
					if (c == '\n')
					{
						break;
					}
					hash = (hash << 5) + hash + c;
				}
				while (n < 64 && n < remaining);
				Add(hash, n);
				remaining -= n;
			}
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:36,代码来源:SimilarityIndex.cs

示例11: ReadWholeStream

 // ignore any close errors, this was a read only stream
 /// <summary>Read an entire input stream into memory as a ByteBuffer.</summary>
 /// <remarks>
 /// Read an entire input stream into memory as a ByteBuffer.
 /// Note: The stream is read to its end and is not usable after calling this
 /// method. The caller is responsible for closing the stream.
 /// </remarks>
 /// <param name="in">input stream to be read.</param>
 /// <param name="sizeHint">
 /// a hint on the approximate number of bytes contained in the
 /// stream, used to allocate temporary buffers more efficiently
 /// </param>
 /// <returns>
 /// complete contents of the input stream. The ByteBuffer always has
 /// a writable backing array, with
 /// <code>position() == 0</code>
 /// and
 /// <code>limit()</code>
 /// equal to the actual length read. Callers may rely
 /// on obtaining the underlying array for efficient data access. If
 /// <code>sizeHint</code>
 /// was too large, the array may be over-allocated,
 /// resulting in
 /// <code>limit() &lt; array().length</code>
 /// .
 /// </returns>
 /// <exception cref="System.IO.IOException">there was an error reading from the stream.
 /// 	</exception>
 public static ByteBuffer ReadWholeStream(InputStream @in, int sizeHint)
 {
     byte[] @out = new byte[sizeHint];
     int pos = 0;
     while (pos < @out.Length)
     {
         int read = @in.Read(@out, pos, @out.Length - pos);
         if (read < 0)
         {
             return ByteBuffer.Wrap(@out, 0, pos);
         }
         pos += read;
     }
     int last = @in.Read();
     if (last < 0)
     {
         return ByteBuffer.Wrap(@out, 0, pos);
     }
     TemporaryBuffer.Heap tmp = new TemporaryBuffer.Heap(int.MaxValue);
     tmp.Write(@out);
     tmp.Write(last);
     tmp.Copy(@in);
     return ByteBuffer.Wrap(tmp.ToByteArray());
 }
开发者ID:JamesChan,项目名称:ngit,代码行数:52,代码来源:IOUtil.cs

示例12: ReadFully

 /// <summary>Read the entire byte array into memory, unless input is shorter</summary>
 /// <param name="fd">input stream to read the data from.</param>
 /// <param name="dst">buffer that must be fully populated, [off, off+len).</param>
 /// <param name="off">position within the buffer to start writing to.</param>
 /// <returns>number of bytes in buffer or stream, whichever is shortest</returns>
 /// <exception cref="System.IO.IOException">there was an error reading from the stream.
 /// 	</exception>
 public static int ReadFully(InputStream fd, byte[] dst, int off)
 {
     int r;
     int len = 0;
     while ((r = fd.Read(dst, off, dst.Length - off)) >= 0 && len < dst.Length)
     {
         off += r;
         len += r;
     }
     return len;
 }
开发者ID:JamesChan,项目名称:ngit,代码行数:18,代码来源:IOUtil.cs

示例13: Fill

		/// <exception cref="NSch.JSchException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		private void Fill(InputStream @in, byte[] buf, int len)
		{
			int s = 0;
			while (s < len)
			{
				int i = @in.Read(buf, s, len - s);
				if (i <= 0)
				{
					throw new JSchException("ProxySOCKS5: stream is closed");
				}
				s += i;
			}
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:15,代码来源:ProxySOCKS5.cs

示例14: ToTemp

		/// <exception cref="System.IO.IOException"></exception>
		/// <exception cref="System.IO.FileNotFoundException"></exception>
		/// <exception cref="Sharpen.Error"></exception>
		private FilePath ToTemp(MessageDigest md, int type, long len, InputStream @is)
		{
			bool delete = true;
			FilePath tmp = NewTempFile();
			try
			{
				FileOutputStream fOut = new FileOutputStream(tmp);
				try
				{
					OutputStream @out = fOut;
					if (config.GetFSyncObjectFiles())
					{
						@out = Channels.NewOutputStream(fOut.GetChannel());
					}
					DeflaterOutputStream cOut = Compress(@out);
					DigestOutputStream dOut = new DigestOutputStream(cOut, md);
					WriteHeader(dOut, type, len);
					byte[] buf = Buffer();
					while (len > 0)
					{
						int n = @is.Read(buf, 0, (int)Math.Min(len, buf.Length));
						if (n <= 0)
						{
							throw ShortInput(len);
						}
						dOut.Write(buf, 0, n);
						len -= n;
					}
					dOut.Flush();
					cOut.Finish();
				}
				finally
				{
					if (config.GetFSyncObjectFiles())
					{
						fOut.GetChannel().Force(true);
					}
					fOut.Close();
				}
				delete = false;
				return tmp;
			}
			finally
			{
				if (delete)
				{
					FileUtils.Delete(tmp);
				}
			}
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:53,代码来源:ObjectDirectoryInserter.cs

示例15: Copy

		/// <summary>Copy all bytes remaining on the input stream into this buffer.</summary>
		/// <remarks>Copy all bytes remaining on the input stream into this buffer.</remarks>
		/// <param name="in">the stream to read from, until EOF is reached.</param>
		/// <exception cref="System.IO.IOException">
		/// an error occurred reading from the input stream, or while
		/// writing to a local temporary file.
		/// </exception>
		public virtual void Copy(InputStream @in)
		{
			if (blocks != null)
			{
				for (; ; )
				{
					TemporaryBuffer.Block s = Last();
					if (s.IsFull())
					{
						if (ReachedInCoreLimit())
						{
							break;
						}
						s = new TemporaryBuffer.Block();
						blocks.AddItem(s);
					}
					int n = @in.Read(s.buffer, s.count, s.buffer.Length - s.count);
					if (n < 1)
					{
						return;
					}
					s.count += n;
				}
			}
			byte[] tmp = new byte[TemporaryBuffer.Block.SZ];
			int n_1;
			while ((n_1 = @in.Read(tmp)) > 0)
			{
				overflow.Write(tmp, 0, n_1);
			}
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:38,代码来源:TemporaryBuffer.cs


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