本文整理匯總了C#中Block.Read方法的典型用法代碼示例。如果您正苦於以下問題:C# Block.Read方法的具體用法?C# Block.Read怎麽用?C# Block.Read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Block
的用法示例。
在下文中一共展示了Block.Read方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
static void Main(string[] args)
{
InitComplements();
var seq = new List<byte[]>();
var b = new Block { Count = -1 };
Index line = Index.None, start = Index.None, end = Index.None;
using (var r = new BinaryReader(Console.OpenStandardInput())) {
using (var w = Console.OpenStandardOutput()) {
while (b.Read(r) > 0) {
seq.Add(b.Data);
if (line.Pos < 0) line = b.IndexOf(Gt, 0);
while (line.Pos >= 0) {
if (start.Pos < 0) {
var off = line.InBlock(b) ? line.Pos : 0;
start = b.IndexOf(Lf, off);
if (start.Pos < 0) {
w.Write(b.Data, off, b.Data.Length - off);
seq.Clear(); break;
}
w.Write(b.Data, off, start.Pos + 1 - off);
}
if (end.Pos < 0) {
end = b.IndexOf(Gt, start.InBlock(b) ? start.Pos : 0);
if (end.Pos < 0) break;
}
w.Reverse(start.Pos, end.Pos, seq);
if (seq.Count > 1) seq.RemoveRange(0, seq.Count - 1);
line = end; end = Index.None; start = Index.None;
}
}
if (start.Pos >= 0 && end.Pos < 0)
w.Reverse(start.Pos, seq[seq.Count -1].Length, seq);
}
}
}
示例2: PrepareBlockAtPosition
/// <summary>
/// 查找指定偏移所在的塊,若塊不存在則創建
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public Block PrepareBlockAtPosition(UInt32 position)
{
UInt32 blockSize = vfs.GetSuperBlock().data.blockSize;
UInt32 IndexPerBlock = blockSize / sizeof(UInt32);
// 直接索引
if (position < BoundLv0)
{
UInt32 totalBlocks = 0;
UInt32 lv0_index = position / blockSize;
totalBlocks += lv0_index + 1;
UInt32 preserve = GetBlocksToPreserve(totalBlocks);
//Console.WriteLine("preserve block: {0} (+{1})", totalBlocks, preserve);
if (preserve > 0)
{
vfs.PreserveBlock(preserve);
data.blockPreserved += preserve;
//Console.WriteLine("data.blockPreserved = {0}", data.blockPreserved);
Save();
}
Block lv0_block = new Block(vfs, data.dataBlockId[lv0_index]);
if (lv0_block.index == UInt32.MaxValue)
{
lv0_block = vfs.AllocateBlock();
data.dataBlockId[lv0_index] = lv0_block.index;
Save();
}
return lv0_block;
}
else if (position < BoundLv1)
{
// 一級間接索引
position -= BoundLv0;
UInt32 totalBlocks = 0;
UInt32 lv0_index = 12;
UInt32 lv1_index = position / blockSize;
totalBlocks += lv0_index + 1;
totalBlocks += lv1_index + 1;
UInt32 preserve = GetBlocksToPreserve(totalBlocks);
//Console.WriteLine("preserve block: {0} (+{1})", totalBlocks, preserve);
if (preserve > 0)
{
vfs.PreserveBlock(preserve);
data.blockPreserved += preserve;
//Console.WriteLine("data.blockPreserved = {0}", data.blockPreserved);
Save();
}
Block lv0_block = new Block(vfs, data.dataBlockId[lv0_index]);
if (lv0_block.index == UInt32.MaxValue)
{
lv0_block = vfs.AllocateBlock(0xFF);
data.dataBlockId[lv0_index] = lv0_block.index;
Save();
}
Block lv1_block = new Block(vfs, lv0_block.Read<UInt32>(lv1_index * sizeof(UInt32)));
if (lv1_block.index == UInt32.MaxValue)
{
lv1_block = vfs.AllocateBlock();
lv0_block.Write(lv1_index * sizeof(UInt32), lv1_block.index);
}
return lv1_block;
}
else
{
// 二級間接索引
position -= BoundLv1;
UInt32 totalBlocks = 0;
UInt32 lv0_index = 13;
UInt32 lv1_index = (position / blockSize) / IndexPerBlock;
UInt32 lv2_index = (position / blockSize) % IndexPerBlock;
//Console.WriteLine("position = {0}, lv0_index = {1}, lv1_index = {2}, lv2_index = {3}", position, lv0_index, lv1_index, lv2_index);
totalBlocks += lv0_index + 1;
totalBlocks += IndexPerBlock + 1;
totalBlocks += (IndexPerBlock + 1) * lv1_index;
totalBlocks += lv2_index + 1;
UInt32 preserve = GetBlocksToPreserve(totalBlocks);
//Console.WriteLine("preserve block: {0} (+{1})", totalBlocks, preserve);
if (preserve > 0)
{
vfs.PreserveBlock(preserve);
data.blockPreserved += preserve;
//.........這裏部分代碼省略.........
示例3: GetBlockAtPosition
/// <summary>
/// 查找指定偏移所在的塊,若塊不存在則返回無效塊
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public Block GetBlockAtPosition(UInt32 position, Boolean allocate = false)
{
UInt32 blockSize = vfs.GetSuperBlock().data.blockSize;
UInt32 IndexPerBlock = blockSize / sizeof(UInt32);
if (position < BoundLv0)
{
// 直接索引
UInt32 lv0_index = position / blockSize;
return new Block(vfs, data.dataBlockId[lv0_index]);
}
else if (position < BoundLv1)
{
// 一級間接索引
position -= BoundLv0;
UInt32 lv0_index = 12;
UInt32 lv1_index = position / blockSize;
Block lv0_block = new Block(vfs, data.dataBlockId[lv0_index]);
if (lv0_block.index == UInt32.MaxValue)
{
return lv0_block;
}
return new Block(vfs, lv0_block.Read<UInt32>(lv1_index * sizeof(UInt32)));
}
else
{
// 二級間接索引
position -= BoundLv1;
UInt32 lv0_index = 13;
UInt32 lv1_index = (position / blockSize) / IndexPerBlock;
UInt32 lv2_index = (position / blockSize) % IndexPerBlock;
Block lv0_block = new Block(vfs, data.dataBlockId[lv0_index]);
if (lv0_block.index == UInt32.MaxValue)
{
return lv0_block;
}
Block lv1_block = new Block(vfs, lv0_block.Read<UInt32>(lv1_index * sizeof(UInt32)));
if (lv1_block.index == UInt32.MaxValue)
{
return lv1_block;
}
return new Block(vfs, lv1_block.Read<UInt32>(lv2_index * sizeof(UInt32)));
}
}