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


C# FileInputStream.Read方法代码示例

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


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

示例1: CopyFile

		/// <exception cref="System.IO.IOException"></exception>
		protected internal static void CopyFile(FilePath src, FilePath dst)
		{
			FileInputStream fis = new FileInputStream(src);
			try
			{
				FileOutputStream fos = new FileOutputStream(dst);
				try
				{
					byte[] buf = new byte[4096];
					int r;
					while ((r = fis.Read(buf)) > 0)
					{
						fos.Write(buf, 0, r);
					}
				}
				finally
				{
					fos.Close();
				}
			}
			finally
			{
				fis.Close();
			}
		}
开发者ID:shoff,项目名称:ngit,代码行数:26,代码来源:RepositoryTestCase.cs

示例2: CopyCurrentContent

 /// <summary>Copy the current file content into the temporary file.</summary>
 /// <remarks>
 /// Copy the current file content into the temporary file.
 /// <p>
 /// This method saves the current file content by inserting it into the
 /// temporary file, so that the caller can safely append rather than replace
 /// the primary file.
 /// <p>
 /// This method does nothing if the current file does not exist, or exists
 /// but is empty.
 /// </remarks>
 /// <exception cref="System.IO.IOException">
 /// the temporary file could not be written, or a read error
 /// occurred while reading from the current file. The lock is
 /// released before throwing the underlying IO exception to the
 /// caller.
 /// </exception>
 /// <exception cref="Sharpen.RuntimeException">
 /// the temporary file could not be written. The lock is released
 /// before throwing the underlying exception to the caller.
 /// </exception>
 public virtual void CopyCurrentContent()
 {
     RequireLock();
     try
     {
         FileInputStream fis = new FileInputStream(@ref);
         try
         {
             if (fsync)
             {
                 FileChannel @in = fis.GetChannel();
                 long pos = 0;
                 long cnt = @in.Size();
                 while (0 < cnt)
                 {
                     long r = os.GetChannel().TransferFrom(@in, pos, cnt);
                     pos += r;
                     cnt -= r;
                 }
             }
             else
             {
                 byte[] buf = new byte[2048];
                 int r;
                 while ((r = fis.Read(buf)) >= 0)
                 {
                     os.Write(buf, 0, r);
                 }
             }
         }
         finally
         {
             fis.Close();
         }
     }
     catch (FileNotFoundException)
     {
     }
     catch (IOException ioe)
     {
         // Don't worry about a file that doesn't exist yet, it
         // conceptually has no current content to copy.
         //
         Unlock();
         throw;
     }
     catch (RuntimeException ioe)
     {
         Unlock();
         throw;
     }
     catch (Error ioe)
     {
         Unlock();
         throw;
     }
 }
开发者ID:kenji-tan,项目名称:ngit,代码行数:78,代码来源:LockFile.cs

示例3: AssertWorkDir

        /// <exception cref="NGit.Errors.CorruptObjectException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        public virtual void AssertWorkDir(Dictionary<string, string> i)
        {
            TreeWalk walk = new TreeWalk(db);
            walk.Recursive = true;
            walk.AddTree(new FileTreeIterator(db));
            string expectedValue;
            string path;
            int nrFiles = 0;
            FileTreeIterator ft;
            while (walk.Next())
            {
                ft = walk.GetTree<FileTreeIterator>(0);
                path = ft.EntryPathString;
                expectedValue = i.Get(path);
                NUnit.Framework.Assert.IsNotNull(expectedValue, "found unexpected file for path "
                     + path + " in workdir");
                FilePath file = new FilePath(db.WorkTree, path);
                NUnit.Framework.Assert.IsTrue(file.Exists());
                if (file.IsFile())
                {
                    FileInputStream @is = new FileInputStream(file);
                    byte[] buffer = new byte[(int)file.Length()];
                    int offset = 0;
                    int numRead = 0;
                    while (offset < buffer.Length && (numRead = @is.Read(buffer, offset, buffer.Length
                         - offset)) >= 0)
                    {
                        offset += numRead;
                    }
                    @is.Close();

                    CollectionAssert.AreEqual (buffer, Sharpen.Runtime.GetBytesForString(i.Get(path)),
                        "unexpected content for path " + path + " in workDir. ");
                    nrFiles++;
                }
            }
            NUnit.Framework.Assert.AreEqual(i.Count, nrFiles, "WorkDir has not the right size."
                );
        }
开发者ID:JamesChan,项目名称:ngit,代码行数:41,代码来源:DirCacheCheckoutTest.cs

