本文整理汇总了C#中Couchbase.Lite.BlobKey.SetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# BlobKey.SetBytes方法的具体用法?C# BlobKey.SetBytes怎么用?C# BlobKey.SetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Couchbase.Lite.BlobKey
的用法示例。
在下文中一共展示了BlobKey.SetBytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetKeyForFilename
public bool GetKeyForFilename(BlobKey outKey, string filename)
{
if (!filename.EndsWith(FileExtension))
{
return false;
}
//trim off extension
string rest = Sharpen.Runtime.Substring(filename, path.Length + 1, filename.Length
- FileExtension.Length);
outKey.SetBytes(BlobKey.ConvertFromHex(rest));
return true;
}
示例2: 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;
}
示例3: StoreBlobStream
public virtual bool StoreBlobStream(InputStream inputStream, BlobKey outKey)
{
FilePath tmp = null;
try
{
tmp = FilePath.CreateTempFile(TmpFilePrefix, TmpFileExtension, new FilePath(path)
);
FileOutputStream fos = new FileOutputStream(tmp);
byte[] buffer = new byte[65536];
int lenRead = inputStream.Read(buffer);
while (lenRead > 0)
{
fos.Write(buffer, 0, lenRead);
lenRead = inputStream.Read(buffer);
}
inputStream.Close();
fos.Close();
}
catch (IOException e)
{
Log.E(Log.TagBlobStore, "Error writing blog to tmp file", e);
return false;
}
BlobKey newKey = KeyForBlobFromFile(tmp);
outKey.SetBytes(newKey.GetBytes());
string path = PathForKey(outKey);
FilePath file = new FilePath(path);
if (file.CanRead())
{
// object with this hash already exists, we should delete tmp file and return true
tmp.Delete();
return true;
}
else
{
// does not exist, we should rename tmp file to this name
tmp.RenameTo(file);
}
return true;
}