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


C# FilePath.CanRead方法代码示例

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


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

示例1: StoreBlob

 public bool StoreBlob(byte[] data, BlobKey outKey)
 {
     BlobKey newKey = KeyForBlob(data);
     outKey.SetBytes(newKey.GetBytes());
     string path = PathForKey(outKey);
     FilePath file = new FilePath(path);
     if (file.CanRead())
     {
         return true;
     }
     FileOutputStream fos = null;
     try
     {
         fos = new FileOutputStream(file);
         fos.Write(data);
     }
     catch (FileNotFoundException e)
     {
         Log.E(Database.Tag, "Error opening file for output", e);
         return false;
     }
     catch (IOException ioe)
     {
         Log.E(Database.Tag, "Error writing to file", ioe);
         return false;
     }
     finally
     {
         if (fos != null)
         {
             try
             {
                 fos.Close();
             }
             catch (IOException)
             {
             }
         }
     }
     // ignore
     return true;
 }
开发者ID:FireflyLogic,项目名称:couchbase-lite-net,代码行数:42,代码来源:BlobStore.cs

示例2: IsGZipped

 public bool IsGZipped(BlobKey key)
 {
     var magic = 0;
     var path = PathForKey(key);
     var file = new FilePath(path);
     if (file.CanRead())
     {
         try
         {
             var raf = new RandomAccessFile(file, "r");
             magic = raf.Read() & unchecked((0xff)) | ((raf.Read() << 8) & unchecked((0xff00)));
             raf.Close();
         }
         catch (Exception e)
         {
             Runtime.PrintStackTrace(e, Console.Error);
         }
     }
     return magic == GZIPInputStream.GzipMagic;
 }
开发者ID:FireflyLogic,项目名称:couchbase-lite-net,代码行数:20,代码来源:BlobStore.cs