示例4: WriteTo

 /// <exception cref="System.IO.IOException"></exception>
 public override void WriteTo(OutputStream @out)
 {
     if (@out == null)
     {
         throw new ArgumentException("Output stream may not be null");
     }
     InputStream @in = new FileInputStream(this.file);
     try
     {
         byte[] tmp = new byte[4096];
         int l;
         while ((l = @in.Read(tmp)) != -1)
         {
             @out.Write(tmp, 0, l);
         }
         @out.Flush();
     }
     finally
     {
         @in.Close();
     }
 }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:23,代码来源:FileBody.cs

示例5: WriteTo

			/// <exception cref="System.IO.IOException"></exception>
			public override void WriteTo(OutputStream os, ProgressMonitor pm)
			{
				if (onDiskFile == null)
				{
					base.WriteTo(os, pm);
					return;
				}
				if (pm == null)
				{
					pm = NullProgressMonitor.INSTANCE;
				}
				FileInputStream @in = new FileInputStream(onDiskFile);
				try
				{
					int cnt;
					byte[] buf = new byte[TemporaryBuffer.Block.SZ];
					while ((cnt = @in.Read(buf)) >= 0)
					{
						os.Write(buf, 0, cnt);
						pm.Update(cnt / 1024);
					}
				}
				finally
				{
					@in.Close();
				}
			}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:28,代码来源:TemporaryBuffer.cs

示例6: KeyForBlobFromFile

 public static BlobKey KeyForBlobFromFile(FileInfo file)
 {
     MessageDigest md;
     try
     {
         md = MessageDigest.GetInstance("SHA-1");
     }
     catch (NoSuchAlgorithmException)
     {
         Log.E(Database.Tag, "Error, SHA-1 digest is unavailable.");
         return null;
     }
     byte[] sha1hash = new byte[40];
     try
     {
         var fis = new FileInputStream(file);
         byte[] buffer = new byte[65536];
         int lenRead = fis.Read(buffer);
         while (lenRead > 0)
         {
             md.Update(buffer, 0, lenRead);
             lenRead = fis.Read(buffer);
         }
         fis.Close();
     }
     catch (IOException)
     {
         Log.E(Database.Tag, "Error readin tmp file to compute key");
     }
     sha1hash = md.Digest();
     BlobKey result = new BlobKey(sha1hash);
     return result;
 }
开发者ID:FireflyLogic,项目名称:couchbase-lite-net,代码行数:33,代码来源:BlobStore.cs

示例7: GetBytesFromFile

 /// <exception cref="System.IO.IOException"></exception>
 private static byte[] GetBytesFromFile(FilePath file)
 {
     InputStream @is = new FileInputStream(file);
     // Get the size of the file
     long length = file.Length();
     // Create the byte array to hold the data
     byte[] bytes = new byte[(int)length];
     // Read in the bytes
     int offset = 0;
     int numRead = 0;
     while (offset < bytes.Length && (numRead = @is.Read(bytes, offset, bytes.Length -
          offset)) >= 0)
     {
         offset += numRead;
     }
     // Ensure all the bytes have been read in
     if (offset < bytes.Length)
     {
         throw new IOException("Could not completely read file " + file.GetName());
     }
     // Close the input stream and return bytes
     @is.Close();
     return bytes;
 }
开发者ID:FireflyLogic,项目名称:couchbase-lite-net,代码行数:25,代码来源:BlobStore.cs

示例8: AssertFileContentsEqual

 /// <exception cref="System.IO.IOException"></exception>
 private void AssertFileContentsEqual(FilePath actFile, string @string)
 {
     ByteArrayOutputStream bos = new ByteArrayOutputStream();
     FileInputStream fis = null;
     byte[] buffer = new byte[100];
     try
     {
         fis = new FileInputStream(actFile);
         int read = fis.Read(buffer);
         while (read > 0)
         {
             bos.Write(buffer, 0, read);
             read = fis.Read(buffer);
         }
         string content = Sharpen.Runtime.GetStringForBytes(bos.ToByteArray(), "UTF-8");
         NUnit.Framework.Assert.AreEqual(@string, content);
     }
     finally
     {
         if (fis != null)
         {
             fis.Close();
         }
     }
 }
开发者ID:nnieslan,项目名称:ngit,代码行数:26,代码来源:PullCommandWithRebaseTest.cs

