本文整理汇总了C#中System.IO.Compression.GZipStream.ReadByte方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.Compression.GZipStream.ReadByte方法的具体用法?C# System.IO.Compression.GZipStream.ReadByte怎么用?C# System.IO.Compression.GZipStream.ReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Compression.GZipStream
的用法示例。
在下文中一共展示了System.IO.Compression.GZipStream.ReadByte方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: decompress
public static bool decompress(string infile, string outfile)
{
try {
System.IO.StreamWriter sw = new System.IO.StreamWriter(outfile);
System.IO.StreamReader sr = new System.IO.StreamReader(infile);
System.IO.Compression.GZipStream gzs = new System.IO.Compression.GZipStream(sr.BaseStream, System.IO.Compression.CompressionMode.Decompress);
int lbyte = gzs.ReadByte();
while (lbyte != -1) {
sw.BaseStream.WriteByte((byte) lbyte);
lbyte = gzs.ReadByte();
}
gzs.Close();
gzs.Dispose();
sw.Close();
sw.Dispose();
} catch (System.Exception ex) {
lerror = ex.Message;
return false;
}
return true;
}
示例2: DfsPut
//.........这里部分代码省略.........
}
Console.WriteLine("dfs://{0} successfully written", dfspath);
}
else
{
for (int i = 0; i < dc.Files.Count; i++)
{
if (0 == string.Compare(dc.Files[i].Name, dfspath, true))
{
Console.Error.WriteLine("Error: The specified file already exists in DFS: {0}", dfspath);
SetFailure();
return;
}
}
long sampledist = dc.DataNodeBaseSize / dc.DataNodeSamples;
using (System.IO.FileStream _fs = new System.IO.FileStream(localpath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
{
//const int MAX_SIZE_PER_RECEIVE = 0x400 * 64;
//byte[] fbuf = new byte[MAX_SIZE_PER_RECEIVE];
byte[] fbuf = new byte[maxLineSize];
int[] lbuf = new int[3];
short lbufCount = 0;
System.IO.Stream fs = _fs;
if (localpath.EndsWith(".gz", StringComparison.OrdinalIgnoreCase))
{
fs = new System.IO.Compression.GZipStream(_fs, System.IO.Compression.CompressionMode.Decompress);
if (RecordLength < 1)
{
lbuf[2] = fs.ReadByte();
lbuf[1] = fs.ReadByte();
lbuf[0] = fs.ReadByte();
if (!(lbuf[2] == 0xEF && lbuf[1] == 0xBB && lbuf[0] == 0xBF))
{
lbufCount = 3;
}
}
}
else
{
if (RecordLength < 1)
{
//remove BOM
fs.Read(fbuf, 0, 3);
if (!(fbuf[0] == 0xEF && fbuf[1] == 0xBB && fbuf[2] == 0xBF))
{
fs.Position = 0;
}
}
}
string[] slaves = dc.Slaves.SlaveList.Split(',', ';');
if (null == dc.Slaves.SlaveList || dc.Slaves.SlaveList.Length == 0 || slaves.Length < 1)
{
Console.Error.WriteLine("SlaveList expected in configuration (no machines)");
SetFailure();
return;
}
if (dc.Replication > 1)
{
示例3: UpdateNetwork
public void UpdateNetwork(GameTime gameTime)
{
// Update the server with our status.
timeSinceLastUpdate += gameTime.ElapsedGameTime.TotalSeconds;
if (timeSinceLastUpdate > 0.05)
{
timeSinceLastUpdate = 0;
if (CurrentStateType == "Infiniminer.States.MainGameState")
propertyBag.SendPlayerUpdate();
}
// Recieve messages from the server.
NetMessageType msgType;
while (propertyBag.netClient.ReadMessage(msgBuffer, out msgType))
{
switch (msgType)
{
case NetMessageType.StatusChanged:
{
if (propertyBag.netClient.Status == NetConnectionStatus.Disconnected)
ChangeState("Infiniminer.States.ServerBrowserState");
}
break;
case NetMessageType.ConnectionApproval:
anyPacketsReceived = true;
break;
case NetMessageType.ConnectionRejected:
{
anyPacketsReceived = false;
try
{
string[] reason = msgBuffer.ReadString().Split(";".ToCharArray());
if (reason.Length < 2 || reason[0] == "VER")
System.Windows.Forms.MessageBox.Show("Error: client/server version incompability!\r\nServer: " + msgBuffer.ReadString() + "\r\nClient: " + Defines.INFINIMINER_VERSION);
else
System.Windows.Forms.MessageBox.Show("Error: you are banned from this server!");
}
catch { }
ChangeState("Infiniminer.States.ServerBrowserState");
}
break;
case NetMessageType.Data:
{
try
{
InfiniminerMessage dataType = (InfiniminerMessage)msgBuffer.ReadByte();
switch (dataType)
{
case InfiniminerMessage.BlockBulkTransfer:
{
anyPacketsReceived = true;
try
{
//This is either the compression flag or the x coordiante
byte isCompressed = msgBuffer.ReadByte();
byte x;
byte y;
//255 was used because it exceeds the map size - of course, bytes won't work anyway if map sizes are allowed to be this big, so this method is a non-issue
if (isCompressed == 255)
{
var compressed = msgBuffer.ReadBytes(msgBuffer.LengthBytes - msgBuffer.Position / 8);
var compressedstream = new System.IO.MemoryStream(compressed);
var decompresser = new System.IO.Compression.GZipStream(compressedstream, System.IO.Compression.CompressionMode.Decompress);
x = (byte)decompresser.ReadByte();
y = (byte)decompresser.ReadByte();
propertyBag.mapLoadProgress[x, y] = true;
for (byte dy = 0; dy < 16; dy++)
for (byte z = 0; z < 64; z++)
{
BlockType blockType = (BlockType)decompresser.ReadByte();
if (blockType != BlockType.None)
propertyBag.blockEngine.downloadList[x, y + dy, z] = blockType;
}
}
else
{
x = isCompressed;
y = msgBuffer.ReadByte();
propertyBag.mapLoadProgress[x, y] = true;
for (byte dy = 0; dy < 16; dy++)
for (byte z = 0; z < 64; z++)
{
BlockType blockType = (BlockType)msgBuffer.ReadByte();
if (blockType != BlockType.None)
propertyBag.blockEngine.downloadList[x, y + dy, z] = blockType;
}
}
bool downloadComplete = true;
for (x = 0; x < 64; x++)
for (y = 0; y < 64; y += 16)
if (propertyBag.mapLoadProgress[x, y] == false)
{
downloadComplete = false;
break;
}
if (downloadComplete)
//.........这里部分代码省略.........
示例4: Decompress
/// <summary>
/// UNCompress a byte[] using GZipStream
///
/// Taken from: http://atakala.com/browser/Item.aspx?user_id=amos&dict_id=1980
/// </summary>
/// <param name="input">byte[] to be uncompressed</param>
/// <returns>Uncompressed representation of input</returns>
public static byte[] Decompress(byte[] input)
{
System.Collections.Generic.List<byte> output = new List<byte>();
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(input))
{
using (System.IO.Compression.GZipStream gs = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Decompress))
{
int readByte = gs.ReadByte();
while (readByte != -1)
{
output.Add((byte)readByte);
readByte = gs.ReadByte();
}
gs.Close();
}
ms.Close();
}
return output.ToArray();
}
示例5: UpdateNetwork
public void UpdateNetwork(GameTime gameTime)
{
// Update the server with our status.
timeSinceLastUpdate += gameTime.ElapsedGameTime.TotalSeconds;
if (timeSinceLastUpdate > NETWORK_UPDATE_TIME)
{
timeSinceLastUpdate = 0;
if (CurrentStateType == "Infiniminer.States.MainGameState")
{
propertyBag.SendPlayerUpdate();
}
}
// Recieve messages from the server.
NetMessageType msgType;
while (propertyBag.netClient.ReadMessage(msgBuffer, out msgType))
{
switch (msgType)
{
case NetMessageType.StatusChanged:
{
if (propertyBag.netClient.Status == NetConnectionStatus.Disconnected)
{
ChangeState("Infiniminer.States.ServerBrowserState");//needed to reset
Thread.Sleep(50);
JoinGame(lastConnection);//attempts to reconnect
ChangeState("Infiniminer.States.LoadingState");
}
}
break;
case NetMessageType.ConnectionApproval:
anyPacketsReceived = true;
break;
case NetMessageType.ConnectionRejected:
{
anyPacketsReceived = false;
try
{
string[] reason = msgBuffer.ReadString().Split(";".ToCharArray());
if (reason.Length < 2 || reason[0] == "VER")
System.Windows.Forms.MessageBox.Show("Error: client/server version incompability!\r\nServer: " + msgBuffer.ReadString() + "\r\nClient: " + Defines.INFINIMINER_VERSION);
else
System.Windows.Forms.MessageBox.Show("Error: you are banned from this server!");
}
catch { }
ChangeState("Infiniminer.States.ServerBrowserState");
}
break;
case NetMessageType.Data:
{
try
{
InfiniminerMessage dataType = (InfiniminerMessage)msgBuffer.ReadByte();
switch (dataType)
{
case InfiniminerMessage.BlockBulkTransfer:
{
anyPacketsReceived = true;
try
{
//This is either the compression flag or the x coordiante
byte isCompressed = msgBuffer.ReadByte();
byte x;
byte y;
//255 was used because it exceeds the map size - of course, bytes won't work anyway if map sizes are allowed to be this big, so this method is a non-issue
if (isCompressed == 255)
{
var compressed = msgBuffer.ReadBytes(msgBuffer.LengthBytes - msgBuffer.Position / 8);
var compressedstream = new System.IO.MemoryStream(compressed);
var decompresser = new System.IO.Compression.GZipStream(compressedstream, System.IO.Compression.CompressionMode.Decompress);
x = (byte)decompresser.ReadByte();
y = (byte)decompresser.ReadByte();
propertyBag.mapLoadProgress[x, y] = true;
for (byte dy = 0; dy < 16; dy++)
for (byte z = 0; z < 64; z++)
{
BlockType blockType = (BlockType)decompresser.ReadByte();
if (blockType != BlockType.None)
propertyBag.blockEngine.downloadList[x, y + dy, z] = blockType;
}
}
else
{
x = isCompressed;
y = msgBuffer.ReadByte();
propertyBag.mapLoadProgress[x, y] = true;
for (byte dy = 0; dy < 16; dy++)
for (byte z = 0; z < 64; z++)
{
BlockType blockType = (BlockType)msgBuffer.ReadByte();
if (blockType != BlockType.None)
propertyBag.blockEngine.downloadList[x, y + dy, z] = blockType;
}
}
bool downloadComplete = true;
//.........这里部分代码省略.........