示例3: BlobStreamForKey

 public Stream BlobStreamForKey(BlobKey key)
 {
     var path = PathForKey(key);
     Log.D(Database.Tag, "Blob Path : " + path);
     var file = new FilePath(path);
     if (file.CanRead())
     {
         try
         {
             return new FileStream(file, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
         }
         catch (FileNotFoundException e)
         {
             Log.E(Database.Tag, "Unexpected file not found in blob store", e);
             return null;
         }
         catch (Exception e)
         {
             Log.E(Database.Tag, "Cannot new FileStream", e);
         }
     }
     return null;
 }
开发者ID:FireflyLogic,项目名称:couchbase-lite-net,代码行数:23,代码来源:BlobStore.cs

示例4: StoreBlobStream

        public bool StoreBlobStream(Stream inputStream, out BlobKey outKey)
        {
            FilePath tmp = null;
            try
            {
                tmp = FilePath.CreateTempFile(TmpFilePrefix, TmpFileExtension, new FilePath(this.path));
                FileOutputStream fos = new FileOutputStream(tmp);
                byte[] buffer = new byte[65536];
                int lenRead = ((InputStream)inputStream).Read(buffer);
                while (lenRead > 0)
                {
                    fos.Write(buffer, 0, lenRead);
                    lenRead = ((InputStream)inputStream).Read(buffer);
                }
                inputStream.Close();
                fos.Close();
            }
            catch (IOException e)
            {
                Log.E(Database.Tag, "Error writing blog to tmp file", e);
                outKey = null;
                return false;
            }

            outKey = KeyForBlobFromFile(tmp);
            var keyPath = PathForKey(outKey);
            var file = new FilePath(keyPath);
            if (file.CanRead())
            {
                // object with this hash already exists, we should delete tmp file and return true
                tmp.Delete();
            }
            else
            {
                // does not exist, we should rename tmp file to this name
                tmp.RenameTo(file);
            }

            return true;
        }
开发者ID:FireflyLogic,项目名称:couchbase-lite-net,代码行数:40,代码来源:BlobStore.cs

示例5: IsGZipped

 public virtual bool IsGZipped(BlobKey key)
 {
     int magic = 0;
     string path = PathForKey(key);
     FilePath file = new FilePath(path);
     if (file.CanRead())
     {
         try
         {
             RandomAccessFile raf = new RandomAccessFile(file, "r");
             magic = raf.Read() & unchecked((int)(0xff)) | ((raf.Read() << 8) & unchecked((int
                 )(0xff00)));
             raf.Close();
         }
         catch (Exception e)
         {
             Sharpen.Runtime.PrintStackTrace(e, System.Console.Error);
         }
     }
     return magic == GZIPInputStream.GzipMagic;
 }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:21,代码来源:BlobStore.cs

示例6: BlobStreamForKey

 public virtual InputStream BlobStreamForKey(BlobKey key)
 {
     string path = PathForKey(key);
     FilePath file = new FilePath(path);
     if (file.CanRead())
     {
         try
         {
             return new FileInputStream(file);
         }
         catch (FileNotFoundException e)
         {
             Log.E(Log.TagBlobStore, "Unexpected file not found in blob store", e);
             return null;
         }
     }
     return null;
 }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:18,代码来源:BlobStore.cs

示例7: IsGZipped

        public bool IsGZipped(BlobKey key)
        {
            var magic = 0;
            var path = PathForKey(key);
            var file = new FilePath(path);
            if (file.CanRead()) {
                try {
                    var raf = new FileStream (file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                    magic = raf.ReadByte() & unchecked((0xff)) | ((raf.ReadByte() << 8) & unchecked((0xff00)));
                    raf.Close();
                }
                catch (Exception e) {
                    Runtime.PrintStackTrace(e, Console.Error);
                }
            }

            return magic == 0;
        }
开发者ID:ertrupti9,项目名称:couchbase-lite-net,代码行数:18,代码来源:BlobStore.cs

示例8: ReadUrl

		/// <exception cref="System.IO.IOException"></exception>
		private static string ReadUrl(string filePath, string charCoding, bool urlIsFile)
		{
			int chunkLength;
			Stream @is = null;
			try
			{
				if (!urlIsFile)
				{
					Uri urlObj = new Uri(filePath);
					URLConnection uc = urlObj.OpenConnection();
					@is = uc.GetInputStream();
					chunkLength = uc.GetContentLength();
					if (chunkLength <= 0)
					{
						chunkLength = 1024;
					}
					if (charCoding == null)
					{
						string type = uc.GetContentType();
						if (type != null)
						{
							charCoding = GetCharCodingFromType(type);
						}
					}
				}
				else
				{
					FilePath f = new FilePath(filePath);
					if (!f.Exists())
					{
						throw new FileNotFoundException("File not found: " + filePath);
					}
					else
					{
						if (!f.CanRead())
						{
							throw new IOException("Cannot read file: " + filePath);
						}
					}
					long length = f.Length();
					chunkLength = (int)length;
					if (chunkLength != length)
					{
						throw new IOException("Too big file size: " + length);
					}
					if (chunkLength == 0)
					{
						return string.Empty;
					}
					@is = new FileInputStream(f);
				}
				TextReader r;
				if (charCoding == null)
				{
					r = new StreamReader(@is);
				}
				else
				{
					r = new StreamReader(@is, charCoding);
				}
				return ReadReader(r, chunkLength);
			}
			finally
			{
				if (@is != null)
				{
					@is.Close();
				}
			}
		}
开发者ID:hazzik,项目名称:Rhino.Net,代码行数:71,代码来源:Global.cs

示例9: BlobStreamForKey

		public Stream BlobStreamForKey(BlobKey key)
		{
			var path = PathForKey(key);
			var file = new FilePath(path);
            if (file.CanRead())
			{
				try
				{
					#if PORTABLE
					return File.OpenStream(file, false);
					#else
                    return new FileStream(file, FileMode.Open);
					#endif
				}
				catch (FileNotFoundException e)
				{
					Log.E(Database.Tag, "Unexpected file not found in blob store", e);
					return null;
				}
			}
			return null;
		}
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:22,代码来源:BlobStore.cs


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