示例9: Load

		/// <exception cref="NSch.JSchException"></exception>
		public static NSch.KeyPair Load(JSch jsch, string prvkey, string pubkey)
		{
			byte[] iv = new byte[8];
			// 8
			bool encrypted = true;
			byte[] data = null;
			byte[] publickeyblob = null;
			int type = ERROR;
			int vendor = VENDOR_OPENSSH;
			try
			{
				FilePath file = new FilePath(prvkey);
				FileInputStream fis = new FileInputStream(prvkey);
				byte[] buf = new byte[(int)(file.Length())];
				int len = 0;
				while (true)
				{
					int i = fis.Read(buf, len, buf.Length - len);
					if (i <= 0)
					{
						break;
					}
					len += i;
				}
				fis.Close();
				int i_1 = 0;
				while (i_1 < len)
				{
					if (buf[i_1] == 'B' && buf[i_1 + 1] == 'E' && buf[i_1 + 2] == 'G' && buf[i_1 + 3]
						 == 'I')
					{
						i_1 += 6;
						if (buf[i_1] == 'D' && buf[i_1 + 1] == 'S' && buf[i_1 + 2] == 'A')
						{
							type = DSA;
						}
						else
						{
							if (buf[i_1] == 'R' && buf[i_1 + 1] == 'S' && buf[i_1 + 2] == 'A')
							{
								type = RSA;
							}
							else
							{
								if (buf[i_1] == 'S' && buf[i_1 + 1] == 'S' && buf[i_1 + 2] == 'H')
								{
									// FSecure
									type = UNKNOWN;
									vendor = VENDOR_FSECURE;
								}
								else
								{
									//System.err.println("invalid format: "+identity);
									throw new JSchException("invalid privatekey: " + prvkey);
								}
							}
						}
						i_1 += 3;
						continue;
					}
					if (buf[i_1] == 'C' && buf[i_1 + 1] == 'B' && buf[i_1 + 2] == 'C' && buf[i_1 + 3]
						 == ',')
					{
						i_1 += 4;
						for (int ii = 0; ii < iv.Length; ii++)
						{
							iv[ii] = unchecked((byte)(((A2b(buf[i_1++]) << 4) & unchecked((int)(0xf0))) + (A2b
								(buf[i_1++]) & unchecked((int)(0xf)))));
						}
						continue;
					}
					if (buf[i_1] == unchecked((int)(0x0d)) && i_1 + 1 < buf.Length && buf[i_1 + 1] ==
						 unchecked((int)(0x0a)))
					{
						i_1++;
						continue;
					}
					if (buf[i_1] == unchecked((int)(0x0a)) && i_1 + 1 < buf.Length)
					{
						if (buf[i_1 + 1] == unchecked((int)(0x0a)))
						{
							i_1 += 2;
							break;
						}
						if (buf[i_1 + 1] == unchecked((int)(0x0d)) && i_1 + 2 < buf.Length && buf[i_1 + 2
							] == unchecked((int)(0x0a)))
						{
							i_1 += 3;
							break;
						}
						bool inheader = false;
						for (int j = i_1 + 1; j < buf.Length; j++)
						{
							if (buf[j] == unchecked((int)(0x0a)))
							{
								break;
							}
							//if(buf[j]==0x0d) break;
							if (buf[j] == ':')
//.........这里部分代码省略.........
开发者ID:yayanyang,项目名称:monodevelop,代码行数:101,代码来源:KeyPair.cs

示例10: ReadSome

 /// <summary>Read at most limit bytes from the local file into memory as a byte array.
 /// 	</summary>
 /// <remarks>Read at most limit bytes from the local file into memory as a byte array.
 /// 	</remarks>
 /// <param name="path">location of the file to read.</param>
 /// <param name="limit">
 /// maximum number of bytes to read, if the file is larger than
 /// only the first limit number of bytes are returned
 /// </param>
 /// <returns>
 /// complete contents of the requested local file. If the contents
 /// exceeds the limit, then only the limit is returned.
 /// </returns>
 /// <exception cref="System.IO.FileNotFoundException">the file does not exist.</exception>
 /// <exception cref="System.IO.IOException">the file exists, but its contents cannot be read.
 /// 	</exception>
 public static byte[] ReadSome(FilePath path, int limit)
 {
     FileInputStream @in = new FileInputStream(path);
     try
     {
         byte[] buf = new byte[limit];
         int cnt = 0;
         for (; ; )
         {
             int n = @in.Read(buf, cnt, buf.Length - cnt);
             if (n <= 0)
             {
                 break;
             }
             cnt += n;
         }
         if (cnt == buf.Length)
         {
             return buf;
         }
         byte[] res = new byte[cnt];
         System.Array.Copy(buf, 0, res, 0, cnt);
         return res;
     }
     finally
     {
         try
         {
             @in.Close();
         }
         catch (IOException)
         {
         }
     }
 }
开发者ID:JamesChan,项目名称:ngit,代码行数:51,代码来源:IOUtil.cs

示例11: NewInstance

		// DSA
		// RSA
		// modulus
		// public exponent
		// private exponent
		//  private String algname="ssh-dss";
		/// <exception cref="NSch.JSchException"></exception>
		internal static NSch.IdentityFile NewInstance(string prvfile, string pubfile, JSch
			 jsch)
		{
			byte[] prvkey = null;
			byte[] pubkey = null;
			FilePath file = null;
			FileInputStream fis = null;
			try
			{
				file = new FilePath(prvfile);
				fis = new FileInputStream(prvfile);
				prvkey = new byte[(int)(file.Length())];
				int len = 0;
				while (true)
				{
					int i = fis.Read(prvkey, len, prvkey.Length - len);
					if (i <= 0)
					{
						break;
					}
					len += i;
				}
				fis.Close();
			}
			catch (Exception e)
			{
				try
				{
					if (fis != null)
					{
						fis.Close();
					}
				}
				catch (Exception)
				{
				}
				if (e is Exception)
				{
					throw new JSchException(e.ToString(), (Exception)e);
				}
				throw new JSchException(e.ToString());
			}
			string _pubfile = pubfile;
			if (pubfile == null)
			{
				_pubfile = prvfile + ".pub";
			}
			try
			{
				file = new FilePath(_pubfile);
				fis = new FileInputStream(_pubfile);
				pubkey = new byte[(int)(file.Length())];
				int len = 0;
				while (true)
				{
					int i = fis.Read(pubkey, len, pubkey.Length - len);
					if (i <= 0)
					{
						break;
					}
					len += i;
				}
				fis.Close();
			}
			catch (Exception e)
			{
				try
				{
					if (fis != null)
					{
						fis.Close();
					}
				}
				catch (Exception)
				{
				}
				if (pubfile != null)
				{
					// The pubfile is explicitry given, but not accessible.
					if (e is Exception)
					{
						throw new JSchException(e.ToString(), (Exception)e);
					}
					throw new JSchException(e.ToString());
				}
			}
			return NewInstance(prvfile, prvkey, pubkey, jsch);
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:95,代码来源:IdentityFile.cs

示例12: ReadFully

 // do nothing
 /// <summary>Read an entire local file into memory as a byte array.</summary>
 /// <remarks>Read an entire local file into memory as a byte array.</remarks>
 /// <param name="path">location of the file to read.</param>
 /// <param name="max">
 /// maximum number of bytes to read, if the file is larger than
 /// this limit an IOException is thrown.
 /// </param>
 /// <returns>complete contents of the requested local file.</returns>
 /// <exception cref="System.IO.FileNotFoundException">the file does not exist.</exception>
 /// <exception cref="System.IO.IOException">the file exists, but its contents cannot be read.
 /// 	</exception>
 public static byte[] ReadFully(FilePath path, int max)
 {
     FileInputStream @in = new FileInputStream(path);
     try
     {
         long sz = Math.Max(path.Length(), 1);
         if (sz > max)
         {
             throw new IOException(MessageFormat.Format(JGitText.Get().fileIsTooLarge, path));
         }
         byte[] buf = new byte[(int)sz];
         int valid = 0;
         for (; ; )
         {
             if (buf.Length == valid)
             {
                 if (buf.Length == max)
                 {
                     int next = @in.Read();
                     if (next < 0)
                     {
                         break;
                     }
                     throw new IOException(MessageFormat.Format(JGitText.Get().fileIsTooLarge, path));
                 }
                 byte[] nb = new byte[Math.Min(buf.Length * 2, max)];
                 System.Array.Copy(buf, 0, nb, 0, valid);
                 buf = nb;
             }
             int n = @in.Read(buf, valid, buf.Length - valid);
             if (n < 0)
             {
                 break;
             }
             valid += n;
         }
         if (valid < buf.Length)
         {
             byte[] nb = new byte[valid];
             System.Array.Copy(buf, 0, nb, 0, valid);
             buf = nb;
         }
         return buf;
     }
     finally
     {
         try
         {
             @in.Close();
         }
         catch (IOException)
         {
         }
     }
 }
开发者ID:kenji-tan,项目名称:ngit,代码行数:67,代码来源:IOUtil.cs


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