mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-16 20:50:48 +01:00
update sharpcifs
This commit is contained in:
@@ -19,96 +19,92 @@ using System.Text;
|
||||
|
||||
namespace SharpCifs.Util
|
||||
{
|
||||
public class Base64
|
||||
{
|
||||
private static readonly string Alphabet
|
||||
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
public class Base64
|
||||
{
|
||||
private static readonly string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
/// <summary>Base-64 encodes the supplied block of data.</summary>
|
||||
/// <remarks>
|
||||
/// Base-64 encodes the supplied block of data. Line wrapping is not
|
||||
/// applied on output.
|
||||
/// </remarks>
|
||||
/// <param name="bytes">The block of data that is to be Base-64 encoded.</param>
|
||||
/// <returns>A <code>String</code> containing the encoded data.</returns>
|
||||
public static string Encode(byte[] bytes)
|
||||
{
|
||||
int length = bytes.Length;
|
||||
if (length == 0)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
StringBuilder buffer = new StringBuilder((int)Math.Ceiling(length / 3d) * 4);
|
||||
int remainder = length % 3;
|
||||
length -= remainder;
|
||||
int block;
|
||||
int i = 0;
|
||||
while (i < length)
|
||||
{
|
||||
block = ((bytes[i++] & unchecked(0xff)) << 16) | ((bytes[i++] & unchecked(
|
||||
0xff)) << 8) | (bytes[i++] & unchecked(0xff));
|
||||
buffer.Append(Alphabet[(int)(((uint)block) >> 18)]);
|
||||
buffer.Append(Alphabet[((int)(((uint)block) >> 12)) & unchecked(0x3f)]);
|
||||
buffer.Append(Alphabet[((int)(((uint)block) >> 6)) & unchecked(0x3f)]);
|
||||
buffer.Append(Alphabet[block & unchecked(0x3f)]);
|
||||
}
|
||||
if (remainder == 0)
|
||||
{
|
||||
return buffer.ToString();
|
||||
}
|
||||
if (remainder == 1)
|
||||
{
|
||||
block = (bytes[i] & unchecked(0xff)) << 4;
|
||||
buffer.Append(Alphabet[(int)(((uint)block) >> 6)]);
|
||||
buffer.Append(Alphabet[block & unchecked(0x3f)]);
|
||||
buffer.Append("==");
|
||||
return buffer.ToString();
|
||||
}
|
||||
block = (((bytes[i++] & unchecked(0xff)) << 8) | ((bytes[i]) & unchecked(0xff))) << 2;
|
||||
buffer.Append(Alphabet[(int)(((uint)block) >> 12)]);
|
||||
buffer.Append(Alphabet[((int)(((uint)block) >> 6)) & unchecked(0x3f)]);
|
||||
buffer.Append(Alphabet[block & unchecked(0x3f)]);
|
||||
buffer.Append("=");
|
||||
return buffer.ToString();
|
||||
}
|
||||
/// <summary>Base-64 encodes the supplied block of data.</summary>
|
||||
/// <remarks>
|
||||
/// Base-64 encodes the supplied block of data. Line wrapping is not
|
||||
/// applied on output.
|
||||
/// </remarks>
|
||||
/// <param name="bytes">The block of data that is to be Base-64 encoded.</param>
|
||||
/// <returns>A <code>String</code> containing the encoded data.</returns>
|
||||
public static string Encode(byte[] bytes)
|
||||
{
|
||||
int length = bytes.Length;
|
||||
if (length == 0)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
StringBuilder buffer = new StringBuilder((int)Math.Ceiling(length / 3d) * 4);
|
||||
int remainder = length % 3;
|
||||
length -= remainder;
|
||||
int block;
|
||||
int i = 0;
|
||||
while (i < length)
|
||||
{
|
||||
block = ((bytes[i++] & unchecked(0xff)) << 16) | ((bytes[i++] & unchecked(
|
||||
0xff)) << 8) | (bytes[i++] & unchecked(0xff));
|
||||
buffer.Append(Alphabet[(int)(((uint)block) >> 18)]);
|
||||
buffer.Append(Alphabet[((int)(((uint)block) >> 12)) & unchecked(0x3f)]);
|
||||
buffer.Append(Alphabet[((int)(((uint)block) >> 6)) & unchecked(0x3f)]);
|
||||
buffer.Append(Alphabet[block & unchecked(0x3f)]);
|
||||
}
|
||||
if (remainder == 0)
|
||||
{
|
||||
return buffer.ToString();
|
||||
}
|
||||
if (remainder == 1)
|
||||
{
|
||||
block = (bytes[i] & unchecked(0xff)) << 4;
|
||||
buffer.Append(Alphabet[(int)(((uint)block) >> 6)]);
|
||||
buffer.Append(Alphabet[block & unchecked(0x3f)]);
|
||||
buffer.Append("==");
|
||||
return buffer.ToString();
|
||||
}
|
||||
block = (((bytes[i++] & unchecked(0xff)) << 8) | ((bytes[i]) & unchecked(0xff))) << 2;
|
||||
buffer.Append(Alphabet[(int)(((uint)block) >> 12)]);
|
||||
buffer.Append(Alphabet[((int)(((uint)block) >> 6)) & unchecked(0x3f)]);
|
||||
buffer.Append(Alphabet[block & unchecked(0x3f)]);
|
||||
buffer.Append("=");
|
||||
return buffer.ToString();
|
||||
}
|
||||
|
||||
/// <summary>Decodes the supplied Base-64 encoded string.</summary>
|
||||
/// <remarks>Decodes the supplied Base-64 encoded string.</remarks>
|
||||
/// <param name="string">The Base-64 encoded string that is to be decoded.</param>
|
||||
/// <returns>A <code>byte[]</code> containing the decoded data block.</returns>
|
||||
public static byte[] Decode(string @string)
|
||||
{
|
||||
int length = @string.Length;
|
||||
if (length == 0)
|
||||
{
|
||||
return new byte[0];
|
||||
}
|
||||
int pad = (@string[length - 2] == '=') ? 2 : (@string[length - 1] == '=') ? 1 : 0;
|
||||
int size = length * 3 / 4 - pad;
|
||||
byte[] buffer = new byte[size];
|
||||
int block;
|
||||
int i = 0;
|
||||
int index = 0;
|
||||
while (i < length)
|
||||
{
|
||||
block = (Alphabet.IndexOf(@string[i++]) & unchecked(0xff)) << 18
|
||||
| (Alphabet.IndexOf(@string[i++]) & unchecked(0xff)) << 12
|
||||
| (Alphabet.IndexOf(@string[i++]) & unchecked(0xff)) << 6
|
||||
| (Alphabet.IndexOf(@string[i++]) & unchecked(0xff));
|
||||
buffer[index++] = unchecked((byte)((int)(((uint)block) >> 16)));
|
||||
if (index < size)
|
||||
{
|
||||
buffer[index++] = unchecked(
|
||||
(byte)(
|
||||
((int)(((uint)block) >> 8)) & unchecked(0xff))
|
||||
);
|
||||
}
|
||||
if (index < size)
|
||||
{
|
||||
buffer[index++] = unchecked((byte)(block & unchecked(0xff)));
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
/// <summary>Decodes the supplied Base-64 encoded string.</summary>
|
||||
/// <remarks>Decodes the supplied Base-64 encoded string.</remarks>
|
||||
/// <param name="string">The Base-64 encoded string that is to be decoded.</param>
|
||||
/// <returns>A <code>byte[]</code> containing the decoded data block.</returns>
|
||||
public static byte[] Decode(string @string)
|
||||
{
|
||||
int length = @string.Length;
|
||||
if (length == 0)
|
||||
{
|
||||
return new byte[0];
|
||||
}
|
||||
int pad = (@string[length - 2] == '=') ? 2 : (@string[length - 1] == '=') ? 1 : 0;
|
||||
int size = length * 3 / 4 - pad;
|
||||
byte[] buffer = new byte[size];
|
||||
int block;
|
||||
int i = 0;
|
||||
int index = 0;
|
||||
while (i < length)
|
||||
{
|
||||
block = (Alphabet.IndexOf(@string[i++]) & unchecked(0xff)) << 18 | (Alphabet
|
||||
.IndexOf(@string[i++]) & unchecked(0xff)) << 12 | (Alphabet.IndexOf(@string
|
||||
[i++]) & unchecked(0xff)) << 6 | (Alphabet.IndexOf(@string[i++]) & unchecked(
|
||||
0xff));
|
||||
buffer[index++] = unchecked((byte)((int)(((uint)block) >> 16)));
|
||||
if (index < size)
|
||||
{
|
||||
buffer[index++] = unchecked((byte)(((int)(((uint)block) >> 8)) & unchecked(0xff)));
|
||||
}
|
||||
if (index < size)
|
||||
{
|
||||
buffer[index++] = unchecked((byte)(block & unchecked(0xff)));
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,118 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace SharpCifs.Util.DbsHelper
|
||||
{
|
||||
public class Log
|
||||
{
|
||||
/// <summary>
|
||||
/// コンソールへのログ出力を行うか否か
|
||||
/// </summary>
|
||||
public static bool IsActive { get; set; } = false;
|
||||
|
||||
public static void Out(string message)
|
||||
{
|
||||
if (!Log.IsActive
|
||||
|| string.IsNullOrEmpty(message))
|
||||
return;
|
||||
|
||||
var msg = DateTime.Now.ToString("HH:mm:ss.fff")
|
||||
+ ": [ThID: "
|
||||
+ System.Environment.CurrentManagedThreadId.ToString().PadLeft(3)
|
||||
+ " "
|
||||
+ message;
|
||||
|
||||
Debug.WriteLine(msg);
|
||||
Console.WriteLine(msg);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 例外のログ出力を行う。
|
||||
/// </summary>
|
||||
/// <param name="ex"></param>
|
||||
public static void Out(Exception ex)
|
||||
{
|
||||
if (!Log.IsActive
|
||||
|| ex == null)
|
||||
return;
|
||||
|
||||
Log.Out($"{ex}");
|
||||
var message = Log.GetHighlighted(Log.GetErrorString(ex));
|
||||
Log.Out(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cast string-arrary to Highlighted message
|
||||
/// 文字列配列を強調メッセージ形式文字列に変換する。
|
||||
/// </summary>
|
||||
/// <param name="messages"></param>
|
||||
/// <returns></returns>
|
||||
private static string GetHighlighted(params System.String[] messages)
|
||||
{
|
||||
var time = DateTime.Now;
|
||||
var list = new List<string>();
|
||||
|
||||
list.Add("");
|
||||
list.Add("");
|
||||
list.Add(time.ToString("HH:mm:ss.fff") + ":");
|
||||
list.Add("##################################################");
|
||||
list.Add("#");
|
||||
|
||||
foreach (string message in messages)
|
||||
{
|
||||
var lines = message.Replace("\r\n", "\n").Replace("\r", "\n").Trim('\n').Split('\n');
|
||||
foreach (var line in lines)
|
||||
{
|
||||
list.Add($"# {line}");
|
||||
}
|
||||
}
|
||||
|
||||
list.Add("#");
|
||||
list.Add("##################################################");
|
||||
list.Add("");
|
||||
list.Add("");
|
||||
|
||||
return string.Join("\r\n", list);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Formatted Exception-Info string-array
|
||||
/// 例外情報を整形した文字列配列を返す。
|
||||
/// </summary>
|
||||
/// <param name="ex"></param>
|
||||
/// <returns></returns>
|
||||
private static string[] GetErrorString(Exception ex)
|
||||
{
|
||||
var list = new List<string>();
|
||||
|
||||
if (ex.Message != null)
|
||||
{
|
||||
list.Add(ex.Message ?? "");
|
||||
list.Add("");
|
||||
}
|
||||
|
||||
if (ex.StackTrace != null)
|
||||
{
|
||||
list.AddRange(ex.StackTrace.Split(new string[] { "場所", "at " },
|
||||
StringSplitOptions.None)
|
||||
.AsEnumerable()
|
||||
.Select(row => "\r\nat " + row));
|
||||
}
|
||||
|
||||
if (ex.InnerException != null)
|
||||
{
|
||||
//InnerExceptionを再帰取得する。
|
||||
list.Add("");
|
||||
list.Add("Inner Exception");
|
||||
list.AddRange(Log.GetErrorString(ex.InnerException));
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,398 +20,382 @@ using SharpCifs.Util.Sharpen;
|
||||
|
||||
namespace SharpCifs.Util
|
||||
{
|
||||
public class Encdec
|
||||
{
|
||||
public const long MillisecondsBetween1970And1601 = 11644473600000L;
|
||||
public class Encdec
|
||||
{
|
||||
public const long MillisecondsBetween1970And1601 = 11644473600000L;
|
||||
|
||||
public const long SecBetweeen1904And1970 = 2082844800L;
|
||||
public const long SecBetweeen1904And1970 = 2082844800L;
|
||||
|
||||
public const int Time1970Sec32Be = 1;
|
||||
public const int Time1970Sec32Be = 1;
|
||||
|
||||
public const int Time1970Sec32Le = 2;
|
||||
public const int Time1970Sec32Le = 2;
|
||||
|
||||
public const int Time1904Sec32Be = 3;
|
||||
public const int Time1904Sec32Be = 3;
|
||||
|
||||
public const int Time1904Sec32Le = 4;
|
||||
public const int Time1904Sec32Le = 4;
|
||||
|
||||
public const int Time1601Nanos64Le = 5;
|
||||
public const int Time1601Nanos64Le = 5;
|
||||
|
||||
public const int Time1601Nanos64Be = 6;
|
||||
public const int Time1601Nanos64Be = 6;
|
||||
|
||||
public const int Time1970Millis64Be = 7;
|
||||
public const int Time1970Millis64Be = 7;
|
||||
|
||||
public const int Time1970Millis64Le = 8;
|
||||
public const int Time1970Millis64Le = 8;
|
||||
|
||||
public static int Enc_uint16be(short s, byte[] dst, int di)
|
||||
{
|
||||
dst[di++] = unchecked((byte)((s >> 8) & unchecked(0xFF)));
|
||||
dst[di] = unchecked((byte)(s & unchecked(0xFF)));
|
||||
return 2;
|
||||
}
|
||||
public static int Enc_uint16be(short s, byte[] dst, int di)
|
||||
{
|
||||
dst[di++] = unchecked((byte)((s >> 8) & unchecked(0xFF)));
|
||||
dst[di] = unchecked((byte)(s & unchecked(0xFF)));
|
||||
return 2;
|
||||
}
|
||||
|
||||
public static int Enc_uint32be(int i, byte[] dst, int di)
|
||||
{
|
||||
dst[di++] = unchecked((byte)((i >> 24) & unchecked(0xFF)));
|
||||
dst[di++] = unchecked((byte)((i >> 16) & unchecked(0xFF)));
|
||||
dst[di++] = unchecked((byte)((i >> 8) & unchecked(0xFF)));
|
||||
dst[di] = unchecked((byte)(i & unchecked(0xFF)));
|
||||
return 4;
|
||||
}
|
||||
public static int Enc_uint32be(int i, byte[] dst, int di)
|
||||
{
|
||||
dst[di++] = unchecked((byte)((i >> 24) & unchecked(0xFF)));
|
||||
dst[di++] = unchecked((byte)((i >> 16) & unchecked(0xFF)));
|
||||
dst[di++] = unchecked((byte)((i >> 8) & unchecked(0xFF)));
|
||||
dst[di] = unchecked((byte)(i & unchecked(0xFF)));
|
||||
return 4;
|
||||
}
|
||||
|
||||
public static int Enc_uint16le(short s, byte[] dst, int di)
|
||||
{
|
||||
dst[di++] = unchecked((byte)(s & unchecked(0xFF)));
|
||||
dst[di] = unchecked((byte)((s >> 8) & unchecked(0xFF)));
|
||||
return 2;
|
||||
}
|
||||
public static int Enc_uint16le(short s, byte[] dst, int di)
|
||||
{
|
||||
dst[di++] = unchecked((byte)(s & unchecked(0xFF)));
|
||||
dst[di] = unchecked((byte)((s >> 8) & unchecked(0xFF)));
|
||||
return 2;
|
||||
}
|
||||
|
||||
public static int Enc_uint32le(int i, byte[] dst, int di)
|
||||
{
|
||||
dst[di++] = unchecked((byte)(i & unchecked(0xFF)));
|
||||
dst[di++] = unchecked((byte)((i >> 8) & unchecked(0xFF)));
|
||||
dst[di++] = unchecked((byte)((i >> 16) & unchecked(0xFF)));
|
||||
dst[di] = unchecked((byte)((i >> 24) & unchecked(0xFF)));
|
||||
return 4;
|
||||
}
|
||||
public static int Enc_uint32le(int i, byte[] dst, int di)
|
||||
{
|
||||
dst[di++] = unchecked((byte)(i & unchecked(0xFF)));
|
||||
dst[di++] = unchecked((byte)((i >> 8) & unchecked(0xFF)));
|
||||
dst[di++] = unchecked((byte)((i >> 16) & unchecked(0xFF)));
|
||||
dst[di] = unchecked((byte)((i >> 24) & unchecked(0xFF)));
|
||||
return 4;
|
||||
}
|
||||
|
||||
public static short Dec_uint16be(byte[] src, int si)
|
||||
{
|
||||
return (short)(((src[si] & unchecked(0xFF)) << 8)
|
||||
| (src[si + 1] & unchecked(0xFF)));
|
||||
}
|
||||
public static short Dec_uint16be(byte[] src, int si)
|
||||
{
|
||||
return (short)(((src[si] & unchecked(0xFF)) << 8) | (src[si + 1] & unchecked(
|
||||
0xFF)));
|
||||
}
|
||||
|
||||
public static int Dec_uint32be(byte[] src, int si)
|
||||
{
|
||||
return ((src[si] & unchecked(0xFF)) << 24)
|
||||
| ((src[si + 1] & unchecked(0xFF)) << 16)
|
||||
| ((src[si + 2] & unchecked(0xFF)) << 8)
|
||||
| (src[si + 3] & unchecked(0xFF));
|
||||
}
|
||||
public static int Dec_uint32be(byte[] src, int si)
|
||||
{
|
||||
return ((src[si] & unchecked(0xFF)) << 24) | ((src[si + 1] & unchecked(0xFF)) << 16) | ((src[si + 2] & unchecked(0xFF)) << 8) | (src[si + 3]
|
||||
& unchecked(0xFF));
|
||||
}
|
||||
|
||||
public static short Dec_uint16le(byte[] src, int si)
|
||||
{
|
||||
return (short)((src[si] & unchecked(0xFF))
|
||||
| ((src[si + 1] & unchecked(0xFF)) << 8));
|
||||
}
|
||||
public static short Dec_uint16le(byte[] src, int si)
|
||||
{
|
||||
return (short)((src[si] & unchecked(0xFF)) | ((src[si + 1] & unchecked(0xFF)) << 8));
|
||||
}
|
||||
|
||||
public static int Dec_uint32le(byte[] src, int si)
|
||||
{
|
||||
return (src[si] & unchecked(0xFF))
|
||||
| ((src[si + 1] & unchecked(0xFF)) << 8)
|
||||
| ((src[si + 2] & unchecked(0xFF)) << 16)
|
||||
| ((src[si + 3] & unchecked(0xFF)) << 24);
|
||||
}
|
||||
public static int Dec_uint32le(byte[] src, int si)
|
||||
{
|
||||
return (src[si] & unchecked(0xFF)) | ((src[si + 1] & unchecked(0xFF
|
||||
)) << 8) | ((src[si + 2] & unchecked(0xFF)) << 16) | ((src[si + 3] & unchecked(
|
||||
0xFF)) << 24);
|
||||
}
|
||||
|
||||
public static int Enc_uint64be(long l, byte[] dst, int di)
|
||||
{
|
||||
Enc_uint32be((int)(l & unchecked(0xFFFFFFFFL)), dst, di + 4);
|
||||
Enc_uint32be((int)((l >> 32) & unchecked(0xFFFFFFFFL)), dst, di);
|
||||
return 8;
|
||||
}
|
||||
public static int Enc_uint64be(long l, byte[] dst, int di)
|
||||
{
|
||||
Enc_uint32be((int)(l & unchecked(0xFFFFFFFFL)), dst, di + 4);
|
||||
Enc_uint32be((int)((l >> 32) & unchecked(0xFFFFFFFFL)), dst, di);
|
||||
return 8;
|
||||
}
|
||||
|
||||
public static int Enc_uint64le(long l, byte[] dst, int di)
|
||||
{
|
||||
Enc_uint32le((int)(l & unchecked(0xFFFFFFFFL)), dst, di);
|
||||
Enc_uint32le((int)((l >> 32) & unchecked(0xFFFFFFFFL)), dst, di + 4);
|
||||
return 8;
|
||||
}
|
||||
public static int Enc_uint64le(long l, byte[] dst, int di)
|
||||
{
|
||||
Enc_uint32le((int)(l & unchecked(0xFFFFFFFFL)), dst, di);
|
||||
Enc_uint32le((int)((l >> 32) & unchecked(0xFFFFFFFFL)), dst, di + 4);
|
||||
return 8;
|
||||
}
|
||||
|
||||
public static long Dec_uint64be(byte[] src, int si)
|
||||
{
|
||||
long l;
|
||||
l = Dec_uint32be(src, si) & unchecked(0xFFFFFFFFL);
|
||||
l <<= 32;
|
||||
l |= Dec_uint32be(src, si + 4) & unchecked(0xFFFFFFFFL);
|
||||
return l;
|
||||
}
|
||||
public static long Dec_uint64be(byte[] src, int si)
|
||||
{
|
||||
long l;
|
||||
l = Dec_uint32be(src, si) & unchecked(0xFFFFFFFFL);
|
||||
l <<= 32;
|
||||
l |= Dec_uint32be(src, si + 4) & unchecked(0xFFFFFFFFL);
|
||||
return l;
|
||||
}
|
||||
|
||||
public static long Dec_uint64le(byte[] src, int si)
|
||||
{
|
||||
long l;
|
||||
l = Dec_uint32le(src, si + 4) & unchecked(0xFFFFFFFFL);
|
||||
l <<= 32;
|
||||
l |= Dec_uint32le(src, si) & unchecked(0xFFFFFFFFL);
|
||||
return l;
|
||||
}
|
||||
public static long Dec_uint64le(byte[] src, int si)
|
||||
{
|
||||
long l;
|
||||
l = Dec_uint32le(src, si + 4) & unchecked(0xFFFFFFFFL);
|
||||
l <<= 32;
|
||||
l |= Dec_uint32le(src, si) & unchecked(0xFFFFFFFFL);
|
||||
return l;
|
||||
}
|
||||
|
||||
public static int Enc_floatle(float f, byte[] dst, int di)
|
||||
{
|
||||
return Enc_uint32le((int)BitConverter.DoubleToInt64Bits(f), dst, di);
|
||||
}
|
||||
public static int Enc_floatle(float f, byte[] dst, int di)
|
||||
{
|
||||
return Enc_uint32le((int)BitConverter.DoubleToInt64Bits(f), dst, di);
|
||||
}
|
||||
|
||||
public static int Enc_floatbe(float f, byte[] dst, int di)
|
||||
{
|
||||
public static int Enc_floatbe(float f, byte[] dst, int di)
|
||||
{
|
||||
return Enc_uint32be((int)BitConverter.DoubleToInt64Bits(f), dst, di);
|
||||
}
|
||||
}
|
||||
|
||||
public static float Dec_floatle(byte[] src, int si)
|
||||
{
|
||||
return (float)BitConverter.Int64BitsToDouble(Dec_uint32le(src, si));
|
||||
}
|
||||
public static float Dec_floatle(byte[] src, int si)
|
||||
{
|
||||
return (float)BitConverter.Int64BitsToDouble(Dec_uint32le(src, si));
|
||||
}
|
||||
|
||||
public static float Dec_floatbe(byte[] src, int si)
|
||||
{
|
||||
public static float Dec_floatbe(byte[] src, int si)
|
||||
{
|
||||
return (float)BitConverter.Int64BitsToDouble(Dec_uint32be(src, si));
|
||||
}
|
||||
}
|
||||
|
||||
public static int Enc_doublele(double d, byte[] dst, int di)
|
||||
{
|
||||
public static int Enc_doublele(double d, byte[] dst, int di)
|
||||
{
|
||||
return Enc_uint64le(BitConverter.DoubleToInt64Bits(d), dst, di);
|
||||
}
|
||||
}
|
||||
|
||||
public static int Enc_doublebe(double d, byte[] dst, int di)
|
||||
{
|
||||
public static int Enc_doublebe(double d, byte[] dst, int di)
|
||||
{
|
||||
return Enc_uint64be(BitConverter.DoubleToInt64Bits(d), dst, di);
|
||||
}
|
||||
}
|
||||
|
||||
public static double Dec_doublele(byte[] src, int si)
|
||||
{
|
||||
public static double Dec_doublele(byte[] src, int si)
|
||||
{
|
||||
return BitConverter.Int64BitsToDouble(Dec_uint64le(src, si));
|
||||
}
|
||||
}
|
||||
|
||||
public static double Dec_doublebe(byte[] src, int si)
|
||||
{
|
||||
public static double Dec_doublebe(byte[] src, int si)
|
||||
{
|
||||
return BitConverter.Int64BitsToDouble(Dec_uint64be(src, si));
|
||||
}
|
||||
}
|
||||
|
||||
public static int Enc_time(DateTime date, byte[] dst, int di, int enc)
|
||||
{
|
||||
long t;
|
||||
switch (enc)
|
||||
{
|
||||
case Time1970Sec32Be:
|
||||
{
|
||||
return Enc_uint32be((int)(date.GetTime() / 1000L), dst, di);
|
||||
}
|
||||
public static int Enc_time(DateTime date, byte[] dst, int di, int enc)
|
||||
{
|
||||
long t;
|
||||
switch (enc)
|
||||
{
|
||||
case Time1970Sec32Be:
|
||||
{
|
||||
return Enc_uint32be((int)(date.GetTime() / 1000L), dst, di);
|
||||
}
|
||||
|
||||
case Time1970Sec32Le:
|
||||
{
|
||||
return Enc_uint32le((int)(date.GetTime() / 1000L), dst, di);
|
||||
}
|
||||
case Time1970Sec32Le:
|
||||
{
|
||||
return Enc_uint32le((int)(date.GetTime() / 1000L), dst, di);
|
||||
}
|
||||
|
||||
case Time1904Sec32Be:
|
||||
{
|
||||
return Enc_uint32be((int)((date.GetTime() / 1000L
|
||||
+ SecBetweeen1904And1970)
|
||||
& unchecked((int)(0xFFFFFFFF))),
|
||||
dst,
|
||||
di);
|
||||
}
|
||||
case Time1904Sec32Be:
|
||||
{
|
||||
return Enc_uint32be((int)((date.GetTime() / 1000L + SecBetweeen1904And1970) &
|
||||
unchecked((int)(0xFFFFFFFF))), dst, di);
|
||||
}
|
||||
|
||||
case Time1904Sec32Le:
|
||||
{
|
||||
return Enc_uint32le((int)((date.GetTime() / 1000L
|
||||
+ SecBetweeen1904And1970)
|
||||
& unchecked((int)(0xFFFFFFFF))),
|
||||
dst,
|
||||
di);
|
||||
}
|
||||
case Time1904Sec32Le:
|
||||
{
|
||||
return Enc_uint32le((int)((date.GetTime() / 1000L + SecBetweeen1904And1970) &
|
||||
unchecked((int)(0xFFFFFFFF))), dst, di);
|
||||
}
|
||||
|
||||
case Time1601Nanos64Be:
|
||||
{
|
||||
t = (date.GetTime() + MillisecondsBetween1970And1601) * 10000L;
|
||||
return Enc_uint64be(t, dst, di);
|
||||
}
|
||||
case Time1601Nanos64Be:
|
||||
{
|
||||
t = (date.GetTime() + MillisecondsBetween1970And1601) * 10000L;
|
||||
return Enc_uint64be(t, dst, di);
|
||||
}
|
||||
|
||||
case Time1601Nanos64Le:
|
||||
{
|
||||
t = (date.GetTime() + MillisecondsBetween1970And1601) * 10000L;
|
||||
return Enc_uint64le(t, dst, di);
|
||||
}
|
||||
case Time1601Nanos64Le:
|
||||
{
|
||||
t = (date.GetTime() + MillisecondsBetween1970And1601) * 10000L;
|
||||
return Enc_uint64le(t, dst, di);
|
||||
}
|
||||
|
||||
case Time1970Millis64Be:
|
||||
{
|
||||
return Enc_uint64be(date.GetTime(), dst, di);
|
||||
}
|
||||
case Time1970Millis64Be:
|
||||
{
|
||||
return Enc_uint64be(date.GetTime(), dst, di);
|
||||
}
|
||||
|
||||
case Time1970Millis64Le:
|
||||
{
|
||||
return Enc_uint64le(date.GetTime(), dst, di);
|
||||
}
|
||||
case Time1970Millis64Le:
|
||||
{
|
||||
return Enc_uint64le(date.GetTime(), dst, di);
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
throw new ArgumentException("Unsupported time encoding");
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw new ArgumentException("Unsupported time encoding");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static DateTime Dec_time(byte[] src, int si, int enc)
|
||||
{
|
||||
long t;
|
||||
switch (enc)
|
||||
{
|
||||
case Time1970Sec32Be:
|
||||
{
|
||||
return Sharpen.Extensions.CreateDate(Dec_uint32be(src, si) * 1000L);
|
||||
}
|
||||
public static DateTime Dec_time(byte[] src, int si, int enc)
|
||||
{
|
||||
long t;
|
||||
switch (enc)
|
||||
{
|
||||
case Time1970Sec32Be:
|
||||
{
|
||||
return Sharpen.Extensions.CreateDate(Dec_uint32be(src, si) * 1000L);
|
||||
}
|
||||
|
||||
case Time1970Sec32Le:
|
||||
{
|
||||
return Sharpen.Extensions.CreateDate(Dec_uint32le(src, si) * 1000L);
|
||||
}
|
||||
case Time1970Sec32Le:
|
||||
{
|
||||
return Sharpen.Extensions.CreateDate(Dec_uint32le(src, si) * 1000L);
|
||||
}
|
||||
|
||||
case Time1904Sec32Be:
|
||||
{
|
||||
return Sharpen.Extensions.CreateDate( ( (Dec_uint32be(src, si)
|
||||
& unchecked(0xFFFFFFFFL))
|
||||
- SecBetweeen1904And1970)
|
||||
* 1000L );
|
||||
}
|
||||
case Time1904Sec32Be:
|
||||
{
|
||||
return Sharpen.Extensions.CreateDate(((Dec_uint32be(src, si) & unchecked(0xFFFFFFFFL)) - SecBetweeen1904And1970) * 1000L);
|
||||
}
|
||||
|
||||
case Time1904Sec32Le:
|
||||
{
|
||||
return Sharpen.Extensions.CreateDate( ( (Dec_uint32le(src, si)
|
||||
& unchecked(0xFFFFFFFFL))
|
||||
- SecBetweeen1904And1970)
|
||||
* 1000L);
|
||||
}
|
||||
case Time1904Sec32Le:
|
||||
{
|
||||
return Sharpen.Extensions.CreateDate(((Dec_uint32le(src, si) & unchecked(0xFFFFFFFFL)) - SecBetweeen1904And1970) * 1000L);
|
||||
}
|
||||
|
||||
case Time1601Nanos64Be:
|
||||
{
|
||||
t = Dec_uint64be(src, si);
|
||||
return Sharpen.Extensions.CreateDate(t / 10000L
|
||||
- MillisecondsBetween1970And1601);
|
||||
}
|
||||
case Time1601Nanos64Be:
|
||||
{
|
||||
t = Dec_uint64be(src, si);
|
||||
return Sharpen.Extensions.CreateDate(t / 10000L - MillisecondsBetween1970And1601
|
||||
);
|
||||
}
|
||||
|
||||
case Time1601Nanos64Le:
|
||||
{
|
||||
t = Dec_uint64le(src, si);
|
||||
return Sharpen.Extensions.CreateDate(t / 10000L
|
||||
- MillisecondsBetween1970And1601);
|
||||
}
|
||||
case Time1601Nanos64Le:
|
||||
{
|
||||
t = Dec_uint64le(src, si);
|
||||
return Sharpen.Extensions.CreateDate(t / 10000L - MillisecondsBetween1970And1601
|
||||
);
|
||||
}
|
||||
|
||||
case Time1970Millis64Be:
|
||||
{
|
||||
return Sharpen.Extensions.CreateDate(Dec_uint64be(src, si));
|
||||
}
|
||||
case Time1970Millis64Be:
|
||||
{
|
||||
return Sharpen.Extensions.CreateDate(Dec_uint64be(src, si));
|
||||
}
|
||||
|
||||
case Time1970Millis64Le:
|
||||
{
|
||||
return Sharpen.Extensions.CreateDate(Dec_uint64le(src, si));
|
||||
}
|
||||
case Time1970Millis64Le:
|
||||
{
|
||||
return Sharpen.Extensions.CreateDate(Dec_uint64le(src, si));
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
throw new ArgumentException("Unsupported time encoding");
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw new ArgumentException("Unsupported time encoding");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
public static int Enc_utf8(string str, byte[] dst, int di, int dlim)
|
||||
{
|
||||
int start = di;
|
||||
int ch;
|
||||
int strlen = str.Length;
|
||||
for (int i = 0; di < dlim && i < strlen; i++)
|
||||
{
|
||||
ch = str[i];
|
||||
if ((ch >= unchecked(0x0001)) && (ch <= unchecked(0x007F)))
|
||||
{
|
||||
dst[di++] = unchecked((byte)ch);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ch > unchecked(0x07FF))
|
||||
{
|
||||
if ((dlim - di) < 3)
|
||||
{
|
||||
break;
|
||||
}
|
||||
dst[di++] = unchecked((byte)(unchecked(0xE0) | ((ch >> 12) & unchecked(0x0F))));
|
||||
dst[di++] = unchecked((byte)(unchecked(0x80) | ((ch >> 6) & unchecked(0x3F))));
|
||||
dst[di++] = unchecked((byte)(unchecked(0x80) | ((ch >> 0) & unchecked(0x3F))));
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((dlim - di) < 2)
|
||||
{
|
||||
break;
|
||||
}
|
||||
dst[di++] = unchecked((byte)(unchecked(0xC0) | ((ch >> 6) & unchecked(0x1F))));
|
||||
dst[di++] = unchecked((byte)(unchecked(0x80) | ((ch >> 0) & unchecked(0x3F))));
|
||||
}
|
||||
}
|
||||
}
|
||||
return di - start;
|
||||
}
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
public static int Enc_utf8(string str, byte[] dst, int di, int dlim)
|
||||
{
|
||||
int start = di;
|
||||
int ch;
|
||||
int strlen = str.Length;
|
||||
for (int i = 0; di < dlim && i < strlen; i++)
|
||||
{
|
||||
ch = str[i];
|
||||
if ((ch >= unchecked(0x0001)) && (ch <= unchecked(0x007F)))
|
||||
{
|
||||
dst[di++] = unchecked((byte)ch);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ch > unchecked(0x07FF))
|
||||
{
|
||||
if ((dlim - di) < 3)
|
||||
{
|
||||
break;
|
||||
}
|
||||
dst[di++] = unchecked((byte)(unchecked(0xE0) | ((ch >> 12) & unchecked(0x0F))));
|
||||
dst[di++] = unchecked((byte)(unchecked(0x80) | ((ch >> 6) & unchecked(0x3F))));
|
||||
dst[di++] = unchecked((byte)(unchecked(0x80) | ((ch >> 0) & unchecked(0x3F))));
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((dlim - di) < 2)
|
||||
{
|
||||
break;
|
||||
}
|
||||
dst[di++] = unchecked((byte)(unchecked(0xC0) | ((ch >> 6) & unchecked(0x1F))));
|
||||
dst[di++] = unchecked((byte)(unchecked(0x80) | ((ch >> 0) & unchecked(0x3F))));
|
||||
}
|
||||
}
|
||||
}
|
||||
return di - start;
|
||||
}
|
||||
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
public static string Dec_utf8(byte[] src, int si, int slim)
|
||||
{
|
||||
char[] uni = new char[slim - si];
|
||||
int ui;
|
||||
int ch;
|
||||
for (ui = 0; si < slim && (ch = src[si++] & unchecked(0xFF)) != 0; ui++)
|
||||
{
|
||||
if (ch < unchecked(0x80))
|
||||
{
|
||||
uni[ui] = (char)ch;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((ch & unchecked(0xE0)) == unchecked(0xC0))
|
||||
{
|
||||
if ((slim - si) < 2)
|
||||
{
|
||||
break;
|
||||
}
|
||||
uni[ui] = (char)((ch & unchecked(0x1F)) << 6);
|
||||
ch = src[si++] & unchecked(0xFF);
|
||||
uni[ui] |= (char)((char)ch & unchecked(0x3F));
|
||||
if ((ch & unchecked(0xC0)) != unchecked(0x80) || uni[ui] < unchecked(
|
||||
0x80))
|
||||
{
|
||||
throw new IOException("Invalid UTF-8 sequence");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((ch & unchecked(0xF0)) == unchecked(0xE0))
|
||||
{
|
||||
if ((slim - si) < 3)
|
||||
{
|
||||
break;
|
||||
}
|
||||
uni[ui] = (char)((ch & unchecked(0x0F)) << 12);
|
||||
ch = src[si++] & unchecked(0xFF);
|
||||
if ((ch & unchecked(0xC0)) != unchecked(0x80))
|
||||
{
|
||||
throw new IOException("Invalid UTF-8 sequence");
|
||||
}
|
||||
uni[ui] |= (char)((char)(ch & unchecked(0x3F)) << 6);
|
||||
ch = src[si++] & unchecked(0xFF);
|
||||
uni[ui] |= (char)((char)ch & unchecked(0x3F));
|
||||
if ((ch & unchecked(0xC0)) != unchecked(0x80) || uni[ui] < unchecked(
|
||||
0x800))
|
||||
{
|
||||
throw new IOException("Invalid UTF-8 sequence");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IOException("Unsupported UTF-8 sequence");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new string(uni, 0, ui);
|
||||
}
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
public static string Dec_utf8(byte[] src, int si, int slim)
|
||||
{
|
||||
char[] uni = new char[slim - si];
|
||||
int ui;
|
||||
int ch;
|
||||
for (ui = 0; si < slim && (ch = src[si++] & unchecked(0xFF)) != 0; ui++)
|
||||
{
|
||||
if (ch < unchecked(0x80))
|
||||
{
|
||||
uni[ui] = (char)ch;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((ch & unchecked(0xE0)) == unchecked(0xC0))
|
||||
{
|
||||
if ((slim - si) < 2)
|
||||
{
|
||||
break;
|
||||
}
|
||||
uni[ui] = (char)((ch & unchecked(0x1F)) << 6);
|
||||
ch = src[si++] & unchecked(0xFF);
|
||||
uni[ui] |= (char)((char)ch & unchecked(0x3F));
|
||||
if ((ch & unchecked(0xC0)) != unchecked(0x80) || uni[ui] < unchecked(
|
||||
0x80))
|
||||
{
|
||||
throw new IOException("Invalid UTF-8 sequence");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((ch & unchecked(0xF0)) == unchecked(0xE0))
|
||||
{
|
||||
if ((slim - si) < 3)
|
||||
{
|
||||
break;
|
||||
}
|
||||
uni[ui] = (char)((ch & unchecked(0x0F)) << 12);
|
||||
ch = src[si++] & unchecked(0xFF);
|
||||
if ((ch & unchecked(0xC0)) != unchecked(0x80))
|
||||
{
|
||||
throw new IOException("Invalid UTF-8 sequence");
|
||||
}
|
||||
uni[ui] |= (char)((char)(ch & unchecked(0x3F)) << 6);
|
||||
ch = src[si++] & unchecked(0xFF);
|
||||
uni[ui] |= (char)((char)ch & unchecked(0x3F));
|
||||
if ((ch & unchecked(0xC0)) != unchecked(0x80) || uni[ui] < unchecked(
|
||||
0x800))
|
||||
{
|
||||
throw new IOException("Invalid UTF-8 sequence");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IOException("Unsupported UTF-8 sequence");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new string(uni, 0, ui);
|
||||
}
|
||||
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
public static string Dec_ucs2le(byte[] src, int si, int slim, char[] buf)
|
||||
{
|
||||
int bi;
|
||||
for (bi = 0; (si + 1) < slim; bi++, si += 2)
|
||||
{
|
||||
buf[bi] = (char)Dec_uint16le(src, si);
|
||||
if (buf[bi] == '\0')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new string(buf, 0, bi);
|
||||
}
|
||||
}
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
public static string Dec_ucs2le(byte[] src, int si, int slim, char[] buf)
|
||||
{
|
||||
int bi;
|
||||
for (bi = 0; (si + 1) < slim; bi++, si += 2)
|
||||
{
|
||||
buf[bi] = (char)Dec_uint16le(src, si);
|
||||
if (buf[bi] == '\0')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new string(buf, 0, bi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,99 +19,99 @@ using SharpCifs.Util.Sharpen;
|
||||
|
||||
namespace SharpCifs.Util
|
||||
{
|
||||
/// <summary>This is an implementation of the HMACT64 keyed hashing algorithm.</summary>
|
||||
/// <remarks>
|
||||
/// This is an implementation of the HMACT64 keyed hashing algorithm.
|
||||
/// HMACT64 is defined by Luke Leighton as a modified HMAC-MD5 (RFC 2104)
|
||||
/// in which the key is truncated at 64 bytes (rather than being hashed
|
||||
/// via MD5).
|
||||
/// </remarks>
|
||||
public class Hmact64 : MessageDigest
|
||||
{
|
||||
private const int BlockLength = 64;
|
||||
/// <summary>This is an implementation of the HMACT64 keyed hashing algorithm.</summary>
|
||||
/// <remarks>
|
||||
/// This is an implementation of the HMACT64 keyed hashing algorithm.
|
||||
/// HMACT64 is defined by Luke Leighton as a modified HMAC-MD5 (RFC 2104)
|
||||
/// in which the key is truncated at 64 bytes (rather than being hashed
|
||||
/// via MD5).
|
||||
/// </remarks>
|
||||
public class Hmact64 : MessageDigest
|
||||
{
|
||||
private const int BlockLength = 64;
|
||||
|
||||
private const byte Ipad = unchecked(unchecked(0x36));
|
||||
private const byte Ipad = unchecked(unchecked(0x36));
|
||||
|
||||
private const byte Opad = unchecked(unchecked(0x5c));
|
||||
private const byte Opad = unchecked(unchecked(0x5c));
|
||||
|
||||
private MessageDigest _md5;
|
||||
private MessageDigest _md5;
|
||||
|
||||
private byte[] _ipad = new byte[BlockLength];
|
||||
private byte[] _ipad = new byte[BlockLength];
|
||||
|
||||
private byte[] _opad = new byte[BlockLength];
|
||||
private byte[] _opad = new byte[BlockLength];
|
||||
|
||||
/// <summary>Creates an HMACT64 instance which uses the given secret key material.</summary>
|
||||
/// <remarks>Creates an HMACT64 instance which uses the given secret key material.</remarks>
|
||||
/// <param name="key">The key material to use in hashing.</param>
|
||||
public Hmact64(byte[] key)
|
||||
{
|
||||
int length = Math.Min(key.Length, BlockLength);
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
_ipad[i] = unchecked((byte)(key[i] ^ Ipad));
|
||||
_opad[i] = unchecked((byte)(key[i] ^ Opad));
|
||||
}
|
||||
for (int i1 = length; i1 < BlockLength; i1++)
|
||||
{
|
||||
_ipad[i1] = Ipad;
|
||||
_opad[i1] = Opad;
|
||||
}
|
||||
try
|
||||
{
|
||||
_md5 = GetInstance("MD5");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException(ex.Message);
|
||||
}
|
||||
EngineReset();
|
||||
}
|
||||
/// <summary>Creates an HMACT64 instance which uses the given secret key material.</summary>
|
||||
/// <remarks>Creates an HMACT64 instance which uses the given secret key material.</remarks>
|
||||
/// <param name="key">The key material to use in hashing.</param>
|
||||
public Hmact64(byte[] key)
|
||||
{
|
||||
int length = Math.Min(key.Length, BlockLength);
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
_ipad[i] = unchecked((byte)(key[i] ^ Ipad));
|
||||
_opad[i] = unchecked((byte)(key[i] ^ Opad));
|
||||
}
|
||||
for (int i1 = length; i1 < BlockLength; i1++)
|
||||
{
|
||||
_ipad[i1] = Ipad;
|
||||
_opad[i1] = Opad;
|
||||
}
|
||||
try
|
||||
{
|
||||
_md5 = GetInstance("MD5");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException(ex.Message);
|
||||
}
|
||||
EngineReset();
|
||||
}
|
||||
|
||||
|
||||
protected byte[] EngineDigest()
|
||||
{
|
||||
byte[] digest = _md5.Digest();
|
||||
_md5.Update(_opad);
|
||||
return _md5.Digest(digest);
|
||||
}
|
||||
protected byte[] EngineDigest()
|
||||
{
|
||||
byte[] digest = _md5.Digest();
|
||||
_md5.Update(_opad);
|
||||
return _md5.Digest(digest);
|
||||
}
|
||||
|
||||
protected int EngineDigest(byte[] buf, int offset, int len)
|
||||
{
|
||||
byte[] digest = _md5.Digest();
|
||||
_md5.Update(_opad);
|
||||
_md5.Update(digest);
|
||||
try
|
||||
{
|
||||
_md5.Digest(buf, offset, len);
|
||||
protected int EngineDigest(byte[] buf, int offset, int len)
|
||||
{
|
||||
byte[] digest = _md5.Digest();
|
||||
_md5.Update(_opad);
|
||||
_md5.Update(digest);
|
||||
try
|
||||
{
|
||||
_md5.Digest(buf, offset, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
protected int EngineGetDigestLength()
|
||||
{
|
||||
return _md5.GetDigestLength();
|
||||
}
|
||||
protected int EngineGetDigestLength()
|
||||
{
|
||||
return _md5.GetDigestLength();
|
||||
}
|
||||
|
||||
protected void EngineReset()
|
||||
{
|
||||
_md5.Reset();
|
||||
_md5.Update(_ipad);
|
||||
}
|
||||
protected void EngineReset()
|
||||
{
|
||||
_md5.Reset();
|
||||
_md5.Update(_ipad);
|
||||
}
|
||||
|
||||
protected void EngineUpdate(byte b)
|
||||
{
|
||||
_md5.Update(b);
|
||||
}
|
||||
protected void EngineUpdate(byte b)
|
||||
{
|
||||
_md5.Update(b);
|
||||
}
|
||||
|
||||
protected void EngineUpdate(byte[] input, int offset, int len)
|
||||
{
|
||||
_md5.Update(input, offset, len);
|
||||
}
|
||||
protected void EngineUpdate(byte[] input, int offset, int len)
|
||||
{
|
||||
_md5.Update(input, offset, len);
|
||||
}
|
||||
|
||||
public override byte[] Digest()
|
||||
{
|
||||
|
||||
@@ -19,176 +19,173 @@ using System.IO;
|
||||
|
||||
namespace SharpCifs.Util
|
||||
{
|
||||
public class Hexdump
|
||||
{
|
||||
private static readonly string Nl = @"\r\n"; //Runtime.GetProperty("line.separator");
|
||||
public class Hexdump
|
||||
{
|
||||
private static readonly string Nl = @"\r\n"; //Runtime.GetProperty("line.separator");
|
||||
|
||||
private static readonly int NlLength = Nl.Length;
|
||||
private static readonly int NlLength = Nl.Length;
|
||||
|
||||
private static readonly char[] SpaceChars =
|
||||
{
|
||||
' ', ' ', ' ', ' ', ' '
|
||||
, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
|
||||
, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
|
||||
, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
|
||||
};
|
||||
private static readonly char[] SpaceChars = { ' ', ' ', ' ', ' ', ' '
|
||||
, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
|
||||
, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
|
||||
, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' };
|
||||
|
||||
public static readonly char[] HexDigits
|
||||
= { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
public static readonly char[] HexDigits = { '0', '1', '2', '3', '4',
|
||||
'5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
|
||||
|
||||
private static bool IsIsoControl(char c)
|
||||
{
|
||||
return (c >= '\u0000' && c <= '\u001F') || (c >= '\u007F' && c <= '\u009F');
|
||||
}
|
||||
|
||||
private static bool IsIsoControl(char c)
|
||||
{
|
||||
return (c >= '\u0000' && c <= '\u001F') || (c >= '\u007F' && c <= '\u009F');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate "hexdump" output of the buffer at src like the following:
|
||||
/// <p><blockquote><pre>
|
||||
/// 00000: 04 d2 29 00 00 01 00 00 00 00 00 01 20 45 47 46 |..).........
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Generate "hexdump" output of the buffer at src like the following:
|
||||
/// <p><blockquote><pre>
|
||||
/// 00000: 04 d2 29 00 00 01 00 00 00 00 00 01 20 45 47 46 |..)......... EGF|
|
||||
/// 00010: 43 45 46 45 45 43 41 43 41 43 41 43 41 43 41 43 |CEFEECACACACACAC|
|
||||
/// 00020: 41 43 41 43 41 43 41 43 41 43 41 41 44 00 00 20 |ACACACACACAAD.. |
|
||||
/// 00030: 00 01 c0 0c 00 20 00 01 00 00 00 00 00 06 20 00 |..... ........ .|
|
||||
/// 00040: ac 22 22 e1 |."". |
|
||||
/// </blockquote></pre>
|
||||
/// </remarks>
|
||||
public static void ToHexdump(TextWriter ps, byte[] src, int srcIndex, int length)
|
||||
{
|
||||
if (length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int s = length % 16;
|
||||
int r = (s == 0) ? length / 16 : length / 16 + 1;
|
||||
char[] c = new char[r * (74 + NlLength)];
|
||||
char[] d = new char[16];
|
||||
int i;
|
||||
int si = 0;
|
||||
int ci = 0;
|
||||
do
|
||||
{
|
||||
ToHexChars(si, c, ci, 5);
|
||||
ci += 5;
|
||||
c[ci++] = ':';
|
||||
do
|
||||
{
|
||||
if (si == length)
|
||||
{
|
||||
int n = 16 - s;
|
||||
Array.Copy(SpaceChars, 0, c, ci, n * 3);
|
||||
ci += n * 3;
|
||||
Array.Copy(SpaceChars, 0, d, s, n);
|
||||
break;
|
||||
}
|
||||
c[ci++] = ' ';
|
||||
i = src[srcIndex + si] & 0xFF;
|
||||
ToHexChars(i, c, ci, 2);
|
||||
ci += 2;
|
||||
if (i < 0 || IsIsoControl((char)i))
|
||||
{
|
||||
d[si % 16] = '.';
|
||||
}
|
||||
else
|
||||
{
|
||||
d[si % 16] = (char)i;
|
||||
}
|
||||
}
|
||||
while ((++si % 16) != 0);
|
||||
c[ci++] = ' ';
|
||||
c[ci++] = ' ';
|
||||
c[ci++] = '|';
|
||||
Array.Copy(d, 0, c, ci, 16);
|
||||
ci += 16;
|
||||
c[ci++] = '|';
|
||||
//Sharpen.Runtime.GetCharsForString(NL, 0, NL_LENGTH, c, ci);
|
||||
c = Nl.ToCharArray(0, NlLength);
|
||||
ci += NlLength;
|
||||
}
|
||||
while (si < length);
|
||||
ps.WriteLine(c);
|
||||
}
|
||||
/// Generate "hexdump" output of the buffer at src like the following:
|
||||
/// <p><blockquote><pre>
|
||||
/// 00000: 04 d2 29 00 00 01 00 00 00 00 00 01 20 45 47 46 |..).........
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Generate "hexdump" output of the buffer at src like the following:
|
||||
/// <p><blockquote><pre>
|
||||
/// 00000: 04 d2 29 00 00 01 00 00 00 00 00 01 20 45 47 46 |..)......... EGF|
|
||||
/// 00010: 43 45 46 45 45 43 41 43 41 43 41 43 41 43 41 43 |CEFEECACACACACAC|
|
||||
/// 00020: 41 43 41 43 41 43 41 43 41 43 41 41 44 00 00 20 |ACACACACACAAD.. |
|
||||
/// 00030: 00 01 c0 0c 00 20 00 01 00 00 00 00 00 06 20 00 |..... ........ .|
|
||||
/// 00040: ac 22 22 e1 |."". |
|
||||
/// </blockquote></pre>
|
||||
/// </remarks>
|
||||
public static void ToHexdump(TextWriter ps, byte[] src, int srcIndex, int length)
|
||||
{
|
||||
if (length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int s = length % 16;
|
||||
int r = (s == 0) ? length / 16 : length / 16 + 1;
|
||||
char[] c = new char[r * (74 + NlLength)];
|
||||
char[] d = new char[16];
|
||||
int i;
|
||||
int si = 0;
|
||||
int ci = 0;
|
||||
do
|
||||
{
|
||||
ToHexChars(si, c, ci, 5);
|
||||
ci += 5;
|
||||
c[ci++] = ':';
|
||||
do
|
||||
{
|
||||
if (si == length)
|
||||
{
|
||||
int n = 16 - s;
|
||||
Array.Copy(SpaceChars, 0, c, ci, n * 3);
|
||||
ci += n * 3;
|
||||
Array.Copy(SpaceChars, 0, d, s, n);
|
||||
break;
|
||||
}
|
||||
c[ci++] = ' ';
|
||||
i = src[srcIndex + si] & 0xFF;
|
||||
ToHexChars(i, c, ci, 2);
|
||||
ci += 2;
|
||||
if (i < 0 || IsIsoControl((char)i))
|
||||
{
|
||||
d[si % 16] = '.';
|
||||
}
|
||||
else
|
||||
{
|
||||
d[si % 16] = (char)i;
|
||||
}
|
||||
}
|
||||
while ((++si % 16) != 0);
|
||||
c[ci++] = ' ';
|
||||
c[ci++] = ' ';
|
||||
c[ci++] = '|';
|
||||
Array.Copy(d, 0, c, ci, 16);
|
||||
ci += 16;
|
||||
c[ci++] = '|';
|
||||
//Sharpen.Runtime.GetCharsForString(NL, 0, NL_LENGTH, c, ci);
|
||||
c = Nl.ToCharArray(0, NlLength);
|
||||
ci += NlLength;
|
||||
}
|
||||
while (si < length);
|
||||
ps.WriteLine(c);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is an alternative to the <code>java.lang.Integer.toHexString</cod>
|
||||
/// method.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is an alternative to the <code>java.lang.Integer.toHexString</cod>
|
||||
/// method. It is an efficient relative that also will pad the left side so
|
||||
/// that the result is <code>size</code> digits.
|
||||
/// </remarks>
|
||||
public static string ToHexString(int val, int size)
|
||||
{
|
||||
char[] c = new char[size];
|
||||
ToHexChars(val, c, 0, size);
|
||||
return new string(c);
|
||||
}
|
||||
/// <summary>
|
||||
/// This is an alternative to the <code>java.lang.Integer.toHexString</cod>
|
||||
/// method.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is an alternative to the <code>java.lang.Integer.toHexString</cod>
|
||||
/// method. It is an efficient relative that also will pad the left side so
|
||||
/// that the result is <code>size</code> digits.
|
||||
/// </remarks>
|
||||
public static string ToHexString(int val, int size)
|
||||
{
|
||||
char[] c = new char[size];
|
||||
ToHexChars(val, c, 0, size);
|
||||
return new string(c);
|
||||
}
|
||||
|
||||
public static string ToHexString(long val, int size)
|
||||
{
|
||||
char[] c = new char[size];
|
||||
ToHexChars(val, c, 0, size);
|
||||
return new string(c);
|
||||
}
|
||||
public static string ToHexString(long val, int size)
|
||||
{
|
||||
char[] c = new char[size];
|
||||
ToHexChars(val, c, 0, size);
|
||||
return new string(c);
|
||||
}
|
||||
|
||||
public static string ToHexString(byte[] src, int srcIndex, int size)
|
||||
{
|
||||
char[] c = new char[size];
|
||||
size = (size % 2 == 0) ? size / 2 : size / 2 + 1;
|
||||
for (int i = 0, j = 0; i < size; i++)
|
||||
{
|
||||
c[j++] = HexDigits[(src[i] >> 4) & 0x0F];
|
||||
if (j == c.Length)
|
||||
{
|
||||
break;
|
||||
}
|
||||
c[j++] = HexDigits[src[i] & 0x0F];
|
||||
}
|
||||
return new string(c);
|
||||
}
|
||||
public static string ToHexString(byte[] src, int srcIndex, int size)
|
||||
{
|
||||
char[] c = new char[size];
|
||||
size = (size % 2 == 0) ? size / 2 : size / 2 + 1;
|
||||
for (int i = 0, j = 0; i < size; i++)
|
||||
{
|
||||
c[j++] = HexDigits[(src[i] >> 4) & 0x0F];
|
||||
if (j == c.Length)
|
||||
{
|
||||
break;
|
||||
}
|
||||
c[j++] = HexDigits[src[i] & 0x0F];
|
||||
}
|
||||
return new string(c);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is the same as
|
||||
/// <see cref="ToHexString(int, int)">ToHexString(int, int)</see>
|
||||
/// but provides a more practical form when trying to avoid
|
||||
/// <see cref="string">string</see>
|
||||
/// concatenation and
|
||||
/// <see cref="System.Text.StringBuilder">System.Text.StringBuilder</see>
|
||||
/// .
|
||||
/// </summary>
|
||||
public static void ToHexChars(int val, char[] dst, int dstIndex, int size)
|
||||
{
|
||||
while (size > 0)
|
||||
{
|
||||
int i = dstIndex + size - 1;
|
||||
if (i < dst.Length)
|
||||
{
|
||||
dst[i] = HexDigits[val & 0x000F];
|
||||
}
|
||||
if (val != 0)
|
||||
{
|
||||
val = (int)(((uint)val) >> 4);
|
||||
}
|
||||
size--;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// This is the same as
|
||||
/// <see cref="ToHexString(int, int)">ToHexString(int, int)</see>
|
||||
/// but provides a more practical form when trying to avoid
|
||||
/// <see cref="string">string</see>
|
||||
/// concatenation and
|
||||
/// <see cref="System.Text.StringBuilder">System.Text.StringBuilder</see>
|
||||
/// .
|
||||
/// </summary>
|
||||
public static void ToHexChars(int val, char[] dst, int dstIndex, int size)
|
||||
{
|
||||
while (size > 0)
|
||||
{
|
||||
int i = dstIndex + size - 1;
|
||||
if (i < dst.Length)
|
||||
{
|
||||
dst[i] = HexDigits[val & 0x000F];
|
||||
}
|
||||
if (val != 0)
|
||||
{
|
||||
val = (int)(((uint)val) >> 4);
|
||||
}
|
||||
size--;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ToHexChars(long val, char[] dst, int dstIndex, int size)
|
||||
{
|
||||
while (size > 0)
|
||||
{
|
||||
dst[dstIndex + size - 1] = HexDigits[(int)(val & 0x000FL)];
|
||||
if (val != 0)
|
||||
{
|
||||
val = (long)(((ulong)val) >> 4);
|
||||
}
|
||||
size--;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void ToHexChars(long val, char[] dst, int dstIndex, int size)
|
||||
{
|
||||
while (size > 0)
|
||||
{
|
||||
dst[dstIndex + size - 1] = HexDigits[(int)(val & 0x000FL)];
|
||||
if (val != 0)
|
||||
{
|
||||
val = (long)(((ulong)val) >> 4);
|
||||
}
|
||||
size--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,55 +24,55 @@ using SharpCifs.Util.Sharpen;
|
||||
|
||||
namespace SharpCifs.Util
|
||||
{
|
||||
/// <summary>
|
||||
/// 0 - nothing
|
||||
/// 1 - critical [default]
|
||||
/// 2 - basic info can be logged under load
|
||||
/// 3 - almost everything
|
||||
/// N - debugging
|
||||
/// </summary>
|
||||
public class LogStream : PrintWriter
|
||||
{
|
||||
/// <summary>
|
||||
/// 0 - nothing
|
||||
/// 1 - critical [default]
|
||||
/// 2 - basic info can be logged under load
|
||||
/// 3 - almost everything
|
||||
/// N - debugging
|
||||
/// </summary>
|
||||
public class LogStream: PrintWriter
|
||||
{
|
||||
private static LogStream _inst = null;
|
||||
|
||||
public int Level = 1;
|
||||
public int Level = 1;
|
||||
|
||||
public void SetLevel(int level)
|
||||
{
|
||||
this.Level = level;
|
||||
}
|
||||
public void SetLevel(int level)
|
||||
{
|
||||
this.Level = level;
|
||||
}
|
||||
|
||||
public LogStream(TextWriter other) : base(other)
|
||||
{
|
||||
public LogStream(TextWriter other) : base(other)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// This must be called before <tt>getInstance</tt> is called or
|
||||
/// it will have no effect.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This must be called before <tt>getInstance</tt> is called or
|
||||
/// it will have no effect.
|
||||
/// </remarks>
|
||||
public static void SetInstance(TextWriter other)
|
||||
{
|
||||
//inst = new Jcifs.Util.LogStream();
|
||||
_inst = new LogStream(other);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This must be called before <tt>getInstance</tt> is called or
|
||||
/// it will have no effect.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This must be called before <tt>getInstance</tt> is called or
|
||||
/// it will have no effect.
|
||||
/// </remarks>
|
||||
public static void SetInstance(TextWriter other)
|
||||
{
|
||||
//inst = new Jcifs.Util.LogStream();
|
||||
_inst = new LogStream(other);
|
||||
}
|
||||
|
||||
public static LogStream GetInstance()
|
||||
{
|
||||
if (_inst == null)
|
||||
{
|
||||
public static LogStream GetInstance()
|
||||
{
|
||||
if (_inst == null)
|
||||
{
|
||||
SetInstance(Console.Error);
|
||||
}
|
||||
return _inst;
|
||||
}
|
||||
|
||||
public override Encoding Encoding
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
return _inst;
|
||||
}
|
||||
|
||||
public override Encoding Encoding
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,329 +19,329 @@ using SharpCifs.Util.Sharpen;
|
||||
|
||||
namespace SharpCifs.Util
|
||||
{
|
||||
/// <summary>Implements the MD4 message digest algorithm in Java.</summary>
|
||||
/// <remarks>
|
||||
/// Implements the MD4 message digest algorithm in Java.
|
||||
/// <p>
|
||||
/// <b>References:</b>
|
||||
/// <ol>
|
||||
/// <li> Ronald L. Rivest,
|
||||
/// "<a href="http://www.roxen.com/rfc/rfc1320.html">
|
||||
/// The MD4 Message-Digest Algorithm</a>",
|
||||
/// IETF RFC-1320 (informational).
|
||||
/// </ol>
|
||||
/// <p><b>$Revision: 1.2 $</b>
|
||||
/// </remarks>
|
||||
/// <author>Raif S. Naffah</author>
|
||||
public class Md4 : MessageDigest
|
||||
{
|
||||
/// <summary>The size in bytes of the input block to the tranformation algorithm.</summary>
|
||||
/// <remarks>The size in bytes of the input block to the tranformation algorithm.</remarks>
|
||||
private const int BlockLength = 64;
|
||||
/// <summary>Implements the MD4 message digest algorithm in Java.</summary>
|
||||
/// <remarks>
|
||||
/// Implements the MD4 message digest algorithm in Java.
|
||||
/// <p>
|
||||
/// <b>References:</b>
|
||||
/// <ol>
|
||||
/// <li> Ronald L. Rivest,
|
||||
/// "<a href="http://www.roxen.com/rfc/rfc1320.html">
|
||||
/// The MD4 Message-Digest Algorithm</a>",
|
||||
/// IETF RFC-1320 (informational).
|
||||
/// </ol>
|
||||
/// <p><b>$Revision: 1.2 $</b>
|
||||
/// </remarks>
|
||||
/// <author>Raif S. Naffah</author>
|
||||
public class Md4 : MessageDigest
|
||||
{
|
||||
/// <summary>The size in bytes of the input block to the tranformation algorithm.</summary>
|
||||
/// <remarks>The size in bytes of the input block to the tranformation algorithm.</remarks>
|
||||
private const int BlockLength = 64;
|
||||
|
||||
/// <summary>4 32-bit words (interim result)</summary>
|
||||
private int[] _context = new int[4];
|
||||
/// <summary>4 32-bit words (interim result)</summary>
|
||||
private int[] _context = new int[4];
|
||||
|
||||
/// <summary>Number of bytes processed so far mod.</summary>
|
||||
/// <remarks>Number of bytes processed so far mod. 2 power of 64.</remarks>
|
||||
private long _count;
|
||||
/// <summary>Number of bytes processed so far mod.</summary>
|
||||
/// <remarks>Number of bytes processed so far mod. 2 power of 64.</remarks>
|
||||
private long _count;
|
||||
|
||||
/// <summary>512 bits input buffer = 16 x 32-bit words holds until reaches 512 bits.</summary>
|
||||
/// <remarks>512 bits input buffer = 16 x 32-bit words holds until reaches 512 bits.</remarks>
|
||||
private byte[] _buffer = new byte[BlockLength];
|
||||
/// <summary>512 bits input buffer = 16 x 32-bit words holds until reaches 512 bits.</summary>
|
||||
/// <remarks>512 bits input buffer = 16 x 32-bit words holds until reaches 512 bits.</remarks>
|
||||
private byte[] _buffer = new byte[BlockLength];
|
||||
|
||||
/// <summary>512 bits work buffer = 16 x 32-bit words</summary>
|
||||
private int[] _x = new int[16];
|
||||
/// <summary>512 bits work buffer = 16 x 32-bit words</summary>
|
||||
private int[] _x = new int[16];
|
||||
|
||||
public Md4()
|
||||
{
|
||||
// This file is currently unlocked (change this line if you lock the file)
|
||||
//
|
||||
// $Log: MD4.java,v $
|
||||
// Revision 1.2 1998/01/05 03:41:19 iang
|
||||
// Added references only.
|
||||
//
|
||||
// Revision 1.1.1.1 1997/11/03 22:36:56 hopwood
|
||||
// + Imported to CVS (tagged as 'start').
|
||||
//
|
||||
// Revision 0.1.0.0 1997/07/14 R. Naffah
|
||||
// + original version
|
||||
//
|
||||
// $Endlog$
|
||||
// MD4 specific object variables
|
||||
//...........................................................................
|
||||
// = 512 / 8;
|
||||
// Constructors
|
||||
//...........................................................................
|
||||
EngineReset();
|
||||
}
|
||||
public Md4()
|
||||
{
|
||||
// This file is currently unlocked (change this line if you lock the file)
|
||||
//
|
||||
// $Log: MD4.java,v $
|
||||
// Revision 1.2 1998/01/05 03:41:19 iang
|
||||
// Added references only.
|
||||
//
|
||||
// Revision 1.1.1.1 1997/11/03 22:36:56 hopwood
|
||||
// + Imported to CVS (tagged as 'start').
|
||||
//
|
||||
// Revision 0.1.0.0 1997/07/14 R. Naffah
|
||||
// + original version
|
||||
//
|
||||
// $Endlog$
|
||||
// MD4 specific object variables
|
||||
//...........................................................................
|
||||
// = 512 / 8;
|
||||
// Constructors
|
||||
//...........................................................................
|
||||
EngineReset();
|
||||
}
|
||||
|
||||
/// <summary>This constructor is here to implement cloneability of this class.</summary>
|
||||
/// <remarks>This constructor is here to implement cloneability of this class.</remarks>
|
||||
private Md4(Md4 md) : this()
|
||||
{
|
||||
_context = (int[])md._context.Clone();
|
||||
_buffer = (byte[])md._buffer.Clone();
|
||||
_count = md._count;
|
||||
}
|
||||
/// <summary>This constructor is here to implement cloneability of this class.</summary>
|
||||
/// <remarks>This constructor is here to implement cloneability of this class.</remarks>
|
||||
private Md4(Md4 md) : this()
|
||||
{
|
||||
_context = (int[])md._context.Clone();
|
||||
_buffer = (byte[])md._buffer.Clone();
|
||||
_count = md._count;
|
||||
}
|
||||
|
||||
// Cloneable method implementation
|
||||
//...........................................................................
|
||||
/// <summary>Returns a copy of this MD object.</summary>
|
||||
/// <remarks>Returns a copy of this MD object.</remarks>
|
||||
public object Clone()
|
||||
{
|
||||
return new Md4(this);
|
||||
}
|
||||
// Cloneable method implementation
|
||||
//...........................................................................
|
||||
/// <summary>Returns a copy of this MD object.</summary>
|
||||
/// <remarks>Returns a copy of this MD object.</remarks>
|
||||
public object Clone()
|
||||
{
|
||||
return new Md4(this);
|
||||
}
|
||||
|
||||
// JCE methods
|
||||
//...........................................................................
|
||||
/// <summary>
|
||||
/// Resets this object disregarding any temporary data present at the
|
||||
/// time of the invocation of this call.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Resets this object disregarding any temporary data present at the
|
||||
/// time of the invocation of this call.
|
||||
/// </remarks>
|
||||
protected void EngineReset()
|
||||
{
|
||||
// initial values of MD4 i.e. A, B, C, D
|
||||
// as per rfc-1320; they are low-order byte first
|
||||
_context[0] = unchecked(0x67452301);
|
||||
_context[1] = unchecked((int)(0xEFCDAB89));
|
||||
_context[2] = unchecked((int)(0x98BADCFE));
|
||||
_context[3] = unchecked(0x10325476);
|
||||
_count = 0L;
|
||||
for (int i = 0; i < BlockLength; i++)
|
||||
{
|
||||
_buffer[i] = 0;
|
||||
}
|
||||
}
|
||||
// JCE methods
|
||||
//...........................................................................
|
||||
/// <summary>
|
||||
/// Resets this object disregarding any temporary data present at the
|
||||
/// time of the invocation of this call.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Resets this object disregarding any temporary data present at the
|
||||
/// time of the invocation of this call.
|
||||
/// </remarks>
|
||||
protected void EngineReset()
|
||||
{
|
||||
// initial values of MD4 i.e. A, B, C, D
|
||||
// as per rfc-1320; they are low-order byte first
|
||||
_context[0] = unchecked(0x67452301);
|
||||
_context[1] = unchecked((int)(0xEFCDAB89));
|
||||
_context[2] = unchecked((int)(0x98BADCFE));
|
||||
_context[3] = unchecked(0x10325476);
|
||||
_count = 0L;
|
||||
for (int i = 0; i < BlockLength; i++)
|
||||
{
|
||||
_buffer[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Continues an MD4 message digest using the input byte.</summary>
|
||||
/// <remarks>Continues an MD4 message digest using the input byte.</remarks>
|
||||
protected void EngineUpdate(byte b)
|
||||
{
|
||||
// compute number of bytes still unhashed; ie. present in buffer
|
||||
int i = (int)(_count % BlockLength);
|
||||
_count++;
|
||||
// update number of bytes
|
||||
_buffer[i] = b;
|
||||
if (i == BlockLength - 1)
|
||||
{
|
||||
Transform(_buffer, 0);
|
||||
}
|
||||
}
|
||||
/// <summary>Continues an MD4 message digest using the input byte.</summary>
|
||||
/// <remarks>Continues an MD4 message digest using the input byte.</remarks>
|
||||
protected void EngineUpdate(byte b)
|
||||
{
|
||||
// compute number of bytes still unhashed; ie. present in buffer
|
||||
int i = (int)(_count % BlockLength);
|
||||
_count++;
|
||||
// update number of bytes
|
||||
_buffer[i] = b;
|
||||
if (i == BlockLength - 1)
|
||||
{
|
||||
Transform(_buffer, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>MD4 block update operation.</summary>
|
||||
/// <remarks>
|
||||
/// MD4 block update operation.
|
||||
/// <p>
|
||||
/// Continues an MD4 message digest operation, by filling the buffer,
|
||||
/// transform(ing) data in 512-bit message block(s), updating the variables
|
||||
/// context and count, and leaving (buffering) the remaining bytes in buffer
|
||||
/// for the next update or finish.
|
||||
/// </remarks>
|
||||
/// <param name="input">input block</param>
|
||||
/// <param name="offset">start of meaningful bytes in input</param>
|
||||
/// <param name="len">count of bytes in input block to consider</param>
|
||||
protected void EngineUpdate(byte[] input, int offset, int len)
|
||||
{
|
||||
// make sure we don't exceed input's allocated size/length
|
||||
if (offset < 0 || len < 0 || (long)offset + len > input.Length)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
// compute number of bytes still unhashed; ie. present in buffer
|
||||
int bufferNdx = (int)(_count % BlockLength);
|
||||
_count += len;
|
||||
// update number of bytes
|
||||
int partLen = BlockLength - bufferNdx;
|
||||
int i = 0;
|
||||
if (len >= partLen)
|
||||
{
|
||||
Array.Copy(input, offset, _buffer, bufferNdx, partLen);
|
||||
Transform(_buffer, 0);
|
||||
for (i = partLen; i + BlockLength - 1 < len; i += BlockLength)
|
||||
{
|
||||
Transform(input, offset + i);
|
||||
}
|
||||
bufferNdx = 0;
|
||||
}
|
||||
// buffer remaining input
|
||||
if (i < len)
|
||||
{
|
||||
Array.Copy(input, offset + i, _buffer, bufferNdx, len - i);
|
||||
}
|
||||
}
|
||||
/// <summary>MD4 block update operation.</summary>
|
||||
/// <remarks>
|
||||
/// MD4 block update operation.
|
||||
/// <p>
|
||||
/// Continues an MD4 message digest operation, by filling the buffer,
|
||||
/// transform(ing) data in 512-bit message block(s), updating the variables
|
||||
/// context and count, and leaving (buffering) the remaining bytes in buffer
|
||||
/// for the next update or finish.
|
||||
/// </remarks>
|
||||
/// <param name="input">input block</param>
|
||||
/// <param name="offset">start of meaningful bytes in input</param>
|
||||
/// <param name="len">count of bytes in input block to consider</param>
|
||||
protected void EngineUpdate(byte[] input, int offset, int len)
|
||||
{
|
||||
// make sure we don't exceed input's allocated size/length
|
||||
if (offset < 0 || len < 0 || (long)offset + len > input.Length)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
// compute number of bytes still unhashed; ie. present in buffer
|
||||
int bufferNdx = (int)(_count % BlockLength);
|
||||
_count += len;
|
||||
// update number of bytes
|
||||
int partLen = BlockLength - bufferNdx;
|
||||
int i = 0;
|
||||
if (len >= partLen)
|
||||
{
|
||||
Array.Copy(input, offset, _buffer, bufferNdx, partLen);
|
||||
Transform(_buffer, 0);
|
||||
for (i = partLen; i + BlockLength - 1 < len; i += BlockLength)
|
||||
{
|
||||
Transform(input, offset + i);
|
||||
}
|
||||
bufferNdx = 0;
|
||||
}
|
||||
// buffer remaining input
|
||||
if (i < len)
|
||||
{
|
||||
Array.Copy(input, offset + i, _buffer, bufferNdx, len - i);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Completes the hash computation by performing final operations such
|
||||
/// as padding.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Completes the hash computation by performing final operations such
|
||||
/// as padding. At the return of this engineDigest, the MD engine is
|
||||
/// reset.
|
||||
/// </remarks>
|
||||
/// <returns>the array of bytes for the resulting hash value.</returns>
|
||||
protected byte[] EngineDigest()
|
||||
{
|
||||
// pad output to 56 mod 64; as RFC1320 puts it: congruent to 448 mod 512
|
||||
int bufferNdx = (int)(_count % BlockLength);
|
||||
int padLen = (bufferNdx < 56) ? (56 - bufferNdx) : (120 - bufferNdx);
|
||||
// padding is alwas binary 1 followed by binary 0s
|
||||
byte[] tail = new byte[padLen + 8];
|
||||
tail[0] = unchecked(unchecked(0x80));
|
||||
// append length before final transform:
|
||||
// save number of bits, casting the long to an array of 8 bytes
|
||||
// save low-order byte first.
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
tail[padLen + i] = unchecked((byte)((long)(((ulong)(_count * 8)) >> (8 * i))));
|
||||
}
|
||||
EngineUpdate(tail, 0, tail.Length);
|
||||
byte[] result = new byte[16];
|
||||
// cast this MD4's context (array of 4 ints) into an array of 16 bytes.
|
||||
for (int i1 = 0; i1 < 4; i1++)
|
||||
{
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
result[i1 * 4 + j] = unchecked((byte)((int)(((uint)_context[i1]) >> (8 * j))));
|
||||
}
|
||||
}
|
||||
// reset the engine
|
||||
EngineReset();
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// Completes the hash computation by performing final operations such
|
||||
/// as padding.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Completes the hash computation by performing final operations such
|
||||
/// as padding. At the return of this engineDigest, the MD engine is
|
||||
/// reset.
|
||||
/// </remarks>
|
||||
/// <returns>the array of bytes for the resulting hash value.</returns>
|
||||
protected byte[] EngineDigest()
|
||||
{
|
||||
// pad output to 56 mod 64; as RFC1320 puts it: congruent to 448 mod 512
|
||||
int bufferNdx = (int)(_count % BlockLength);
|
||||
int padLen = (bufferNdx < 56) ? (56 - bufferNdx) : (120 - bufferNdx);
|
||||
// padding is alwas binary 1 followed by binary 0s
|
||||
byte[] tail = new byte[padLen + 8];
|
||||
tail[0] = unchecked(unchecked(0x80));
|
||||
// append length before final transform:
|
||||
// save number of bits, casting the long to an array of 8 bytes
|
||||
// save low-order byte first.
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
tail[padLen + i] = unchecked((byte)((long)(((ulong)(_count * 8)) >> (8 * i))));
|
||||
}
|
||||
EngineUpdate(tail, 0, tail.Length);
|
||||
byte[] result = new byte[16];
|
||||
// cast this MD4's context (array of 4 ints) into an array of 16 bytes.
|
||||
for (int i1 = 0; i1 < 4; i1++)
|
||||
{
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
result[i1 * 4 + j] = unchecked((byte)((int)(((uint)_context[i1]) >> (8 * j))));
|
||||
}
|
||||
}
|
||||
// reset the engine
|
||||
EngineReset();
|
||||
return result;
|
||||
}
|
||||
|
||||
// own methods
|
||||
//...........................................................................
|
||||
/// <summary>MD4 basic transformation.</summary>
|
||||
/// <remarks>
|
||||
/// MD4 basic transformation.
|
||||
/// <p>
|
||||
/// Transforms context based on 512 bits from input block starting
|
||||
/// from the offset'th byte.
|
||||
/// </remarks>
|
||||
/// <param name="block">input sub-array.</param>
|
||||
/// <param name="offset">starting position of sub-array.</param>
|
||||
private void Transform(byte[] block, int offset)
|
||||
{
|
||||
// encodes 64 bytes from input block into an array of 16 32-bit
|
||||
// entities. Use A as a temp var.
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
_x[i] = (block[offset++] & unchecked(0xFF)) | (block[offset++] & unchecked(
|
||||
0xFF)) << 8 | (block[offset++] & unchecked(0xFF)) << 16 | (block[offset
|
||||
++] & unchecked(0xFF)) << 24;
|
||||
}
|
||||
int a = _context[0];
|
||||
int b = _context[1];
|
||||
int c = _context[2];
|
||||
int d = _context[3];
|
||||
a = Ff(a, b, c, d, _x[0], 3);
|
||||
d = Ff(d, a, b, c, _x[1], 7);
|
||||
c = Ff(c, d, a, b, _x[2], 11);
|
||||
b = Ff(b, c, d, a, _x[3], 19);
|
||||
a = Ff(a, b, c, d, _x[4], 3);
|
||||
d = Ff(d, a, b, c, _x[5], 7);
|
||||
c = Ff(c, d, a, b, _x[6], 11);
|
||||
b = Ff(b, c, d, a, _x[7], 19);
|
||||
a = Ff(a, b, c, d, _x[8], 3);
|
||||
d = Ff(d, a, b, c, _x[9], 7);
|
||||
c = Ff(c, d, a, b, _x[10], 11);
|
||||
b = Ff(b, c, d, a, _x[11], 19);
|
||||
a = Ff(a, b, c, d, _x[12], 3);
|
||||
d = Ff(d, a, b, c, _x[13], 7);
|
||||
c = Ff(c, d, a, b, _x[14], 11);
|
||||
b = Ff(b, c, d, a, _x[15], 19);
|
||||
a = Gg(a, b, c, d, _x[0], 3);
|
||||
d = Gg(d, a, b, c, _x[4], 5);
|
||||
c = Gg(c, d, a, b, _x[8], 9);
|
||||
b = Gg(b, c, d, a, _x[12], 13);
|
||||
a = Gg(a, b, c, d, _x[1], 3);
|
||||
d = Gg(d, a, b, c, _x[5], 5);
|
||||
c = Gg(c, d, a, b, _x[9], 9);
|
||||
b = Gg(b, c, d, a, _x[13], 13);
|
||||
a = Gg(a, b, c, d, _x[2], 3);
|
||||
d = Gg(d, a, b, c, _x[6], 5);
|
||||
c = Gg(c, d, a, b, _x[10], 9);
|
||||
b = Gg(b, c, d, a, _x[14], 13);
|
||||
a = Gg(a, b, c, d, _x[3], 3);
|
||||
d = Gg(d, a, b, c, _x[7], 5);
|
||||
c = Gg(c, d, a, b, _x[11], 9);
|
||||
b = Gg(b, c, d, a, _x[15], 13);
|
||||
a = Hh(a, b, c, d, _x[0], 3);
|
||||
d = Hh(d, a, b, c, _x[8], 9);
|
||||
c = Hh(c, d, a, b, _x[4], 11);
|
||||
b = Hh(b, c, d, a, _x[12], 15);
|
||||
a = Hh(a, b, c, d, _x[2], 3);
|
||||
d = Hh(d, a, b, c, _x[10], 9);
|
||||
c = Hh(c, d, a, b, _x[6], 11);
|
||||
b = Hh(b, c, d, a, _x[14], 15);
|
||||
a = Hh(a, b, c, d, _x[1], 3);
|
||||
d = Hh(d, a, b, c, _x[9], 9);
|
||||
c = Hh(c, d, a, b, _x[5], 11);
|
||||
b = Hh(b, c, d, a, _x[13], 15);
|
||||
a = Hh(a, b, c, d, _x[3], 3);
|
||||
d = Hh(d, a, b, c, _x[11], 9);
|
||||
c = Hh(c, d, a, b, _x[7], 11);
|
||||
b = Hh(b, c, d, a, _x[15], 15);
|
||||
_context[0] += a;
|
||||
_context[1] += b;
|
||||
_context[2] += c;
|
||||
_context[3] += d;
|
||||
}
|
||||
// own methods
|
||||
//...........................................................................
|
||||
/// <summary>MD4 basic transformation.</summary>
|
||||
/// <remarks>
|
||||
/// MD4 basic transformation.
|
||||
/// <p>
|
||||
/// Transforms context based on 512 bits from input block starting
|
||||
/// from the offset'th byte.
|
||||
/// </remarks>
|
||||
/// <param name="block">input sub-array.</param>
|
||||
/// <param name="offset">starting position of sub-array.</param>
|
||||
private void Transform(byte[] block, int offset)
|
||||
{
|
||||
// encodes 64 bytes from input block into an array of 16 32-bit
|
||||
// entities. Use A as a temp var.
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
_x[i] = (block[offset++] & unchecked(0xFF)) | (block[offset++] & unchecked(
|
||||
0xFF)) << 8 | (block[offset++] & unchecked(0xFF)) << 16 | (block[offset
|
||||
++] & unchecked(0xFF)) << 24;
|
||||
}
|
||||
int a = _context[0];
|
||||
int b = _context[1];
|
||||
int c = _context[2];
|
||||
int d = _context[3];
|
||||
a = Ff(a, b, c, d, _x[0], 3);
|
||||
d = Ff(d, a, b, c, _x[1], 7);
|
||||
c = Ff(c, d, a, b, _x[2], 11);
|
||||
b = Ff(b, c, d, a, _x[3], 19);
|
||||
a = Ff(a, b, c, d, _x[4], 3);
|
||||
d = Ff(d, a, b, c, _x[5], 7);
|
||||
c = Ff(c, d, a, b, _x[6], 11);
|
||||
b = Ff(b, c, d, a, _x[7], 19);
|
||||
a = Ff(a, b, c, d, _x[8], 3);
|
||||
d = Ff(d, a, b, c, _x[9], 7);
|
||||
c = Ff(c, d, a, b, _x[10], 11);
|
||||
b = Ff(b, c, d, a, _x[11], 19);
|
||||
a = Ff(a, b, c, d, _x[12], 3);
|
||||
d = Ff(d, a, b, c, _x[13], 7);
|
||||
c = Ff(c, d, a, b, _x[14], 11);
|
||||
b = Ff(b, c, d, a, _x[15], 19);
|
||||
a = Gg(a, b, c, d, _x[0], 3);
|
||||
d = Gg(d, a, b, c, _x[4], 5);
|
||||
c = Gg(c, d, a, b, _x[8], 9);
|
||||
b = Gg(b, c, d, a, _x[12], 13);
|
||||
a = Gg(a, b, c, d, _x[1], 3);
|
||||
d = Gg(d, a, b, c, _x[5], 5);
|
||||
c = Gg(c, d, a, b, _x[9], 9);
|
||||
b = Gg(b, c, d, a, _x[13], 13);
|
||||
a = Gg(a, b, c, d, _x[2], 3);
|
||||
d = Gg(d, a, b, c, _x[6], 5);
|
||||
c = Gg(c, d, a, b, _x[10], 9);
|
||||
b = Gg(b, c, d, a, _x[14], 13);
|
||||
a = Gg(a, b, c, d, _x[3], 3);
|
||||
d = Gg(d, a, b, c, _x[7], 5);
|
||||
c = Gg(c, d, a, b, _x[11], 9);
|
||||
b = Gg(b, c, d, a, _x[15], 13);
|
||||
a = Hh(a, b, c, d, _x[0], 3);
|
||||
d = Hh(d, a, b, c, _x[8], 9);
|
||||
c = Hh(c, d, a, b, _x[4], 11);
|
||||
b = Hh(b, c, d, a, _x[12], 15);
|
||||
a = Hh(a, b, c, d, _x[2], 3);
|
||||
d = Hh(d, a, b, c, _x[10], 9);
|
||||
c = Hh(c, d, a, b, _x[6], 11);
|
||||
b = Hh(b, c, d, a, _x[14], 15);
|
||||
a = Hh(a, b, c, d, _x[1], 3);
|
||||
d = Hh(d, a, b, c, _x[9], 9);
|
||||
c = Hh(c, d, a, b, _x[5], 11);
|
||||
b = Hh(b, c, d, a, _x[13], 15);
|
||||
a = Hh(a, b, c, d, _x[3], 3);
|
||||
d = Hh(d, a, b, c, _x[11], 9);
|
||||
c = Hh(c, d, a, b, _x[7], 11);
|
||||
b = Hh(b, c, d, a, _x[15], 15);
|
||||
_context[0] += a;
|
||||
_context[1] += b;
|
||||
_context[2] += c;
|
||||
_context[3] += d;
|
||||
}
|
||||
|
||||
// The basic MD4 atomic functions.
|
||||
private int Ff(int a, int b, int c, int d, int x, int s)
|
||||
{
|
||||
int t = a + ((b & c) | (~b & d)) + x;
|
||||
return t << s | (int)(((uint)t) >> (32 - s));
|
||||
}
|
||||
// The basic MD4 atomic functions.
|
||||
private int Ff(int a, int b, int c, int d, int x, int s)
|
||||
{
|
||||
int t = a + ((b & c) | (~b & d)) + x;
|
||||
return t << s | (int)(((uint)t) >> (32 - s));
|
||||
}
|
||||
|
||||
private int Gg(int a, int b, int c, int d, int x, int s)
|
||||
{
|
||||
int t = a + ((b & (c | d)) | (c & d)) + x + unchecked(0x5A827999);
|
||||
return t << s | (int)(((uint)t) >> (32 - s));
|
||||
}
|
||||
private int Gg(int a, int b, int c, int d, int x, int s)
|
||||
{
|
||||
int t = a + ((b & (c | d)) | (c & d)) + x + unchecked(0x5A827999);
|
||||
return t << s | (int)(((uint)t) >> (32 - s));
|
||||
}
|
||||
|
||||
private int Hh(int a, int b, int c, int d, int x, int s)
|
||||
{
|
||||
int t = a + (b ^ c ^ d) + x + unchecked(0x6ED9EBA1);
|
||||
return t << s | (int)(((uint)t) >> (32 - s));
|
||||
}
|
||||
private int Hh(int a, int b, int c, int d, int x, int s)
|
||||
{
|
||||
int t = a + (b ^ c ^ d) + x + unchecked(0x6ED9EBA1);
|
||||
return t << s | (int)(((uint)t) >> (32 - s));
|
||||
}
|
||||
|
||||
public override byte[] Digest()
|
||||
{
|
||||
return EngineDigest();
|
||||
}
|
||||
public override byte[] Digest()
|
||||
{
|
||||
return EngineDigest();
|
||||
}
|
||||
|
||||
public override int GetDigestLength()
|
||||
{
|
||||
return EngineDigest().Length;
|
||||
}
|
||||
public override int GetDigestLength()
|
||||
{
|
||||
return EngineDigest().Length;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
EngineReset();
|
||||
}
|
||||
public override void Reset()
|
||||
{
|
||||
EngineReset();
|
||||
}
|
||||
|
||||
public override void Update(byte[] b)
|
||||
{
|
||||
public override void Update(byte[] b)
|
||||
{
|
||||
EngineUpdate(b, 0, b.Length);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(byte b)
|
||||
{
|
||||
EngineUpdate(b);
|
||||
}
|
||||
public override void Update(byte b)
|
||||
{
|
||||
EngineUpdate(b);
|
||||
}
|
||||
|
||||
public override void Update(byte[] b, int offset, int len)
|
||||
{
|
||||
EngineUpdate(b, offset, len);
|
||||
}
|
||||
}
|
||||
public override void Update(byte[] b, int offset, int len)
|
||||
{
|
||||
EngineUpdate(b, offset, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,53 +16,53 @@
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
namespace SharpCifs.Util
|
||||
{
|
||||
public class Rc4
|
||||
{
|
||||
internal byte[] S;
|
||||
public class Rc4
|
||||
{
|
||||
internal byte[] S;
|
||||
|
||||
internal int I;
|
||||
internal int I;
|
||||
|
||||
internal int J;
|
||||
internal int J;
|
||||
|
||||
public Rc4()
|
||||
{
|
||||
}
|
||||
public Rc4()
|
||||
{
|
||||
}
|
||||
|
||||
public Rc4(byte[] key)
|
||||
{
|
||||
Init(key, 0, key.Length);
|
||||
}
|
||||
public Rc4(byte[] key)
|
||||
{
|
||||
Init(key, 0, key.Length);
|
||||
}
|
||||
|
||||
public virtual void Init(byte[] key, int ki, int klen)
|
||||
{
|
||||
S = new byte[256];
|
||||
for (I = 0; I < 256; I++)
|
||||
{
|
||||
S[I] = unchecked((byte)I);
|
||||
}
|
||||
for (I = J = 0; I < 256; I++)
|
||||
{
|
||||
J = (J + key[ki + I % klen] + S[I]) & unchecked(0xff);
|
||||
byte t = S[I];
|
||||
S[I] = S[J];
|
||||
S[J] = t;
|
||||
}
|
||||
I = J = 0;
|
||||
}
|
||||
public virtual void Init(byte[] key, int ki, int klen)
|
||||
{
|
||||
S = new byte[256];
|
||||
for (I = 0; I < 256; I++)
|
||||
{
|
||||
S[I] = unchecked((byte)I);
|
||||
}
|
||||
for (I = J = 0; I < 256; I++)
|
||||
{
|
||||
J = (J + key[ki + I % klen] + S[I]) & unchecked(0xff);
|
||||
byte t = S[I];
|
||||
S[I] = S[J];
|
||||
S[J] = t;
|
||||
}
|
||||
I = J = 0;
|
||||
}
|
||||
|
||||
public virtual void Update(byte[] src, int soff, int slen, byte[] dst, int doff)
|
||||
{
|
||||
int slim;
|
||||
slim = soff + slen;
|
||||
while (soff < slim)
|
||||
{
|
||||
I = (I + 1) & unchecked(0xff);
|
||||
J = (J + S[I]) & unchecked(0xff);
|
||||
byte t = S[I];
|
||||
S[I] = S[J];
|
||||
S[J] = t;
|
||||
dst[doff++] = unchecked((byte)(src[soff++] ^ S[(S[I] + S[J]) & unchecked(0xff)]));
|
||||
}
|
||||
}
|
||||
}
|
||||
public virtual void Update(byte[] src, int soff, int slen, byte[] dst, int doff)
|
||||
{
|
||||
int slim;
|
||||
slim = soff + slen;
|
||||
while (soff < slim)
|
||||
{
|
||||
I = (I + 1) & unchecked(0xff);
|
||||
J = (J + S[I]) & unchecked(0xff);
|
||||
byte t = S[I];
|
||||
S[I] = S[J];
|
||||
S[J] = t;
|
||||
dst[doff++] = unchecked((byte)(src[soff++] ^ S[(S[I] + S[J]) & unchecked(0xff)]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,159 +6,146 @@ using System.Linq;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public abstract class AbstractMap<T, TU> : IDictionary<T, TU>
|
||||
{
|
||||
public virtual void Clear()
|
||||
{
|
||||
EntrySet().Clear();
|
||||
}
|
||||
{
|
||||
public virtual void Clear ()
|
||||
{
|
||||
EntrySet ().Clear ();
|
||||
}
|
||||
|
||||
public virtual bool ContainsKey(object name)
|
||||
{
|
||||
return EntrySet().Any(p => p.Key.Equals((T)name));
|
||||
}
|
||||
public virtual bool ContainsKey (object name)
|
||||
{
|
||||
return EntrySet ().Any (p => p.Key.Equals ((T)name));
|
||||
}
|
||||
|
||||
public abstract ICollection<KeyValuePair<T, TU>> EntrySet();
|
||||
public abstract ICollection<KeyValuePair<T, TU>> EntrySet ();
|
||||
|
||||
public virtual TU Get(object key)
|
||||
{
|
||||
return EntrySet().Where(p => p.Key.Equals(key)).Select(p => p.Value).FirstOrDefault();
|
||||
}
|
||||
public virtual TU Get (object key)
|
||||
{
|
||||
return EntrySet ().Where (p => p.Key.Equals (key)).Select (p => p.Value).FirstOrDefault ();
|
||||
}
|
||||
|
||||
protected virtual IEnumerator<KeyValuePair<T, TU>> InternalGetEnumerator()
|
||||
{
|
||||
return EntrySet().GetEnumerator();
|
||||
}
|
||||
protected virtual IEnumerator<KeyValuePair<T, TU>> InternalGetEnumerator ()
|
||||
{
|
||||
return EntrySet ().GetEnumerator ();
|
||||
}
|
||||
|
||||
public virtual bool IsEmpty()
|
||||
{
|
||||
return !EntrySet().Any();
|
||||
}
|
||||
public virtual bool IsEmpty ()
|
||||
{
|
||||
return !EntrySet ().Any ();
|
||||
}
|
||||
|
||||
public virtual TU Put(T key, TU value)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
public virtual TU Put (T key, TU value)
|
||||
{
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
|
||||
public virtual TU Remove(object key)
|
||||
{
|
||||
Iterator<TU> iterator = EntrySet() as Iterator<TU>;
|
||||
if (iterator == null)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
while (iterator.HasNext())
|
||||
{
|
||||
TU local = iterator.Next();
|
||||
if (local.Equals((T)key))
|
||||
{
|
||||
iterator.Remove();
|
||||
return local;
|
||||
}
|
||||
}
|
||||
return default(TU);
|
||||
}
|
||||
public virtual TU Remove (object key)
|
||||
{
|
||||
Iterator<TU> iterator = EntrySet () as Iterator<TU>;
|
||||
if (iterator == null) {
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
while (iterator.HasNext ()) {
|
||||
TU local = iterator.Next ();
|
||||
if (local.Equals ((T)key)) {
|
||||
iterator.Remove ();
|
||||
return local;
|
||||
}
|
||||
}
|
||||
return default(TU);
|
||||
}
|
||||
|
||||
void ICollection<KeyValuePair<T, TU>>.Add(KeyValuePair<T, TU> item)
|
||||
{
|
||||
Put(item.Key, item.Value);
|
||||
}
|
||||
void ICollection<KeyValuePair<T, TU>>.Add (KeyValuePair<T, TU> item)
|
||||
{
|
||||
Put (item.Key, item.Value);
|
||||
}
|
||||
|
||||
bool ICollection<KeyValuePair<T, TU>>.Contains(KeyValuePair<T, TU> item)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
bool ICollection<KeyValuePair<T, TU>>.Contains (KeyValuePair<T, TU> item)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
void ICollection<KeyValuePair<T, TU>>.CopyTo(KeyValuePair<T, TU>[] array, int arrayIndex)
|
||||
{
|
||||
EntrySet().CopyTo(array, arrayIndex);
|
||||
}
|
||||
void ICollection<KeyValuePair<T, TU>>.CopyTo (KeyValuePair<T, TU>[] array, int arrayIndex)
|
||||
{
|
||||
EntrySet ().CopyTo (array, arrayIndex);
|
||||
}
|
||||
|
||||
bool ICollection<KeyValuePair<T, TU>>.Remove(KeyValuePair<T, TU> item)
|
||||
{
|
||||
Remove(item.Key);
|
||||
return true;
|
||||
}
|
||||
bool ICollection<KeyValuePair<T, TU>>.Remove (KeyValuePair<T, TU> item)
|
||||
{
|
||||
Remove (item.Key);
|
||||
return true;
|
||||
}
|
||||
|
||||
void IDictionary<T, TU>.Add(T key, TU value)
|
||||
{
|
||||
Put(key, value);
|
||||
}
|
||||
void IDictionary<T, TU>.Add (T key, TU value)
|
||||
{
|
||||
Put (key, value);
|
||||
}
|
||||
|
||||
bool IDictionary<T, TU>.ContainsKey(T key)
|
||||
{
|
||||
return ContainsKey(key);
|
||||
}
|
||||
bool IDictionary<T, TU>.ContainsKey (T key)
|
||||
{
|
||||
return ContainsKey (key);
|
||||
}
|
||||
|
||||
bool IDictionary<T, TU>.Remove(T key)
|
||||
{
|
||||
if (ContainsKey(key))
|
||||
{
|
||||
Remove(key);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool IDictionary<T, TU>.Remove (T key)
|
||||
{
|
||||
if (ContainsKey (key)) {
|
||||
Remove (key);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IDictionary<T, TU>.TryGetValue(T key, out TU value)
|
||||
{
|
||||
if (ContainsKey(key))
|
||||
{
|
||||
value = Get(key);
|
||||
return true;
|
||||
}
|
||||
value = default(TU);
|
||||
return false;
|
||||
}
|
||||
bool IDictionary<T, TU>.TryGetValue (T key, out TU value)
|
||||
{
|
||||
if (ContainsKey (key)) {
|
||||
value = Get (key);
|
||||
return true;
|
||||
}
|
||||
value = default(TU);
|
||||
return false;
|
||||
}
|
||||
|
||||
IEnumerator<KeyValuePair<T, TU>> IEnumerable<KeyValuePair<T, TU>>.GetEnumerator()
|
||||
{
|
||||
return InternalGetEnumerator();
|
||||
}
|
||||
IEnumerator<KeyValuePair<T, TU>> IEnumerable<KeyValuePair<T, TU>>.GetEnumerator ()
|
||||
{
|
||||
return InternalGetEnumerator ();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return InternalGetEnumerator();
|
||||
}
|
||||
IEnumerator IEnumerable.GetEnumerator ()
|
||||
{
|
||||
return InternalGetEnumerator ();
|
||||
}
|
||||
|
||||
public virtual int Count
|
||||
{
|
||||
get { return EntrySet().Count; }
|
||||
}
|
||||
public virtual int Count {
|
||||
get { return EntrySet ().Count; }
|
||||
}
|
||||
|
||||
public TU this[T key]
|
||||
{
|
||||
get { return Get(key); }
|
||||
set { Put(key, value); }
|
||||
}
|
||||
public TU this[T key] {
|
||||
get { return Get (key); }
|
||||
set { Put (key, value); }
|
||||
}
|
||||
|
||||
public virtual IEnumerable<T> Keys
|
||||
{
|
||||
get { return EntrySet().Select(p => p.Key); }
|
||||
}
|
||||
public virtual IEnumerable<T> Keys {
|
||||
get { return EntrySet ().Select (p => p.Key); }
|
||||
}
|
||||
|
||||
int ICollection<KeyValuePair<T, TU>>.Count
|
||||
{
|
||||
get { return Count; }
|
||||
}
|
||||
int ICollection<KeyValuePair<T, TU>>.Count {
|
||||
get { return Count; }
|
||||
}
|
||||
|
||||
bool ICollection<KeyValuePair<T, TU>>.IsReadOnly
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
bool ICollection<KeyValuePair<T, TU>>.IsReadOnly {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
ICollection<T> IDictionary<T, TU>.Keys
|
||||
{
|
||||
get { return Keys.ToList(); }
|
||||
}
|
||||
ICollection<T> IDictionary<T, TU>.Keys {
|
||||
get { return Keys.ToList (); }
|
||||
}
|
||||
|
||||
ICollection<TU> IDictionary<T, TU>.Values
|
||||
{
|
||||
get { return Values.ToList(); }
|
||||
}
|
||||
ICollection<TU> IDictionary<T, TU>.Values {
|
||||
get { return Values.ToList (); }
|
||||
}
|
||||
|
||||
public virtual IEnumerable<TU> Values
|
||||
{
|
||||
get { return EntrySet().Select(p => p.Value); }
|
||||
}
|
||||
}
|
||||
public virtual IEnumerable<TU> Values {
|
||||
get { return EntrySet ().Select (p => p.Value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,57 +5,55 @@ using System.Linq;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public class Arrays
|
||||
{
|
||||
public static List<T> AsList<T>(params T[] array)
|
||||
{
|
||||
return array.ToList();
|
||||
}
|
||||
{
|
||||
public static List<T> AsList<T> (params T[] array)
|
||||
{
|
||||
return array.ToList ();
|
||||
}
|
||||
|
||||
public static bool Equals<T>(T[] a1, T[] a2)
|
||||
{
|
||||
if (a1.Length != a2.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return !a1.Where((t, i) => !t.Equals(a2[i])).Any();
|
||||
}
|
||||
public static bool Equals<T> (T[] a1, T[] a2)
|
||||
{
|
||||
if (a1.Length != a2.Length) {
|
||||
return false;
|
||||
}
|
||||
return !a1.Where((t, i) => !t.Equals(a2[i])).Any();
|
||||
}
|
||||
|
||||
public static void Fill<T>(T[] array, T val)
|
||||
{
|
||||
Fill(array, 0, array.Length, val);
|
||||
}
|
||||
public static void Fill<T> (T[] array, T val)
|
||||
{
|
||||
Fill (array, 0, array.Length, val);
|
||||
}
|
||||
|
||||
public static void Fill<T>(T[] array, int start, int end, T val)
|
||||
{
|
||||
for (int i = start; i < end; i++)
|
||||
{
|
||||
array[i] = val;
|
||||
}
|
||||
}
|
||||
public static void Fill<T> (T[] array, int start, int end, T val)
|
||||
{
|
||||
for (int i = start; i < end; i++) {
|
||||
array[i] = val;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Sort(string[] array)
|
||||
{
|
||||
Array.Sort(array, (s1, s2) => string.CompareOrdinal(s1, s2));
|
||||
}
|
||||
public static void Sort (string[] array)
|
||||
{
|
||||
Array.Sort (array, (s1,s2) => string.CompareOrdinal (s1,s2));
|
||||
}
|
||||
|
||||
public static void Sort<T>(T[] array)
|
||||
{
|
||||
Array.Sort(array);
|
||||
}
|
||||
public static void Sort<T> (T[] array)
|
||||
{
|
||||
Array.Sort (array);
|
||||
}
|
||||
|
||||
public static void Sort<T>(T[] array, IComparer<T> c)
|
||||
{
|
||||
Array.Sort(array, c);
|
||||
}
|
||||
public static void Sort<T> (T[] array, IComparer<T> c)
|
||||
{
|
||||
Array.Sort (array, c);
|
||||
}
|
||||
|
||||
public static void Sort<T>(T[] array, int start, int count)
|
||||
{
|
||||
Array.Sort(array, start, count);
|
||||
}
|
||||
public static void Sort<T> (T[] array, int start, int count)
|
||||
{
|
||||
Array.Sort (array, start, count);
|
||||
}
|
||||
|
||||
public static void Sort<T>(T[] array, int start, int count, IComparer<T> c)
|
||||
{
|
||||
Array.Sort(array, start, count, c);
|
||||
}
|
||||
}
|
||||
public static void Sort<T> (T[] array, int start, int count, IComparer<T> c)
|
||||
{
|
||||
Array.Sort (array, start, count, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ using System.IO;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public class BufferedReader : StreamReader
|
||||
{
|
||||
public BufferedReader(InputStreamReader r) : base(r.BaseStream)
|
||||
{
|
||||
}
|
||||
}
|
||||
{
|
||||
public BufferedReader (InputStreamReader r) : base(r.BaseStream)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,31 +28,31 @@ using System.IO;
|
||||
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public class BufferedWriter
|
||||
{
|
||||
StreamWriter _writer;
|
||||
|
||||
public BufferedWriter(StreamWriter w)
|
||||
{
|
||||
_writer = w;
|
||||
}
|
||||
|
||||
public void Write(string s)
|
||||
{
|
||||
_writer.Write(s);
|
||||
}
|
||||
|
||||
public void NewLine()
|
||||
{
|
||||
_writer.WriteLine();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
public class BufferedWriter
|
||||
{
|
||||
StreamWriter _writer;
|
||||
|
||||
public BufferedWriter (StreamWriter w)
|
||||
{
|
||||
_writer = w;
|
||||
}
|
||||
|
||||
public void Write (string s)
|
||||
{
|
||||
_writer.Write (s);
|
||||
}
|
||||
|
||||
public void NewLine ()
|
||||
{
|
||||
_writer.WriteLine ();
|
||||
}
|
||||
|
||||
public void Close ()
|
||||
{
|
||||
//Stream.`Close` method deleted
|
||||
//_writer.Close ();
|
||||
//_writer.Close ();
|
||||
_writer.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal class CharBuffer : CharSequence
|
||||
{
|
||||
internal string Wrapped;
|
||||
{
|
||||
internal string Wrapped;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Wrapped;
|
||||
}
|
||||
public override string ToString ()
|
||||
{
|
||||
return Wrapped;
|
||||
}
|
||||
|
||||
public static CharBuffer Wrap(string str)
|
||||
{
|
||||
CharBuffer buffer = new CharBuffer();
|
||||
buffer.Wrapped = str;
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
public static CharBuffer Wrap (string str)
|
||||
{
|
||||
CharBuffer buffer = new CharBuffer ();
|
||||
buffer.Wrapped = str;
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,31 +2,31 @@ using System.Text;
|
||||
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public class CharSequence
|
||||
{
|
||||
public static implicit operator CharSequence(string str)
|
||||
{
|
||||
return new StringCharSequence(str);
|
||||
}
|
||||
|
||||
public static implicit operator CharSequence(StringBuilder str)
|
||||
{
|
||||
return new StringCharSequence(str.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
class StringCharSequence : CharSequence
|
||||
{
|
||||
string _str;
|
||||
|
||||
public StringCharSequence(string str)
|
||||
{
|
||||
this._str = str;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _str;
|
||||
}
|
||||
}
|
||||
public class CharSequence
|
||||
{
|
||||
public static implicit operator CharSequence (string str)
|
||||
{
|
||||
return new StringCharSequence (str);
|
||||
}
|
||||
|
||||
public static implicit operator CharSequence (StringBuilder str)
|
||||
{
|
||||
return new StringCharSequence (str.ToString ());
|
||||
}
|
||||
}
|
||||
|
||||
class StringCharSequence: CharSequence
|
||||
{
|
||||
string _str;
|
||||
|
||||
public StringCharSequence (string str)
|
||||
{
|
||||
this._str = str;
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return _str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,47 +5,45 @@ using System.Collections.ObjectModel;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal static class Collections<T>
|
||||
{
|
||||
static readonly IList<T> Empty = new T[0];
|
||||
public static IList<T> EmptySet
|
||||
{
|
||||
get { return Empty; }
|
||||
}
|
||||
{
|
||||
static readonly IList<T> Empty = new T [0];
|
||||
public static IList<T> EmptySet {
|
||||
get { return Empty; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Collections
|
||||
{
|
||||
public static bool AddAll<T> (ICollection<T> list, IEnumerable toAdd)
|
||||
{
|
||||
foreach (T t in toAdd)
|
||||
list.Add (t);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Collections
|
||||
{
|
||||
public static bool AddAll<T>(ICollection<T> list, IEnumerable toAdd)
|
||||
{
|
||||
foreach (T t in toAdd)
|
||||
list.Add(t);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static TV Remove<TK, TV>(IDictionary<TK, TV> map, TK toRemove) where TK : class
|
||||
{
|
||||
TV local;
|
||||
if (map.TryGetValue(toRemove, out local))
|
||||
{
|
||||
map.Remove(toRemove);
|
||||
return local;
|
||||
}
|
||||
return default(TV);
|
||||
}
|
||||
public static TV Remove<TK, TV> (IDictionary<TK, TV> map, TK toRemove) where TK : class
|
||||
{
|
||||
TV local;
|
||||
if (map.TryGetValue (toRemove, out local)) {
|
||||
map.Remove (toRemove);
|
||||
return local;
|
||||
}
|
||||
return default(TV);
|
||||
}
|
||||
|
||||
|
||||
public static T[] ToArray<T>(ICollection<T> list)
|
||||
{
|
||||
T[] array = new T[list.Count];
|
||||
list.CopyTo(array, 0);
|
||||
return array;
|
||||
}
|
||||
public static T[] ToArray<T> (ICollection<T> list)
|
||||
{
|
||||
T[] array = new T[list.Count];
|
||||
list.CopyTo (array, 0);
|
||||
return array;
|
||||
}
|
||||
|
||||
public static T[] ToArray<T>(List<object> list)
|
||||
{
|
||||
T[] array = new T[list.Count];
|
||||
for (int c = 0; c < list.Count; c++)
|
||||
for(int c = 0; c < list.Count; c++)
|
||||
{
|
||||
array[c] = (T)list[c];
|
||||
}
|
||||
@@ -54,97 +52,95 @@ namespace SharpCifs.Util.Sharpen
|
||||
}
|
||||
|
||||
|
||||
public static TU[] ToArray<T, TU>(ICollection<T> list, TU[] res) where T : TU
|
||||
{
|
||||
if (res.Length < list.Count)
|
||||
res = new TU[list.Count];
|
||||
public static TU[] ToArray<T,TU> (ICollection<T> list, TU[] res) where T:TU
|
||||
{
|
||||
if (res.Length < list.Count)
|
||||
res = new TU [list.Count];
|
||||
|
||||
int n = 0;
|
||||
foreach (T t in list)
|
||||
res [n++] = t;
|
||||
|
||||
if (res.Length > list.Count)
|
||||
res [list.Count] = default (T);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static IDictionary<TK,TV> EmptyMap<TK,TV> ()
|
||||
{
|
||||
return new Dictionary<TK,TV> ();
|
||||
}
|
||||
|
||||
int n = 0;
|
||||
foreach (T t in list)
|
||||
res[n++] = t;
|
||||
public static IList<T> EmptyList<T> ()
|
||||
{
|
||||
return Collections<T>.EmptySet;
|
||||
}
|
||||
|
||||
if (res.Length > list.Count)
|
||||
res[list.Count] = default(T);
|
||||
return res;
|
||||
}
|
||||
public static ICollection<T> EmptySet<T> ()
|
||||
{
|
||||
return Collections<T>.EmptySet;
|
||||
}
|
||||
|
||||
public static IDictionary<TK, TV> EmptyMap<TK, TV>()
|
||||
{
|
||||
return new Dictionary<TK, TV>();
|
||||
}
|
||||
public static IList<T> NCopies<T> (int n, T elem)
|
||||
{
|
||||
List<T> list = new List<T> (n);
|
||||
while (n-- > 0) {
|
||||
list.Add (elem);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static IList<T> EmptyList<T>()
|
||||
{
|
||||
return Collections<T>.EmptySet;
|
||||
}
|
||||
public static void Reverse<T> (IList<T> list)
|
||||
{
|
||||
int end = list.Count - 1;
|
||||
int index = 0;
|
||||
while (index < end) {
|
||||
T tmp = list [index];
|
||||
list [index] = list [end];
|
||||
list [end] = tmp;
|
||||
++index;
|
||||
--end;
|
||||
}
|
||||
}
|
||||
|
||||
public static ICollection<T> EmptySet<T>()
|
||||
{
|
||||
return Collections<T>.EmptySet;
|
||||
}
|
||||
public static ICollection<T> Singleton<T> (T item)
|
||||
{
|
||||
List<T> list = new List<T> (1);
|
||||
list.Add (item);
|
||||
return list;
|
||||
}
|
||||
|
||||
public static IList<T> NCopies<T>(int n, T elem)
|
||||
{
|
||||
List<T> list = new List<T>(n);
|
||||
while (n-- > 0)
|
||||
{
|
||||
list.Add(elem);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
public static IList<T> SingletonList<T> (T item)
|
||||
{
|
||||
List<T> list = new List<T> (1);
|
||||
list.Add (item);
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void Reverse<T>(IList<T> list)
|
||||
{
|
||||
int end = list.Count - 1;
|
||||
int index = 0;
|
||||
while (index < end)
|
||||
{
|
||||
T tmp = list[index];
|
||||
list[index] = list[end];
|
||||
list[end] = tmp;
|
||||
++index;
|
||||
--end;
|
||||
}
|
||||
}
|
||||
public static IList<T> SynchronizedList<T> (IList<T> list)
|
||||
{
|
||||
return new SynchronizedList<T> (list);
|
||||
}
|
||||
|
||||
public static ICollection<T> Singleton<T>(T item)
|
||||
{
|
||||
List<T> list = new List<T>(1);
|
||||
list.Add(item);
|
||||
return list;
|
||||
}
|
||||
public static ICollection<T> UnmodifiableCollection<T> (ICollection<T> list)
|
||||
{
|
||||
return list;
|
||||
}
|
||||
|
||||
public static IList<T> SingletonList<T>(T item)
|
||||
{
|
||||
List<T> list = new List<T>(1);
|
||||
list.Add(item);
|
||||
return list;
|
||||
}
|
||||
public static IList<T> UnmodifiableList<T> (IList<T> list)
|
||||
{
|
||||
return new ReadOnlyCollection<T> (list);
|
||||
}
|
||||
|
||||
public static IList<T> SynchronizedList<T>(IList<T> list)
|
||||
{
|
||||
return new SynchronizedList<T>(list);
|
||||
}
|
||||
|
||||
public static ICollection<T> UnmodifiableCollection<T>(ICollection<T> list)
|
||||
{
|
||||
return list;
|
||||
}
|
||||
|
||||
public static IList<T> UnmodifiableList<T>(IList<T> list)
|
||||
{
|
||||
return new ReadOnlyCollection<T>(list);
|
||||
}
|
||||
|
||||
public static ICollection<T> UnmodifiableSet<T>(ICollection<T> list)
|
||||
{
|
||||
return list;
|
||||
}
|
||||
|
||||
public static IDictionary<TK, TV> UnmodifiableMap<TK, TV>(IDictionary<TK, TV> dict)
|
||||
{
|
||||
return dict;
|
||||
}
|
||||
public static ICollection<T> UnmodifiableSet<T> (ICollection<T> list)
|
||||
{
|
||||
return list;
|
||||
}
|
||||
|
||||
public static IDictionary<TK,TV> UnmodifiableMap<TK,TV> (IDictionary<TK,TV> dict)
|
||||
{
|
||||
return dict;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,131 +3,120 @@ using System.Collections.Generic;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal class ConcurrentHashMap<T, TU> : AbstractMap<T, TU>, IConcurrentMap<T, TU>
|
||||
{
|
||||
private Dictionary<T, TU> _table;
|
||||
{
|
||||
private Dictionary<T, TU> _table;
|
||||
|
||||
public ConcurrentHashMap()
|
||||
{
|
||||
_table = new Dictionary<T, TU>();
|
||||
}
|
||||
public ConcurrentHashMap ()
|
||||
{
|
||||
_table = new Dictionary<T, TU> ();
|
||||
}
|
||||
|
||||
public ConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel)
|
||||
{
|
||||
_table = new Dictionary<T, TU>(initialCapacity);
|
||||
}
|
||||
public ConcurrentHashMap (int initialCapacity, float loadFactor, int concurrencyLevel)
|
||||
{
|
||||
_table = new Dictionary<T, TU> (initialCapacity);
|
||||
}
|
||||
|
||||
public override void Clear()
|
||||
{
|
||||
lock (_table)
|
||||
{
|
||||
_table = new Dictionary<T, TU>();
|
||||
}
|
||||
}
|
||||
public override void Clear ()
|
||||
{
|
||||
lock (_table) {
|
||||
_table = new Dictionary<T, TU> ();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool ContainsKey(object name)
|
||||
{
|
||||
return _table.ContainsKey((T)name);
|
||||
}
|
||||
public override bool ContainsKey (object name)
|
||||
{
|
||||
return _table.ContainsKey ((T)name);
|
||||
}
|
||||
|
||||
public override ICollection<KeyValuePair<T, TU>> EntrySet()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public override ICollection<KeyValuePair<T, TU>> EntrySet ()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public override TU Get(object key)
|
||||
{
|
||||
TU local;
|
||||
_table.TryGetValue((T)key, out local);
|
||||
return local;
|
||||
}
|
||||
public override TU Get (object key)
|
||||
{
|
||||
TU local;
|
||||
_table.TryGetValue ((T)key, out local);
|
||||
return local;
|
||||
}
|
||||
|
||||
protected override IEnumerator<KeyValuePair<T, TU>> InternalGetEnumerator()
|
||||
{
|
||||
return _table.GetEnumerator();
|
||||
}
|
||||
protected override IEnumerator<KeyValuePair<T, TU>> InternalGetEnumerator ()
|
||||
{
|
||||
return _table.GetEnumerator ();
|
||||
}
|
||||
|
||||
public override bool IsEmpty()
|
||||
{
|
||||
return _table.Count == 0;
|
||||
}
|
||||
public override bool IsEmpty ()
|
||||
{
|
||||
return _table.Count == 0;
|
||||
}
|
||||
|
||||
public override TU Put(T key, TU value)
|
||||
{
|
||||
lock (_table)
|
||||
{
|
||||
TU old = Get(key);
|
||||
Dictionary<T, TU> newTable = new Dictionary<T, TU>(_table);
|
||||
newTable[key] = value;
|
||||
_table = newTable;
|
||||
return old;
|
||||
}
|
||||
}
|
||||
public override TU Put (T key, TU value)
|
||||
{
|
||||
lock (_table) {
|
||||
TU old = Get (key);
|
||||
Dictionary<T, TU> newTable = new Dictionary<T, TU> (_table);
|
||||
newTable[key] = value;
|
||||
_table = newTable;
|
||||
return old;
|
||||
}
|
||||
}
|
||||
|
||||
public TU PutIfAbsent(T key, TU value)
|
||||
{
|
||||
lock (_table)
|
||||
{
|
||||
if (!ContainsKey(key))
|
||||
{
|
||||
Dictionary<T, TU> newTable = new Dictionary<T, TU>(_table);
|
||||
newTable[key] = value;
|
||||
_table = newTable;
|
||||
return value;
|
||||
}
|
||||
return Get(key);
|
||||
}
|
||||
}
|
||||
public TU PutIfAbsent (T key, TU value)
|
||||
{
|
||||
lock (_table) {
|
||||
if (!ContainsKey (key)) {
|
||||
Dictionary<T, TU> newTable = new Dictionary<T, TU> (_table);
|
||||
newTable[key] = value;
|
||||
_table = newTable;
|
||||
return value;
|
||||
}
|
||||
return Get (key);
|
||||
}
|
||||
}
|
||||
|
||||
public override TU Remove(object key)
|
||||
{
|
||||
lock (_table)
|
||||
{
|
||||
TU old = Get((T)key);
|
||||
Dictionary<T, TU> newTable = new Dictionary<T, TU>(_table);
|
||||
newTable.Remove((T)key);
|
||||
_table = newTable;
|
||||
return old;
|
||||
}
|
||||
}
|
||||
public override TU Remove (object key)
|
||||
{
|
||||
lock (_table) {
|
||||
TU old = Get ((T)key);
|
||||
Dictionary<T, TU> newTable = new Dictionary<T, TU> (_table);
|
||||
newTable.Remove ((T)key);
|
||||
_table = newTable;
|
||||
return old;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Remove(object key, object value)
|
||||
{
|
||||
lock (_table)
|
||||
{
|
||||
if (ContainsKey(key) && value.Equals(Get(key)))
|
||||
{
|
||||
Dictionary<T, TU> newTable = new Dictionary<T, TU>(_table);
|
||||
newTable.Remove((T)key);
|
||||
_table = newTable;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool Remove (object key, object value)
|
||||
{
|
||||
lock (_table) {
|
||||
if (ContainsKey (key) && value.Equals (Get (key))) {
|
||||
Dictionary<T, TU> newTable = new Dictionary<T, TU> (_table);
|
||||
newTable.Remove ((T)key);
|
||||
_table = newTable;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Replace(T key, TU oldValue, TU newValue)
|
||||
{
|
||||
lock (_table)
|
||||
{
|
||||
if (ContainsKey(key) && oldValue.Equals(Get(key)))
|
||||
{
|
||||
Dictionary<T, TU> newTable = new Dictionary<T, TU>(_table);
|
||||
newTable[key] = newValue;
|
||||
_table = newTable;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool Replace (T key, TU oldValue, TU newValue)
|
||||
{
|
||||
lock (_table) {
|
||||
if (ContainsKey (key) && oldValue.Equals (Get (key))) {
|
||||
Dictionary<T, TU> newTable = new Dictionary<T, TU> (_table);
|
||||
newTable[key] = newValue;
|
||||
_table = newTable;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerable<T> Keys
|
||||
{
|
||||
get { return _table.Keys; }
|
||||
}
|
||||
public override IEnumerable<T> Keys {
|
||||
get { return _table.Keys; }
|
||||
}
|
||||
|
||||
public override IEnumerable<TU> Values
|
||||
{
|
||||
get { return _table.Values; }
|
||||
}
|
||||
}
|
||||
public override IEnumerable<TU> Values {
|
||||
get { return _table.Values; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,35 +3,35 @@ using System.Globalization;
|
||||
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public abstract class DateFormat
|
||||
{
|
||||
public const int Default = 2;
|
||||
public abstract class DateFormat
|
||||
{
|
||||
public const int Default = 2;
|
||||
|
||||
public static DateFormat GetDateTimeInstance (int dateStyle, int timeStyle)
|
||||
{
|
||||
return GetDateTimeInstance (dateStyle, timeStyle, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
public static DateFormat GetDateTimeInstance (int dateStyle, int timeStyle, CultureInfo aLocale)
|
||||
{
|
||||
return new SimpleDateFormat (aLocale.DateTimeFormat.FullDateTimePattern, aLocale);
|
||||
}
|
||||
|
||||
TimeZoneInfo _timeZone;
|
||||
|
||||
public static DateFormat GetDateTimeInstance(int dateStyle, int timeStyle)
|
||||
{
|
||||
return GetDateTimeInstance(dateStyle, timeStyle, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
public static DateFormat GetDateTimeInstance(int dateStyle, int timeStyle, CultureInfo aLocale)
|
||||
{
|
||||
return new SimpleDateFormat(aLocale.DateTimeFormat.FullDateTimePattern, aLocale);
|
||||
}
|
||||
|
||||
TimeZoneInfo _timeZone;
|
||||
|
||||
public abstract DateTime Parse(string value);
|
||||
|
||||
public TimeZoneInfo GetTimeZone()
|
||||
{
|
||||
return _timeZone;
|
||||
}
|
||||
|
||||
public void SetTimeZone(TimeZoneInfo timeZone)
|
||||
{
|
||||
this._timeZone = timeZone;
|
||||
}
|
||||
|
||||
public abstract string Format(DateTime time);
|
||||
}
|
||||
public abstract DateTime Parse (string value);
|
||||
|
||||
public TimeZoneInfo GetTimeZone ()
|
||||
{
|
||||
return _timeZone;
|
||||
}
|
||||
|
||||
public void SetTimeZone (TimeZoneInfo timeZone)
|
||||
{
|
||||
this._timeZone = timeZone;
|
||||
}
|
||||
|
||||
public abstract string Format (DateTime time);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,55 +4,52 @@ using System.Collections.Generic;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal class EnumeratorWrapper<T> : Iterator<T>
|
||||
{
|
||||
object _collection;
|
||||
IEnumerator<T> _e;
|
||||
T _lastVal;
|
||||
bool _more;
|
||||
bool _copied;
|
||||
{
|
||||
object _collection;
|
||||
IEnumerator<T> _e;
|
||||
T _lastVal;
|
||||
bool _more;
|
||||
bool _copied;
|
||||
|
||||
public EnumeratorWrapper(object collection, IEnumerator<T> e)
|
||||
{
|
||||
this._e = e;
|
||||
this._collection = collection;
|
||||
_more = e.MoveNext();
|
||||
}
|
||||
public EnumeratorWrapper (object collection, IEnumerator<T> e)
|
||||
{
|
||||
this._e = e;
|
||||
this._collection = collection;
|
||||
_more = e.MoveNext ();
|
||||
}
|
||||
|
||||
public override bool HasNext()
|
||||
{
|
||||
return _more;
|
||||
}
|
||||
public override bool HasNext ()
|
||||
{
|
||||
return _more;
|
||||
}
|
||||
|
||||
public override T Next()
|
||||
{
|
||||
if (!_more)
|
||||
throw new NoSuchElementException();
|
||||
_lastVal = _e.Current;
|
||||
_more = _e.MoveNext();
|
||||
return _lastVal;
|
||||
}
|
||||
public override T Next ()
|
||||
{
|
||||
if (!_more)
|
||||
throw new NoSuchElementException ();
|
||||
_lastVal = _e.Current;
|
||||
_more = _e.MoveNext ();
|
||||
return _lastVal;
|
||||
}
|
||||
|
||||
public override void Remove()
|
||||
{
|
||||
ICollection<T> col = _collection as ICollection<T>;
|
||||
if (col == null)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
if (_more && !_copied)
|
||||
{
|
||||
// Read the remaining elements, since the current enumerator
|
||||
// will be invalid after removing the element
|
||||
List<T> remaining = new List<T>();
|
||||
do
|
||||
{
|
||||
remaining.Add(_e.Current);
|
||||
} while (_e.MoveNext());
|
||||
_e = remaining.GetEnumerator();
|
||||
_e.MoveNext();
|
||||
_copied = true;
|
||||
}
|
||||
col.Remove(_lastVal);
|
||||
}
|
||||
}
|
||||
public override void Remove ()
|
||||
{
|
||||
ICollection<T> col = _collection as ICollection<T>;
|
||||
if (col == null) {
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
if (_more && !_copied) {
|
||||
// Read the remaining elements, since the current enumerator
|
||||
// will be invalid after removing the element
|
||||
List<T> remaining = new List<T> ();
|
||||
do {
|
||||
remaining.Add (_e.Current);
|
||||
} while (_e.MoveNext ());
|
||||
_e = remaining.GetEnumerator ();
|
||||
_e.MoveNext ();
|
||||
_copied = true;
|
||||
}
|
||||
col.Remove (_lastVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,191 +28,190 @@ using System;
|
||||
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public class VirtualMachineError : Error
|
||||
{
|
||||
}
|
||||
public class VirtualMachineError : Error
|
||||
{
|
||||
}
|
||||
|
||||
public class StackOverflowError : VirtualMachineError
|
||||
{
|
||||
}
|
||||
public class StackOverflowError : VirtualMachineError
|
||||
{
|
||||
}
|
||||
|
||||
public class BrokenBarrierException : Exception
|
||||
{
|
||||
}
|
||||
public class BrokenBarrierException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
internal class BufferUnderflowException : Exception
|
||||
{
|
||||
}
|
||||
internal class BufferUnderflowException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
public class CharacterCodingException : Exception
|
||||
{
|
||||
}
|
||||
public class CharacterCodingException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
public class DataFormatException : Exception
|
||||
{
|
||||
}
|
||||
public class DataFormatException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
public class EofException : Exception
|
||||
{
|
||||
public EofException()
|
||||
{
|
||||
}
|
||||
public class EofException : Exception
|
||||
{
|
||||
public EofException ()
|
||||
{
|
||||
}
|
||||
|
||||
public EofException(string msg) : base(msg)
|
||||
{
|
||||
}
|
||||
}
|
||||
public EofException (string msg) : base(msg)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class Error : Exception
|
||||
{
|
||||
public Error()
|
||||
{
|
||||
}
|
||||
public class Error : Exception
|
||||
{
|
||||
public Error ()
|
||||
{
|
||||
}
|
||||
|
||||
public Error(Exception ex) : base("Runtime Exception", ex)
|
||||
{
|
||||
}
|
||||
public Error (Exception ex) : base("Runtime Exception", ex)
|
||||
{
|
||||
}
|
||||
|
||||
public Error(string msg) : base(msg)
|
||||
{
|
||||
}
|
||||
public Error (string msg) : base(msg)
|
||||
{
|
||||
}
|
||||
|
||||
public Error(string msg, Exception ex) : base(msg, ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
public Error (string msg, Exception ex) : base(msg, ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class ExecutionException : Exception
|
||||
{
|
||||
public ExecutionException(Exception inner) : base("Execution failed", inner)
|
||||
{
|
||||
}
|
||||
}
|
||||
public class ExecutionException : Exception
|
||||
{
|
||||
public ExecutionException (Exception inner): base ("Execution failed", inner)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class InstantiationException : Exception
|
||||
{
|
||||
}
|
||||
public class InstantiationException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
public class InterruptedIoException : Exception
|
||||
{
|
||||
public InterruptedIoException(string msg) : base(msg)
|
||||
{
|
||||
}
|
||||
}
|
||||
public class InterruptedIoException : Exception
|
||||
{
|
||||
public InterruptedIoException (string msg) : base(msg)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class MissingResourceException : Exception
|
||||
{
|
||||
}
|
||||
public class MissingResourceException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
public class NoSuchAlgorithmException : Exception
|
||||
{
|
||||
}
|
||||
public class NoSuchAlgorithmException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
public class NoSuchElementException : Exception
|
||||
{
|
||||
}
|
||||
public class NoSuchElementException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
internal class NoSuchMethodException : Exception
|
||||
{
|
||||
}
|
||||
internal class NoSuchMethodException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
internal class OverlappingFileLockException : Exception
|
||||
{
|
||||
}
|
||||
internal class OverlappingFileLockException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
public class ParseException : Exception
|
||||
{
|
||||
public ParseException()
|
||||
{
|
||||
}
|
||||
public class ParseException : Exception
|
||||
{
|
||||
public ParseException ()
|
||||
{
|
||||
}
|
||||
|
||||
public ParseException(string msg, int errorOffset)
|
||||
: base(string.Format("Msg: {0}. Error Offset: {1}", msg, errorOffset))
|
||||
{
|
||||
}
|
||||
}
|
||||
public ParseException (string msg, int errorOffset) : base(string.Format ("Msg: {0}. Error Offset: {1}", msg, errorOffset))
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class RuntimeException : Exception
|
||||
{
|
||||
public RuntimeException()
|
||||
{
|
||||
}
|
||||
public class RuntimeException : Exception
|
||||
{
|
||||
public RuntimeException ()
|
||||
{
|
||||
}
|
||||
|
||||
public RuntimeException(Exception ex) : base("Runtime Exception", ex)
|
||||
{
|
||||
}
|
||||
public RuntimeException (Exception ex) : base("Runtime Exception", ex)
|
||||
{
|
||||
}
|
||||
|
||||
public RuntimeException(string msg) : base(msg)
|
||||
{
|
||||
}
|
||||
public RuntimeException (string msg) : base(msg)
|
||||
{
|
||||
}
|
||||
|
||||
public RuntimeException(string msg, Exception ex) : base(msg, ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
public RuntimeException (string msg, Exception ex) : base(msg, ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
internal class StringIndexOutOfBoundsException : Exception
|
||||
{
|
||||
}
|
||||
internal class StringIndexOutOfBoundsException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
public class UnknownHostException : Exception
|
||||
{
|
||||
public UnknownHostException()
|
||||
{
|
||||
}
|
||||
public class UnknownHostException : Exception
|
||||
{
|
||||
public UnknownHostException ()
|
||||
{
|
||||
}
|
||||
|
||||
public UnknownHostException(string message) : base(message)
|
||||
{
|
||||
public UnknownHostException(string message) : base(message)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public UnknownHostException (Exception ex): base ("Host not found", ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public UnknownHostException(Exception ex) : base("Host not found", ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
public class UnsupportedEncodingException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
public class UnsupportedEncodingException : Exception
|
||||
{
|
||||
}
|
||||
internal class UriSyntaxException : Exception
|
||||
{
|
||||
public UriSyntaxException (string s, string msg) : base(s + " " + msg)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
internal class UriSyntaxException : Exception
|
||||
{
|
||||
public UriSyntaxException(string s, string msg) : base(s + " " + msg)
|
||||
{
|
||||
}
|
||||
}
|
||||
internal class ZipException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
internal class ZipException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
public class GitException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
public class ConnectException : Exception
|
||||
{
|
||||
public ConnectException(string msg) : base(msg)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class KeyManagementException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
class IllegalCharsetNameException : Exception
|
||||
{
|
||||
public IllegalCharsetNameException(string msg) : base(msg)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class UnsupportedCharsetException : Exception
|
||||
{
|
||||
public UnsupportedCharsetException(string msg) : base(msg)
|
||||
{
|
||||
}
|
||||
}
|
||||
public class GitException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
public class ConnectException: Exception
|
||||
{
|
||||
public ConnectException (string msg): base (msg)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class KeyManagementException: Exception
|
||||
{
|
||||
}
|
||||
|
||||
class IllegalCharsetNameException: Exception
|
||||
{
|
||||
public IllegalCharsetNameException (string msg): base (msg)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class UnsupportedCharsetException: Exception
|
||||
{
|
||||
public UnsupportedCharsetException (string msg): base (msg)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,14 +5,12 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
//using Windows.Networking;
|
||||
//using Windows.Networking.Sockets;
|
||||
|
||||
@@ -73,7 +71,7 @@ namespace SharpCifs.Util.Sharpen
|
||||
|
||||
public static int BitCount(int val)
|
||||
{
|
||||
uint num = (uint) val;
|
||||
uint num = (uint)val;
|
||||
int count = 0;
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
@@ -126,9 +124,10 @@ namespace SharpCifs.Util.Sharpen
|
||||
|
||||
public static Encoding GetEncoding(string name)
|
||||
{
|
||||
//Encoding e = Encoding.GetEncoding (name, EncoderFallback.ExceptionFallback, DecoderFallback.ExceptionFallback);
|
||||
// Encoding e = Encoding.GetEncoding (name, EncoderFallback.ExceptionFallback, DecoderFallback.ExceptionFallback);
|
||||
try
|
||||
{
|
||||
|
||||
Encoding e = Encoding.GetEncoding(name.Replace('_', '-'));
|
||||
if (e is UTF8Encoding)
|
||||
return new UTF8Encoding(false, true);
|
||||
@@ -205,32 +204,12 @@ namespace SharpCifs.Util.Sharpen
|
||||
|
||||
public static int GetOffset(this TimeZoneInfo tzone, long date)
|
||||
{
|
||||
return (int) tzone.GetUtcOffset(MillisToDateTimeOffset(date, 0).DateTime).TotalMilliseconds;
|
||||
}
|
||||
|
||||
public static InputStream GetResourceAsStream(this Type type, string name)
|
||||
{
|
||||
//Type.`Assembly` property deleted
|
||||
//string str2 = type.Assembly.GetName().Name + ".resources";
|
||||
string str2 = type.GetTypeInfo().Assembly.GetName().Name + ".resources";
|
||||
string[] textArray1 = {str2, ".", type.Namespace, ".", name};
|
||||
string str = string.Concat(textArray1);
|
||||
|
||||
//Type.`Assembly` property deleted
|
||||
//Stream manifestResourceStream = type.Assembly.GetManifestResourceStream(str);
|
||||
Stream manifestResourceStream = type.GetTypeInfo().Assembly.GetManifestResourceStream(str);
|
||||
if (manifestResourceStream == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return InputStream.Wrap(manifestResourceStream);
|
||||
return (int)tzone.GetUtcOffset(MillisToDateTimeOffset(date, 0).DateTime).TotalMilliseconds;
|
||||
}
|
||||
|
||||
public static long GetTime(this DateTime dateTime)
|
||||
{
|
||||
return
|
||||
new DateTimeOffset(DateTime.SpecifyKind(dateTime, DateTimeKind.Utc), TimeSpan.Zero)
|
||||
.ToMillisecondsSinceEpoch();
|
||||
return new DateTimeOffset(DateTime.SpecifyKind(dateTime, DateTimeKind.Utc), TimeSpan.Zero).ToMillisecondsSinceEpoch();
|
||||
}
|
||||
|
||||
public static void InitCause(this Exception ex, Exception cause)
|
||||
@@ -266,7 +245,7 @@ namespace SharpCifs.Util.Sharpen
|
||||
public static Iterator<T> Iterator<T>(this IEnumerable<T> col)
|
||||
{
|
||||
return new EnumeratorWrapper<T>(col, col.GetEnumerator());
|
||||
}
|
||||
}
|
||||
|
||||
public static T Last<T>(this ICollection<T> col)
|
||||
{
|
||||
@@ -291,28 +270,27 @@ namespace SharpCifs.Util.Sharpen
|
||||
|
||||
public static DateTime CreateDate(long milliSecondsSinceEpoch)
|
||||
{
|
||||
long num = EpochTicks + (milliSecondsSinceEpoch*10000);
|
||||
long num = EpochTicks + (milliSecondsSinceEpoch * 10000);
|
||||
return new DateTime(num);
|
||||
}
|
||||
|
||||
public static DateTime CreateDateFromUTC(long milliSecondsSinceEpoch)
|
||||
{
|
||||
long num = EpochTicks + (milliSecondsSinceEpoch*10000);
|
||||
long num = EpochTicks + (milliSecondsSinceEpoch * 10000);
|
||||
return new DateTime(num, DateTimeKind.Utc);
|
||||
}
|
||||
|
||||
|
||||
public static DateTimeOffset MillisToDateTimeOffset(long milliSecondsSinceEpoch,
|
||||
long offsetMinutes)
|
||||
public static DateTimeOffset MillisToDateTimeOffset(long milliSecondsSinceEpoch, long offsetMinutes)
|
||||
{
|
||||
TimeSpan offset = TimeSpan.FromMinutes(offsetMinutes);
|
||||
long num = EpochTicks + (milliSecondsSinceEpoch*10000);
|
||||
long num = EpochTicks + (milliSecondsSinceEpoch * 10000);
|
||||
return new DateTimeOffset(num + offset.Ticks, offset);
|
||||
}
|
||||
|
||||
public static int NumberOfLeadingZeros(int val)
|
||||
{
|
||||
uint num = (uint) val;
|
||||
uint num = (uint)val;
|
||||
int count = 0;
|
||||
while ((num & 0x80000000) == 0)
|
||||
{
|
||||
@@ -324,7 +302,7 @@ namespace SharpCifs.Util.Sharpen
|
||||
|
||||
public static int NumberOfTrailingZeros(int val)
|
||||
{
|
||||
uint num = (uint) val;
|
||||
uint num = (uint)val;
|
||||
int count = 0;
|
||||
while ((num & 1) == 0)
|
||||
{
|
||||
@@ -375,7 +353,7 @@ namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
Regex rgx = new Regex(regex);
|
||||
|
||||
if (replacement.IndexOfAny(new[] {'\\', '$'}) != -1)
|
||||
if (replacement.IndexOfAny(new[] { '\\', '$' }) != -1)
|
||||
{
|
||||
// Back references not yet supported
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@@ -394,13 +372,7 @@ namespace SharpCifs.Util.Sharpen
|
||||
return rgx.Replace(str, replacement);
|
||||
}
|
||||
|
||||
public static bool RegionMatches(this
|
||||
string str,
|
||||
bool ignoreCase,
|
||||
int toOffset,
|
||||
string other,
|
||||
int ooffset,
|
||||
int len)
|
||||
public static bool RegionMatches(this string str, bool ignoreCase, int toOffset, string other, int ooffset, int len)
|
||||
{
|
||||
if (toOffset < 0 || ooffset < 0 || toOffset + len > str.Length || ooffset + len > other.Length)
|
||||
return false;
|
||||
@@ -526,19 +498,14 @@ namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
if (dateTime.Kind != DateTimeKind.Utc)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
"dateTime is expected to be expressed as a UTC DateTime", "dateTime");
|
||||
throw new ArgumentException("dateTime is expected to be expressed as a UTC DateTime", "dateTime");
|
||||
}
|
||||
return new DateTimeOffset(DateTime.SpecifyKind(dateTime, DateTimeKind.Utc),
|
||||
TimeSpan.Zero).ToMillisecondsSinceEpoch();
|
||||
return new DateTimeOffset(DateTime.SpecifyKind(dateTime, DateTimeKind.Utc), TimeSpan.Zero).ToMillisecondsSinceEpoch();
|
||||
}
|
||||
|
||||
public static long ToMillisecondsSinceEpoch(this DateTimeOffset dateTimeOffset)
|
||||
{
|
||||
return (
|
||||
((dateTimeOffset.Ticks - dateTimeOffset.Offset.Ticks) - EpochTicks)
|
||||
/TimeSpan.TicksPerMillisecond
|
||||
);
|
||||
return (((dateTimeOffset.Ticks - dateTimeOffset.Offset.Ticks) - EpochTicks) / TimeSpan.TicksPerMillisecond);
|
||||
}
|
||||
|
||||
public static string ToOctalString(int val)
|
||||
@@ -630,8 +597,8 @@ namespace SharpCifs.Util.Sharpen
|
||||
if (host == "0.0.0.0")
|
||||
{
|
||||
return IPAddress.Any;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return IPAddress.Parse(host);
|
||||
@@ -639,47 +606,42 @@ namespace SharpCifs.Util.Sharpen
|
||||
catch (Exception ex)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IPAddress[] GetAddressesByName(string host)
|
||||
{
|
||||
try
|
||||
{
|
||||
//get v4-address only
|
||||
return System.Net.Dns.GetHostEntryAsync(host)
|
||||
.GetAwaiter()
|
||||
.GetResult()
|
||||
.AddressList
|
||||
.Where(addr => addr.AddressFamily == AddressFamily.InterNetwork)
|
||||
.ToArray();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
//IReadOnlyList<EndpointPair> data = null;
|
||||
|
||||
//try
|
||||
//{
|
||||
// Task.Run(async () =>
|
||||
// {
|
||||
// data = await DatagramSocket.GetEndpointPairsAsync(new HostName(host), "0");
|
||||
// }).Wait();
|
||||
//}
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
// return null;
|
||||
//}
|
||||
|
||||
//return data != null
|
||||
// ? data.Where(i => i.RemoteHostName.Type == HostNameType.Ipv4)
|
||||
// .GroupBy(i => i.RemoteHostName.DisplayName)
|
||||
// .Select(i => IPAddress.Parse(i.First().RemoteHostName.DisplayName))
|
||||
// .ToArray()
|
||||
// : null;
|
||||
|
||||
//get v4-address only
|
||||
var entry = Task.Run(() => System.Net.Dns.GetHostEntryAsync(host))
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
return entry.AddressList
|
||||
.Where(addr => addr.AddressFamily == AddressFamily.InterNetwork)
|
||||
.ToArray();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static IPAddress[] GetLocalAddresses()
|
||||
{
|
||||
try
|
||||
{
|
||||
//get v4-address only
|
||||
return NetworkInterface.GetAllNetworkInterfaces()
|
||||
.SelectMany(i => i.GetIPProperties().UnicastAddresses)
|
||||
.Select(ua => ua.Address)
|
||||
.Where(addr => addr.AddressFamily == AddressFamily.InterNetwork
|
||||
&& !IPAddress.IsLoopback(addr))
|
||||
.ToArray();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static string GetImplementationVersion(this Assembly asm)
|
||||
{
|
||||
return asm.GetName().Version.ToString();
|
||||
@@ -705,11 +667,6 @@ namespace SharpCifs.Util.Sharpen
|
||||
return ((IPEndPoint)socket.LocalEndPoint).Port;
|
||||
}
|
||||
|
||||
public static IPAddress GetLocalInetAddress(this Socket socket)
|
||||
{
|
||||
return ((IPEndPoint)socket.LocalEndPoint).Address;
|
||||
}
|
||||
|
||||
public static int GetPort(this Socket socket)
|
||||
{
|
||||
return ((IPEndPoint)socket.RemoteEndPoint).Port;
|
||||
@@ -721,16 +678,14 @@ namespace SharpCifs.Util.Sharpen
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public static bool RemoveElement(this ArrayList list, object elem)
|
||||
/*public static bool RemoveElement(this ArrayList list, object elem)
|
||||
{
|
||||
int i = list.IndexOf(elem);
|
||||
if (i == -1)
|
||||
return false;
|
||||
list.RemoveAt(i);
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
}*/
|
||||
|
||||
public static Semaphore CreateSemaphore(int count)
|
||||
{
|
||||
|
||||
@@ -3,18 +3,18 @@ using System.IO;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public class FileInputStream : InputStream
|
||||
{
|
||||
public FileInputStream(FilePath file) : this(file.GetPath())
|
||||
{
|
||||
}
|
||||
{
|
||||
public FileInputStream (FilePath file) : this(file.GetPath ())
|
||||
{
|
||||
}
|
||||
|
||||
public FileInputStream(string file)
|
||||
{
|
||||
if (!File.Exists(file))
|
||||
{
|
||||
throw new FileNotFoundException("File not found", file);
|
||||
}
|
||||
Wrapped = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
}
|
||||
}
|
||||
public FileInputStream (string file)
|
||||
{
|
||||
if (!File.Exists (file)) {
|
||||
throw new FileNotFoundException ("File not found", file);
|
||||
}
|
||||
Wrapped = new FileStream (file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,37 +3,31 @@ using System.IO;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal class FileOutputStream : OutputStream
|
||||
{
|
||||
public FileOutputStream(FilePath file) : this(file.GetPath(), false)
|
||||
{
|
||||
}
|
||||
{
|
||||
public FileOutputStream (FilePath file): this (file.GetPath (), false)
|
||||
{
|
||||
}
|
||||
|
||||
public FileOutputStream(string file) : this(file, false)
|
||||
{
|
||||
}
|
||||
public FileOutputStream (string file): this (file, false)
|
||||
{
|
||||
}
|
||||
|
||||
public FileOutputStream(FilePath file, bool append) : this(file.GetPath(), append)
|
||||
{
|
||||
}
|
||||
public FileOutputStream (FilePath file, bool append) : this(file.GetPath (), append)
|
||||
{
|
||||
}
|
||||
|
||||
public FileOutputStream(string file, bool append)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (append)
|
||||
{
|
||||
Wrapped = File.Open(file, FileMode.Append, FileAccess.Write);
|
||||
}
|
||||
else
|
||||
{
|
||||
Wrapped = File.Open(file, FileMode.Create, FileAccess.Write);
|
||||
}
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
throw new FileNotFoundException("File not found: " + file);
|
||||
}
|
||||
}
|
||||
public FileOutputStream (string file, bool append)
|
||||
{
|
||||
try {
|
||||
if (append) {
|
||||
Wrapped = File.Open (file, FileMode.Append, FileAccess.Write);
|
||||
} else {
|
||||
Wrapped = File.Open (file, FileMode.Create, FileAccess.Write);
|
||||
}
|
||||
} catch (DirectoryNotFoundException) {
|
||||
throw new FileNotFoundException ("File not found: " + file);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,337 +6,308 @@ using System.Threading;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public class FilePath
|
||||
{
|
||||
private string _path;
|
||||
private static long _tempCounter;
|
||||
{
|
||||
private string _path;
|
||||
private static long _tempCounter;
|
||||
|
||||
public FilePath()
|
||||
{
|
||||
}
|
||||
public FilePath ()
|
||||
{
|
||||
}
|
||||
|
||||
public FilePath(string path)
|
||||
: this((string)null, path)
|
||||
{
|
||||
public FilePath (string path)
|
||||
: this ((string) null, path)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public FilePath(FilePath other, string child)
|
||||
: this((string)other, child)
|
||||
{
|
||||
public FilePath (FilePath other, string child)
|
||||
: this ((string) other, child)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public FilePath(string other, string child)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
_path = child;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (!string.IsNullOrEmpty(child)
|
||||
&& (child[0] == Path.DirectorySeparatorChar
|
||||
|| child[0] == Path.AltDirectorySeparatorChar))
|
||||
child = child.Substring(1);
|
||||
public FilePath (string other, string child)
|
||||
{
|
||||
if (other == null) {
|
||||
_path = child;
|
||||
} else {
|
||||
while (!string.IsNullOrEmpty(child) && (child[0] == Path.DirectorySeparatorChar || child[0] == Path.AltDirectorySeparatorChar))
|
||||
child = child.Substring (1);
|
||||
|
||||
if (!string.IsNullOrEmpty(other)
|
||||
&& other[other.Length - 1] == Path.VolumeSeparatorChar)
|
||||
other += Path.DirectorySeparatorChar;
|
||||
if (!string.IsNullOrEmpty(other) && other[other.Length - 1] == Path.VolumeSeparatorChar)
|
||||
other += Path.DirectorySeparatorChar;
|
||||
|
||||
_path = Path.Combine(other, child);
|
||||
}
|
||||
}
|
||||
_path = Path.Combine (other, child);
|
||||
}
|
||||
}
|
||||
|
||||
public static implicit operator FilePath (string name)
|
||||
{
|
||||
return new FilePath (name);
|
||||
}
|
||||
|
||||
public static implicit operator FilePath(string name)
|
||||
{
|
||||
return new FilePath(name);
|
||||
}
|
||||
public static implicit operator string (FilePath filePath)
|
||||
{
|
||||
return filePath == null ? null : filePath._path;
|
||||
}
|
||||
|
||||
public override bool Equals (object obj)
|
||||
{
|
||||
FilePath other = obj as FilePath;
|
||||
if (other == null)
|
||||
return false;
|
||||
return GetCanonicalPath () == other.GetCanonicalPath ();
|
||||
}
|
||||
|
||||
public override int GetHashCode ()
|
||||
{
|
||||
return _path.GetHashCode ();
|
||||
}
|
||||
|
||||
public static implicit operator string(FilePath filePath)
|
||||
{
|
||||
return filePath == null ? null : filePath._path;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
FilePath other = obj as FilePath;
|
||||
if (other == null)
|
||||
return false;
|
||||
return GetCanonicalPath() == other.GetCanonicalPath();
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return _path.GetHashCode();
|
||||
}
|
||||
|
||||
public bool CreateNewFile()
|
||||
{
|
||||
try
|
||||
{
|
||||
public bool CreateNewFile ()
|
||||
{
|
||||
try {
|
||||
//Stream.`Close` method deleted
|
||||
//File.Open (_path, FileMode.CreateNew).Close ();
|
||||
File.Open(_path, FileMode.CreateNew).Dispose();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static FilePath CreateTempFile()
|
||||
{
|
||||
return new FilePath(Path.GetTempFileName());
|
||||
}
|
||||
public static FilePath CreateTempFile ()
|
||||
{
|
||||
return new FilePath (Path.GetTempFileName ());
|
||||
}
|
||||
|
||||
public static FilePath CreateTempFile(string prefix, string suffix)
|
||||
{
|
||||
return CreateTempFile(prefix, suffix, null);
|
||||
}
|
||||
public static FilePath CreateTempFile (string prefix, string suffix)
|
||||
{
|
||||
return CreateTempFile (prefix, suffix, null);
|
||||
}
|
||||
|
||||
public static FilePath CreateTempFile(string prefix, string suffix, FilePath directory)
|
||||
{
|
||||
string file;
|
||||
if (prefix == null)
|
||||
{
|
||||
throw new ArgumentNullException("prefix");
|
||||
}
|
||||
if (prefix.Length < 3)
|
||||
{
|
||||
throw new ArgumentException("prefix must have at least 3 characters");
|
||||
}
|
||||
string str = (directory == null) ? Path.GetTempPath() : directory.GetPath();
|
||||
do
|
||||
{
|
||||
file = Path.Combine(str, prefix + Interlocked.Increment(ref _tempCounter) + suffix);
|
||||
} while (File.Exists(file));
|
||||
|
||||
new FileOutputStream(file).Close();
|
||||
return new FilePath(file);
|
||||
}
|
||||
public static FilePath CreateTempFile (string prefix, string suffix, FilePath directory)
|
||||
{
|
||||
string file;
|
||||
if (prefix == null) {
|
||||
throw new ArgumentNullException ("prefix");
|
||||
}
|
||||
if (prefix.Length < 3) {
|
||||
throw new ArgumentException ("prefix must have at least 3 characters");
|
||||
}
|
||||
string str = (directory == null) ? Path.GetTempPath () : directory.GetPath ();
|
||||
do {
|
||||
file = Path.Combine (str, prefix + Interlocked.Increment (ref _tempCounter) + suffix);
|
||||
} while (File.Exists (file));
|
||||
|
||||
new FileOutputStream (file).Close ();
|
||||
return new FilePath (file);
|
||||
}
|
||||
|
||||
|
||||
public void DeleteOnExit()
|
||||
{
|
||||
}
|
||||
public void DeleteOnExit ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public FilePath GetAbsoluteFile()
|
||||
{
|
||||
return new FilePath(Path.GetFullPath(_path));
|
||||
}
|
||||
public FilePath GetAbsoluteFile ()
|
||||
{
|
||||
return new FilePath (Path.GetFullPath (_path));
|
||||
}
|
||||
|
||||
public string GetAbsolutePath()
|
||||
{
|
||||
return Path.GetFullPath(_path);
|
||||
}
|
||||
public string GetAbsolutePath ()
|
||||
{
|
||||
return Path.GetFullPath (_path);
|
||||
}
|
||||
|
||||
public FilePath GetCanonicalFile()
|
||||
{
|
||||
return new FilePath(GetCanonicalPath());
|
||||
}
|
||||
public FilePath GetCanonicalFile ()
|
||||
{
|
||||
return new FilePath (GetCanonicalPath ());
|
||||
}
|
||||
|
||||
public string GetCanonicalPath()
|
||||
{
|
||||
return Path.GetFullPath(_path);
|
||||
}
|
||||
public string GetCanonicalPath ()
|
||||
{
|
||||
string p = Path.GetFullPath (_path);
|
||||
p.TrimEnd (Path.DirectorySeparatorChar);
|
||||
return p;
|
||||
}
|
||||
|
||||
public string GetName()
|
||||
{
|
||||
return Path.GetFileName(_path);
|
||||
}
|
||||
public string GetName ()
|
||||
{
|
||||
return Path.GetFileName (_path);
|
||||
}
|
||||
|
||||
public FilePath GetParentFile()
|
||||
{
|
||||
return new FilePath(Path.GetDirectoryName(_path));
|
||||
}
|
||||
public FilePath GetParentFile ()
|
||||
{
|
||||
return new FilePath (Path.GetDirectoryName (_path));
|
||||
}
|
||||
|
||||
public string GetPath()
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
public string GetPath ()
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
|
||||
public bool IsAbsolute()
|
||||
{
|
||||
return Path.IsPathRooted(_path);
|
||||
}
|
||||
public bool IsAbsolute ()
|
||||
{
|
||||
return Path.IsPathRooted (_path);
|
||||
}
|
||||
|
||||
public bool IsDirectory()
|
||||
{
|
||||
public bool IsDirectory ()
|
||||
{
|
||||
return false; // FileHelper.Instance.IsDirectory(this);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsFile()
|
||||
{
|
||||
return false; //FileHelper.Instance.IsFile (this);
|
||||
}
|
||||
public bool IsFile ()
|
||||
{
|
||||
return false; //FileHelper.Instance.IsFile (this);
|
||||
}
|
||||
|
||||
public long LastModified()
|
||||
{
|
||||
public long LastModified ()
|
||||
{
|
||||
return 0; // FileHelper.Instance.LastModified(this);
|
||||
}
|
||||
}
|
||||
|
||||
public long Length()
|
||||
{
|
||||
public long Length ()
|
||||
{
|
||||
return 0; // FileHelper.Instance.Length(this);
|
||||
}
|
||||
}
|
||||
|
||||
public string[] List()
|
||||
{
|
||||
return List(null);
|
||||
}
|
||||
public string[] List ()
|
||||
{
|
||||
return List (null);
|
||||
}
|
||||
|
||||
public string[] List(IFilenameFilter filter)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (IsFile())
|
||||
return null;
|
||||
List<string> list = new List<string>();
|
||||
foreach (string filePth in Directory.GetFileSystemEntries(_path))
|
||||
{
|
||||
string fileName = Path.GetFileName(filePth);
|
||||
if ((filter == null) || filter.Accept(this, fileName))
|
||||
{
|
||||
list.Add(fileName);
|
||||
}
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public string[] List (IFilenameFilter filter)
|
||||
{
|
||||
try {
|
||||
if (IsFile ())
|
||||
return null;
|
||||
List<string> list = new List<string> ();
|
||||
foreach (string filePth in Directory.GetFileSystemEntries (_path)) {
|
||||
string fileName = Path.GetFileName (filePth);
|
||||
if ((filter == null) || filter.Accept (this, fileName)) {
|
||||
list.Add (fileName);
|
||||
}
|
||||
}
|
||||
return list.ToArray ();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public FilePath[] ListFiles()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (IsFile())
|
||||
return null;
|
||||
List<FilePath> list = new List<FilePath>();
|
||||
foreach (string filePath in Directory.GetFileSystemEntries(_path))
|
||||
{
|
||||
list.Add(new FilePath(filePath));
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public FilePath[] ListFiles ()
|
||||
{
|
||||
try {
|
||||
if (IsFile ())
|
||||
return null;
|
||||
List<FilePath> list = new List<FilePath> ();
|
||||
foreach (string filePath in Directory.GetFileSystemEntries (_path)) {
|
||||
list.Add (new FilePath (filePath));
|
||||
}
|
||||
return list.ToArray ();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static void MakeDirWritable(string dir)
|
||||
{
|
||||
//FileHelper.Instance.MakeDirWritable (dir);
|
||||
}
|
||||
static void MakeDirWritable (string dir)
|
||||
{
|
||||
//FileHelper.Instance.MakeDirWritable (dir);
|
||||
}
|
||||
|
||||
static void MakeFileWritable(string file)
|
||||
{
|
||||
//FileHelper.Instance.MakeFileWritable (file);
|
||||
}
|
||||
static void MakeFileWritable (string file)
|
||||
{
|
||||
//FileHelper.Instance.MakeFileWritable (file);
|
||||
}
|
||||
|
||||
public bool Mkdir()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(_path))
|
||||
return false;
|
||||
Directory.CreateDirectory(_path);
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool Mkdir ()
|
||||
{
|
||||
try {
|
||||
if (Directory.Exists (_path))
|
||||
return false;
|
||||
Directory.CreateDirectory (_path);
|
||||
return true;
|
||||
} catch (Exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Mkdirs()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(_path))
|
||||
return false;
|
||||
Directory.CreateDirectory(_path);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool Mkdirs ()
|
||||
{
|
||||
try {
|
||||
if (Directory.Exists (_path))
|
||||
return false;
|
||||
Directory.CreateDirectory (_path);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool RenameTo(FilePath file)
|
||||
{
|
||||
return RenameTo(file._path);
|
||||
}
|
||||
public bool RenameTo (FilePath file)
|
||||
{
|
||||
return RenameTo (file._path);
|
||||
}
|
||||
|
||||
public bool RenameTo(string name)
|
||||
{
|
||||
public bool RenameTo (string name)
|
||||
{
|
||||
return false; // FileHelper.Instance.RenameTo(this, name);
|
||||
}
|
||||
}
|
||||
|
||||
public bool SetLastModified(long milis)
|
||||
{
|
||||
public bool SetLastModified (long milis)
|
||||
{
|
||||
return false; // FileHelper.Instance.SetLastModified(this, milis);
|
||||
}
|
||||
}
|
||||
|
||||
public bool SetReadOnly()
|
||||
{
|
||||
public bool SetReadOnly ()
|
||||
{
|
||||
return false; // FileHelper.Instance.SetReadOnly(this);
|
||||
}
|
||||
|
||||
public Uri ToUri()
|
||||
{
|
||||
return new Uri(_path);
|
||||
}
|
||||
|
||||
// Don't change the case of this method, since ngit does reflection on it
|
||||
public bool CanExecute()
|
||||
{
|
||||
}
|
||||
|
||||
public Uri ToUri ()
|
||||
{
|
||||
return new Uri (_path);
|
||||
}
|
||||
|
||||
// Don't change the case of this method, since ngit does reflection on it
|
||||
public bool CanExecute ()
|
||||
{
|
||||
return false; // FileHelper.Instance.CanExecute(this);
|
||||
}
|
||||
|
||||
// Don't change the case of this method, since ngit does reflection on it
|
||||
public bool SetExecutable(bool exec)
|
||||
{
|
||||
}
|
||||
|
||||
// Don't change the case of this method, since ngit does reflection on it
|
||||
public bool SetExecutable (bool exec)
|
||||
{
|
||||
return false; // FileHelper.Instance.SetExecutable(this, exec);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetParent ()
|
||||
{
|
||||
string p = Path.GetDirectoryName (_path);
|
||||
if (string.IsNullOrEmpty(p) || p == _path)
|
||||
return null;
|
||||
return p;
|
||||
}
|
||||
|
||||
public string GetParent()
|
||||
{
|
||||
string p = Path.GetDirectoryName(_path);
|
||||
if (string.IsNullOrEmpty(p) || p == _path)
|
||||
return null;
|
||||
return p;
|
||||
}
|
||||
public override string ToString ()
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
|
||||
static internal string PathSeparator {
|
||||
get { return Path.PathSeparator.ToString (); }
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
static internal char PathSeparatorChar {
|
||||
get { return Path.PathSeparator; }
|
||||
}
|
||||
|
||||
static internal string PathSeparator
|
||||
{
|
||||
get { return Path.PathSeparator.ToString(); }
|
||||
}
|
||||
static internal char SeparatorChar {
|
||||
get { return Path.DirectorySeparatorChar; }
|
||||
}
|
||||
|
||||
static internal char PathSeparatorChar
|
||||
{
|
||||
get { return Path.PathSeparator; }
|
||||
}
|
||||
|
||||
static internal char SeparatorChar
|
||||
{
|
||||
get { return Path.DirectorySeparatorChar; }
|
||||
}
|
||||
|
||||
static internal string Separator
|
||||
{
|
||||
get { return Path.DirectorySeparatorChar.ToString(); }
|
||||
}
|
||||
}
|
||||
static internal string Separator {
|
||||
get { return Path.DirectorySeparatorChar.ToString (); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public class FileReader : InputStreamReader
|
||||
{
|
||||
//public FileReader (FilePath f) : base(f.GetPath ())
|
||||
//{
|
||||
//}
|
||||
{
|
||||
//public FileReader (FilePath f) : base(f.GetPath ())
|
||||
//{
|
||||
//}
|
||||
//path -> fileStream
|
||||
public FileReader(InputStream s) : base(s)
|
||||
{
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public class FilterInputStream : InputStream
|
||||
{
|
||||
protected InputStream In;
|
||||
{
|
||||
protected InputStream In;
|
||||
|
||||
public FilterInputStream(InputStream s)
|
||||
{
|
||||
In = s;
|
||||
}
|
||||
public FilterInputStream (InputStream s)
|
||||
{
|
||||
In = s;
|
||||
}
|
||||
|
||||
public override int Available()
|
||||
{
|
||||
return In.Available();
|
||||
}
|
||||
public override int Available ()
|
||||
{
|
||||
return In.Available ();
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
In.Close();
|
||||
}
|
||||
public override void Close ()
|
||||
{
|
||||
In.Close ();
|
||||
}
|
||||
|
||||
public override void Mark(int readlimit)
|
||||
{
|
||||
In.Mark(readlimit);
|
||||
}
|
||||
public override void Mark (int readlimit)
|
||||
{
|
||||
In.Mark (readlimit);
|
||||
}
|
||||
|
||||
public override bool MarkSupported()
|
||||
{
|
||||
return In.MarkSupported();
|
||||
}
|
||||
public override bool MarkSupported ()
|
||||
{
|
||||
return In.MarkSupported ();
|
||||
}
|
||||
|
||||
public override int Read()
|
||||
{
|
||||
return In.Read();
|
||||
}
|
||||
public override int Read ()
|
||||
{
|
||||
return In.Read ();
|
||||
}
|
||||
|
||||
public override int Read(byte[] buf)
|
||||
{
|
||||
return In.Read(buf);
|
||||
}
|
||||
public override int Read (byte[] buf)
|
||||
{
|
||||
return In.Read (buf);
|
||||
}
|
||||
|
||||
public override int Read(byte[] b, int off, int len)
|
||||
{
|
||||
return In.Read(b, off, len);
|
||||
}
|
||||
public override int Read (byte[] b, int off, int len)
|
||||
{
|
||||
return In.Read (b, off, len);
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
In.Reset();
|
||||
}
|
||||
public override void Reset ()
|
||||
{
|
||||
In.Reset ();
|
||||
}
|
||||
|
||||
public override long Skip(long cnt)
|
||||
{
|
||||
return In.Skip(cnt);
|
||||
}
|
||||
}
|
||||
public override long Skip (long cnt)
|
||||
{
|
||||
return In.Skip (cnt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public class FilterOutputStream : OutputStream
|
||||
{
|
||||
protected OutputStream Out;
|
||||
{
|
||||
protected OutputStream Out;
|
||||
|
||||
public FilterOutputStream(OutputStream os)
|
||||
{
|
||||
Out = os;
|
||||
}
|
||||
public FilterOutputStream (OutputStream os)
|
||||
{
|
||||
Out = os;
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
Out.Close();
|
||||
}
|
||||
public override void Close ()
|
||||
{
|
||||
Out.Close ();
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
Out.Flush();
|
||||
}
|
||||
public override void Flush ()
|
||||
{
|
||||
Out.Flush ();
|
||||
}
|
||||
|
||||
public override void Write(byte[] b)
|
||||
{
|
||||
Out.Write(b);
|
||||
}
|
||||
public override void Write (byte[] b)
|
||||
{
|
||||
Out.Write (b);
|
||||
}
|
||||
|
||||
public override void Write(int b)
|
||||
{
|
||||
Out.Write(b);
|
||||
}
|
||||
public override void Write (int b)
|
||||
{
|
||||
Out.Write (b);
|
||||
}
|
||||
|
||||
public override void Write(byte[] b, int offset, int len)
|
||||
{
|
||||
Out.Write(b, offset, len);
|
||||
}
|
||||
}
|
||||
public override void Write (byte[] b, int offset, int len)
|
||||
{
|
||||
Out.Write (b, offset, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,18 +6,15 @@ namespace SharpCifs.Util.Sharpen
|
||||
public class Hashtable : Dictionary<object, object>
|
||||
{
|
||||
public void Put(object key, object value)
|
||||
{
|
||||
if (this.ContainsKey(key))
|
||||
this[key] = value;
|
||||
else
|
||||
this.Add(key, value);
|
||||
{
|
||||
Add(key, value);
|
||||
}
|
||||
|
||||
public object Get(object key)
|
||||
{
|
||||
return this.ContainsKey(key)
|
||||
? this[key]
|
||||
: null;
|
||||
var m_key = Keys.SingleOrDefault(k => k.Equals(key));
|
||||
|
||||
return m_key != null ? this[m_key] : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,3 +34,4 @@ namespace SharpCifs.Util.Sharpen
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal interface ICallable<T>
|
||||
{
|
||||
T Call();
|
||||
}
|
||||
internal interface ICallable<T>
|
||||
{
|
||||
T Call ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ using System.Collections.Generic;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal interface IConcurrentMap<T, TU> : IDictionary<T, TU>
|
||||
{
|
||||
TU PutIfAbsent(T key, TU value);
|
||||
bool Remove(object key, object value);
|
||||
bool Replace(T key, TU oldValue, TU newValue);
|
||||
}
|
||||
{
|
||||
TU PutIfAbsent (T key, TU value);
|
||||
bool Remove (object key, object value);
|
||||
bool Replace (T key, TU oldValue, TU newValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public interface IExecutor
|
||||
{
|
||||
void Execute(IRunnable runnable);
|
||||
}
|
||||
{
|
||||
void Execute (IRunnable runnable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public interface IFilenameFilter
|
||||
{
|
||||
bool Accept(FilePath dir, string name);
|
||||
}
|
||||
{
|
||||
bool Accept (FilePath dir, string name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal interface IFuture<T>
|
||||
{
|
||||
bool Cancel(bool mayInterruptIfRunning);
|
||||
T Get();
|
||||
}
|
||||
{
|
||||
bool Cancel (bool mayInterruptIfRunning);
|
||||
T Get ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal interface IPrivilegedAction<T>
|
||||
{
|
||||
T Run();
|
||||
}
|
||||
internal interface IPrivilegedAction<T>
|
||||
{
|
||||
T Run ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public interface IRunnable
|
||||
{
|
||||
void Run();
|
||||
}
|
||||
{
|
||||
void Run ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,156 +4,147 @@ using System.IO;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public class InputStream : IDisposable
|
||||
{
|
||||
private long _mark;
|
||||
protected Stream Wrapped;
|
||||
protected Stream BaseStream;
|
||||
{
|
||||
private long _mark;
|
||||
protected Stream Wrapped;
|
||||
protected Stream BaseStream;
|
||||
|
||||
public static implicit operator InputStream(Stream s)
|
||||
{
|
||||
return Wrap(s);
|
||||
}
|
||||
public static implicit operator InputStream (Stream s)
|
||||
{
|
||||
return Wrap (s);
|
||||
}
|
||||
|
||||
public static implicit operator Stream(InputStream s)
|
||||
{
|
||||
return s.GetWrappedStream();
|
||||
}
|
||||
public static implicit operator Stream (InputStream s)
|
||||
{
|
||||
return s.GetWrappedStream ();
|
||||
}
|
||||
|
||||
public virtual int Available()
|
||||
{
|
||||
if (Wrapped is WrappedSystemStream)
|
||||
return ((WrappedSystemStream)Wrapped).InputStream.Available();
|
||||
return 0;
|
||||
}
|
||||
public virtual int Available ()
|
||||
{
|
||||
if (Wrapped is WrappedSystemStream)
|
||||
return ((WrappedSystemStream)Wrapped).InputStream.Available ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public virtual void Close()
|
||||
{
|
||||
if (Wrapped != null)
|
||||
{
|
||||
public virtual void Close ()
|
||||
{
|
||||
if (Wrapped != null) {
|
||||
//Stream.`Close` method deleted
|
||||
//Wrapped.Close();
|
||||
//Wrapped.Close ();
|
||||
Wrapped.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public void Dispose ()
|
||||
{
|
||||
Close ();
|
||||
}
|
||||
|
||||
internal Stream GetWrappedStream ()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
// Always create a wrapper stream (not directly Wrapped) since the subclass
|
||||
// may be overriding methods that need to be called when used through the Stream class
|
||||
return new WrappedSystemStream (this);
|
||||
}
|
||||
|
||||
internal Stream GetWrappedStream()
|
||||
{
|
||||
// Always create a wrapper stream (not directly Wrapped) since the subclass
|
||||
// may be overriding methods that need to be called when used through the Stream class
|
||||
return new WrappedSystemStream(this);
|
||||
}
|
||||
public virtual void Mark (int readlimit)
|
||||
{
|
||||
if (Wrapped is WrappedSystemStream)
|
||||
((WrappedSystemStream)Wrapped).InputStream.Mark (readlimit);
|
||||
else {
|
||||
if (BaseStream is WrappedSystemStream)
|
||||
((WrappedSystemStream)BaseStream).OnMark (readlimit);
|
||||
if (Wrapped != null)
|
||||
_mark = Wrapped.Position;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool MarkSupported ()
|
||||
{
|
||||
if (Wrapped is WrappedSystemStream)
|
||||
return ((WrappedSystemStream)Wrapped).InputStream.MarkSupported ();
|
||||
return ((Wrapped != null) && Wrapped.CanSeek);
|
||||
}
|
||||
|
||||
public virtual void Mark(int readlimit)
|
||||
{
|
||||
if (Wrapped is WrappedSystemStream)
|
||||
((WrappedSystemStream)Wrapped).InputStream.Mark(readlimit);
|
||||
else
|
||||
{
|
||||
if (BaseStream is WrappedSystemStream)
|
||||
((WrappedSystemStream)BaseStream).OnMark(readlimit);
|
||||
if (Wrapped != null)
|
||||
_mark = Wrapped.Position;
|
||||
}
|
||||
}
|
||||
public virtual int Read ()
|
||||
{
|
||||
if (Wrapped == null) {
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
return Wrapped.ReadByte ();
|
||||
}
|
||||
|
||||
public virtual bool MarkSupported()
|
||||
{
|
||||
if (Wrapped is WrappedSystemStream)
|
||||
return ((WrappedSystemStream)Wrapped).InputStream.MarkSupported();
|
||||
return ((Wrapped != null) && Wrapped.CanSeek);
|
||||
}
|
||||
public virtual int Read (byte[] buf)
|
||||
{
|
||||
return Read (buf, 0, buf.Length);
|
||||
}
|
||||
|
||||
public virtual int Read()
|
||||
{
|
||||
if (Wrapped == null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
return Wrapped.ReadByte();
|
||||
}
|
||||
public virtual int Read (byte[] b, int off, int len)
|
||||
{
|
||||
if (Wrapped is WrappedSystemStream)
|
||||
return ((WrappedSystemStream)Wrapped).InputStream.Read (b, off, len);
|
||||
|
||||
if (Wrapped != null) {
|
||||
int num = Wrapped.Read (b, off, len);
|
||||
return ((num <= 0) ? -1 : num);
|
||||
}
|
||||
int totalRead = 0;
|
||||
while (totalRead < len) {
|
||||
int nr = Read ();
|
||||
if (nr == -1)
|
||||
return -1;
|
||||
b[off + totalRead] = (byte)nr;
|
||||
totalRead++;
|
||||
}
|
||||
return totalRead;
|
||||
}
|
||||
|
||||
public virtual int Read(byte[] buf)
|
||||
{
|
||||
return Read(buf, 0, buf.Length);
|
||||
}
|
||||
public virtual void Reset ()
|
||||
{
|
||||
if (Wrapped is WrappedSystemStream)
|
||||
((WrappedSystemStream)Wrapped).InputStream.Reset ();
|
||||
else {
|
||||
if (Wrapped == null)
|
||||
throw new IOException ();
|
||||
Wrapped.Position = _mark;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int Read(byte[] b, int off, int len)
|
||||
{
|
||||
if (Wrapped is WrappedSystemStream)
|
||||
return ((WrappedSystemStream)Wrapped).InputStream.Read(b, off, len);
|
||||
public virtual long Skip (long cnt)
|
||||
{
|
||||
if (Wrapped is WrappedSystemStream)
|
||||
return ((WrappedSystemStream)Wrapped).InputStream.Skip (cnt);
|
||||
|
||||
long n = cnt;
|
||||
while (n > 0) {
|
||||
if (Read () == -1)
|
||||
return cnt - n;
|
||||
n--;
|
||||
}
|
||||
return cnt - n;
|
||||
}
|
||||
|
||||
internal virtual bool CanSeek ()
|
||||
{
|
||||
if (Wrapped != null)
|
||||
return Wrapped.CanSeek;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Wrapped != null)
|
||||
{
|
||||
int num = Wrapped.Read(b, off, len);
|
||||
return ((num <= 0) ? -1 : num);
|
||||
}
|
||||
int totalRead = 0;
|
||||
while (totalRead < len)
|
||||
{
|
||||
int nr = Read();
|
||||
if (nr == -1)
|
||||
return -1;
|
||||
b[off + totalRead] = (byte)nr;
|
||||
totalRead++;
|
||||
}
|
||||
return totalRead;
|
||||
}
|
||||
|
||||
public virtual void Reset()
|
||||
{
|
||||
if (Wrapped is WrappedSystemStream)
|
||||
((WrappedSystemStream)Wrapped).InputStream.Reset();
|
||||
else
|
||||
{
|
||||
if (Wrapped == null)
|
||||
throw new IOException();
|
||||
Wrapped.Position = _mark;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual long Skip(long cnt)
|
||||
{
|
||||
if (Wrapped is WrappedSystemStream)
|
||||
return ((WrappedSystemStream)Wrapped).InputStream.Skip(cnt);
|
||||
|
||||
long n = cnt;
|
||||
while (n > 0)
|
||||
{
|
||||
if (Read() == -1)
|
||||
return cnt - n;
|
||||
n--;
|
||||
}
|
||||
return cnt - n;
|
||||
}
|
||||
|
||||
internal virtual bool CanSeek()
|
||||
{
|
||||
if (Wrapped != null)
|
||||
return Wrapped.CanSeek;
|
||||
return false;
|
||||
}
|
||||
|
||||
internal virtual long Position
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Wrapped != null)
|
||||
return Wrapped.Position;
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
set
|
||||
{
|
||||
if (Wrapped != null)
|
||||
Wrapped.Position = value;
|
||||
else
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
internal virtual long Position {
|
||||
get
|
||||
{
|
||||
if (Wrapped != null)
|
||||
return Wrapped.Position;
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
set {
|
||||
if (Wrapped != null)
|
||||
Wrapped.Position = value;
|
||||
else
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual long Length
|
||||
{
|
||||
@@ -161,18 +152,18 @@ namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
if (Wrapped != null)
|
||||
{
|
||||
return Wrapped.Length;
|
||||
return Wrapped.Length;
|
||||
}
|
||||
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
static internal InputStream Wrap(Stream s)
|
||||
{
|
||||
InputStream stream = new InputStream();
|
||||
stream.Wrapped = s;
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
static internal InputStream Wrap (Stream s)
|
||||
{
|
||||
InputStream stream = new InputStream ();
|
||||
stream.Wrapped = s;
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,23 +4,22 @@ using System.Text;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public class InputStreamReader : StreamReader
|
||||
{
|
||||
{
|
||||
//Stream(string path) constructor deleted
|
||||
//protected InputStreamReader (string file) : base(file)
|
||||
//{
|
||||
//}
|
||||
//protected InputStreamReader (string file) : base(file)
|
||||
//{
|
||||
//}
|
||||
|
||||
public InputStreamReader(InputStream s) : base(s.GetWrappedStream())
|
||||
{
|
||||
}
|
||||
public InputStreamReader (InputStream s) : base(s.GetWrappedStream ())
|
||||
{
|
||||
}
|
||||
|
||||
public InputStreamReader(InputStream s, string encoding)
|
||||
: base(s.GetWrappedStream(), Encoding.GetEncoding(encoding))
|
||||
{
|
||||
}
|
||||
public InputStreamReader (InputStream s, string encoding) : base(s.GetWrappedStream (), Encoding.GetEncoding (encoding))
|
||||
{
|
||||
}
|
||||
|
||||
public InputStreamReader(InputStream s, Encoding e) : base(s.GetWrappedStream(), e)
|
||||
{
|
||||
}
|
||||
}
|
||||
public InputStreamReader (InputStream s, Encoding e) : base(s.GetWrappedStream (), e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,52 +5,49 @@ using System.Collections.Generic;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public interface ITerator
|
||||
{
|
||||
bool HasNext();
|
||||
object Next();
|
||||
void Remove();
|
||||
}
|
||||
{
|
||||
bool HasNext ();
|
||||
object Next ();
|
||||
void Remove ();
|
||||
}
|
||||
|
||||
public abstract class Iterator<T> : IEnumerator<T>, ITerator
|
||||
{
|
||||
private T _lastValue;
|
||||
public abstract class Iterator<T> : IEnumerator<T>, ITerator
|
||||
{
|
||||
private T _lastValue;
|
||||
|
||||
object ITerator.Next()
|
||||
{
|
||||
return Next();
|
||||
}
|
||||
object ITerator.Next ()
|
||||
{
|
||||
return Next ();
|
||||
}
|
||||
|
||||
public abstract bool HasNext();
|
||||
public abstract T Next();
|
||||
public abstract void Remove();
|
||||
public abstract bool HasNext ();
|
||||
public abstract T Next ();
|
||||
public abstract void Remove ();
|
||||
|
||||
bool IEnumerator.MoveNext()
|
||||
{
|
||||
if (HasNext())
|
||||
{
|
||||
_lastValue = Next();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool IEnumerator.MoveNext ()
|
||||
{
|
||||
if (HasNext ()) {
|
||||
_lastValue = Next ();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void IEnumerator.Reset()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
void IEnumerator.Reset ()
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
}
|
||||
void IDisposable.Dispose ()
|
||||
{
|
||||
}
|
||||
|
||||
T IEnumerator<T>.Current
|
||||
{
|
||||
get { return _lastValue; }
|
||||
}
|
||||
T IEnumerator<T>.Current {
|
||||
get { return _lastValue; }
|
||||
}
|
||||
|
||||
object IEnumerator.Current
|
||||
{
|
||||
get { return _lastValue; }
|
||||
}
|
||||
}
|
||||
object IEnumerator.Current {
|
||||
get { return _lastValue; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ using System;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal class LinkageError : Exception
|
||||
{
|
||||
public LinkageError(string msg) : base(msg)
|
||||
{
|
||||
}
|
||||
}
|
||||
{
|
||||
public LinkageError (string msg) : base(msg)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,16 +4,15 @@ using System;
|
||||
using System.Text;
|
||||
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
// **************************************************************
|
||||
// * Raw implementation of the MD5 hash algorithm
|
||||
// * from RFC 1321.
|
||||
// *
|
||||
// * Written By: Reid Borsuk and Jenny Zheng
|
||||
// * Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// **************************************************************
|
||||
{ // **************************************************************
|
||||
// * Raw implementation of the MD5 hash algorithm
|
||||
// * from RFC 1321.
|
||||
// *
|
||||
// * Written By: Reid Borsuk and Jenny Zheng
|
||||
// * Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// **************************************************************
|
||||
|
||||
// Simple struct for the (a,b,c,d) which is used to compute the mesage digest.
|
||||
// Simple struct for the (a,b,c,d) which is used to compute the mesage digest.
|
||||
struct AbcdStruct
|
||||
{
|
||||
public uint A;
|
||||
@@ -30,13 +29,9 @@ namespace SharpCifs.Util.Sharpen
|
||||
public static byte[] GetHash(string input, Encoding encoding)
|
||||
{
|
||||
if (null == input)
|
||||
throw new ArgumentNullException(
|
||||
"input", "Unable to calculate hash over null input data");
|
||||
throw new ArgumentNullException("input", "Unable to calculate hash over null input data");
|
||||
if (null == encoding)
|
||||
throw new ArgumentNullException(
|
||||
"encoding",
|
||||
"Unable to calculate hash over a string without a default encoding. "
|
||||
+ "Consider using the GetHash(string) overload to use UTF8 Encoding");
|
||||
throw new ArgumentNullException("encoding", "Unable to calculate hash over a string without a default encoding. Consider using the GetHash(string) overload to use UTF8 Encoding");
|
||||
|
||||
byte[] target = encoding.GetBytes(input);
|
||||
|
||||
@@ -51,8 +46,7 @@ namespace SharpCifs.Util.Sharpen
|
||||
public static string GetHashString(byte[] input)
|
||||
{
|
||||
if (null == input)
|
||||
throw new ArgumentNullException(
|
||||
"input", "Unable to calculate hash over null input data");
|
||||
throw new ArgumentNullException("input", "Unable to calculate hash over null input data");
|
||||
|
||||
string retval = BitConverter.ToString(GetHash(input));
|
||||
retval = retval.Replace("-", "");
|
||||
@@ -63,13 +57,9 @@ namespace SharpCifs.Util.Sharpen
|
||||
public static string GetHashString(string input, Encoding encoding)
|
||||
{
|
||||
if (null == input)
|
||||
throw new ArgumentNullException(
|
||||
"input", "Unable to calculate hash over null input data");
|
||||
throw new ArgumentNullException("input", "Unable to calculate hash over null input data");
|
||||
if (null == encoding)
|
||||
throw new ArgumentNullException(
|
||||
"encoding",
|
||||
"Unable to calculate hash over a string without a default encoding. "
|
||||
+ "Consider using the GetHashString(string) overload to use UTF8 Encoding");
|
||||
throw new ArgumentNullException("encoding", "Unable to calculate hash over a string without a default encoding. Consider using the GetHashString(string) overload to use UTF8 Encoding");
|
||||
|
||||
byte[] target = encoding.GetBytes(input);
|
||||
|
||||
@@ -84,8 +74,7 @@ namespace SharpCifs.Util.Sharpen
|
||||
public static byte[] GetHash(byte[] input)
|
||||
{
|
||||
if (null == input)
|
||||
throw new ArgumentNullException(
|
||||
"input", "Unable to calculate hash over null input data");
|
||||
throw new ArgumentNullException("input", "Unable to calculate hash over null input data");
|
||||
|
||||
//Intitial values defined in RFC 1321
|
||||
AbcdStruct abcd = new AbcdStruct();
|
||||
@@ -102,18 +91,10 @@ namespace SharpCifs.Util.Sharpen
|
||||
startIndex += 64;
|
||||
}
|
||||
// The final data block.
|
||||
return GetHashFinalBlock(input,
|
||||
startIndex,
|
||||
input.Length - startIndex,
|
||||
abcd,
|
||||
(Int64)input.Length * 8);
|
||||
return GetHashFinalBlock(input, startIndex, input.Length - startIndex, abcd, (Int64)input.Length * 8);
|
||||
}
|
||||
|
||||
internal static byte[] GetHashFinalBlock(byte[] input,
|
||||
int ibStart,
|
||||
int cbSize,
|
||||
AbcdStruct abcd,
|
||||
Int64 len)
|
||||
internal static byte[] GetHashFinalBlock(byte[] input, int ibStart, int cbSize, AbcdStruct abcd, Int64 len)
|
||||
{
|
||||
byte[] working = new byte[64];
|
||||
byte[] length = BitConverter.GetBytes(len);
|
||||
@@ -148,11 +129,11 @@ namespace SharpCifs.Util.Sharpen
|
||||
|
||||
// Performs a single block transform of MD5 for a given set of ABCD inputs
|
||||
/* If implementing your own hashing framework, be sure to set the initial ABCD correctly according to RFC 1321:
|
||||
// A = 0x67452301;
|
||||
// B = 0xefcdab89;
|
||||
// C = 0x98badcfe;
|
||||
// D = 0x10325476;
|
||||
*/
|
||||
// A = 0x67452301;
|
||||
// B = 0xefcdab89;
|
||||
// C = 0x98badcfe;
|
||||
// D = 0x10325476;
|
||||
*/
|
||||
internal static void GetHashBlock(byte[] input, ref AbcdStruct abcdValue, int ibStart)
|
||||
{
|
||||
uint[] temp = Converter(input, ibStart);
|
||||
@@ -276,8 +257,7 @@ namespace SharpCifs.Util.Sharpen
|
||||
private static uint[] Converter(byte[] input, int ibStart)
|
||||
{
|
||||
if (null == input)
|
||||
throw new ArgumentNullException(
|
||||
"input", "Unable convert null array to array of uInts");
|
||||
throw new ArgumentNullException("input", "Unable convert null array to array of uInts");
|
||||
|
||||
uint[] result = new uint[16];
|
||||
|
||||
|
||||
@@ -4,84 +4,80 @@ using System.Text.RegularExpressions;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal class Matcher
|
||||
{
|
||||
private int _current;
|
||||
private MatchCollection _matches;
|
||||
private Regex _regex;
|
||||
private string _str;
|
||||
{
|
||||
private int _current;
|
||||
private MatchCollection _matches;
|
||||
private Regex _regex;
|
||||
private string _str;
|
||||
|
||||
internal Matcher(Regex regex, string str)
|
||||
{
|
||||
this._regex = regex;
|
||||
this._str = str;
|
||||
}
|
||||
internal Matcher (Regex regex, string str)
|
||||
{
|
||||
this._regex = regex;
|
||||
this._str = str;
|
||||
}
|
||||
|
||||
public int End()
|
||||
{
|
||||
if ((_matches == null) || (_current >= _matches.Count))
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
return (_matches[_current].Index + _matches[_current].Length);
|
||||
}
|
||||
public int End ()
|
||||
{
|
||||
if ((_matches == null) || (_current >= _matches.Count)) {
|
||||
throw new InvalidOperationException ();
|
||||
}
|
||||
return (_matches[_current].Index + _matches[_current].Length);
|
||||
}
|
||||
|
||||
public bool Find()
|
||||
{
|
||||
if (_matches == null)
|
||||
{
|
||||
_matches = _regex.Matches(_str);
|
||||
_current = 0;
|
||||
}
|
||||
return (_current < _matches.Count);
|
||||
}
|
||||
public bool Find ()
|
||||
{
|
||||
if (_matches == null) {
|
||||
_matches = _regex.Matches (_str);
|
||||
_current = 0;
|
||||
}
|
||||
return (_current < _matches.Count);
|
||||
}
|
||||
|
||||
public bool Find(int index)
|
||||
{
|
||||
_matches = _regex.Matches(_str, index);
|
||||
_current = 0;
|
||||
return (_matches.Count > 0);
|
||||
}
|
||||
public bool Find (int index)
|
||||
{
|
||||
_matches = _regex.Matches (_str, index);
|
||||
_current = 0;
|
||||
return (_matches.Count > 0);
|
||||
}
|
||||
|
||||
public string Group(int n)
|
||||
{
|
||||
if ((_matches == null) || (_current >= _matches.Count))
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
Group grp = _matches[_current].Groups[n];
|
||||
return grp.Success ? grp.Value : null;
|
||||
}
|
||||
public string Group (int n)
|
||||
{
|
||||
if ((_matches == null) || (_current >= _matches.Count)) {
|
||||
throw new InvalidOperationException ();
|
||||
}
|
||||
Group grp = _matches[_current].Groups[n];
|
||||
return grp.Success ? grp.Value : null;
|
||||
}
|
||||
|
||||
public bool Matches()
|
||||
{
|
||||
_matches = null;
|
||||
return Find();
|
||||
}
|
||||
public bool Matches ()
|
||||
{
|
||||
_matches = null;
|
||||
return Find ();
|
||||
}
|
||||
|
||||
public string ReplaceFirst(string txt)
|
||||
{
|
||||
return _regex.Replace(_str, txt, 1);
|
||||
}
|
||||
public string ReplaceFirst (string txt)
|
||||
{
|
||||
return _regex.Replace (_str, txt, 1);
|
||||
}
|
||||
|
||||
public Matcher Reset(CharSequence str)
|
||||
{
|
||||
return Reset(str.ToString());
|
||||
}
|
||||
public Matcher Reset (CharSequence str)
|
||||
{
|
||||
return Reset (str.ToString ());
|
||||
}
|
||||
|
||||
public Matcher Reset(string str)
|
||||
{
|
||||
_matches = null;
|
||||
this._str = str;
|
||||
return this;
|
||||
}
|
||||
public Matcher Reset (string str)
|
||||
{
|
||||
_matches = null;
|
||||
this._str = str;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int Start()
|
||||
{
|
||||
if ((_matches == null) || (_current >= _matches.Count))
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
return _matches[_current].Index;
|
||||
}
|
||||
}
|
||||
public int Start ()
|
||||
{
|
||||
if ((_matches == null) || (_current >= _matches.Count)) {
|
||||
throw new InvalidOperationException ();
|
||||
}
|
||||
return _matches[_current].Index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,58 +6,55 @@ using System.Security.Cryptography;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public abstract class MessageDigest
|
||||
{
|
||||
public void Digest(byte[] buffer, int o, int len)
|
||||
{
|
||||
byte[] d = Digest();
|
||||
d.CopyTo(buffer, o);
|
||||
}
|
||||
{
|
||||
public void Digest (byte[] buffer, int o, int len)
|
||||
{
|
||||
byte[] d = Digest ();
|
||||
d.CopyTo (buffer, o);
|
||||
}
|
||||
|
||||
public byte[] Digest(byte[] buffer)
|
||||
{
|
||||
Update(buffer);
|
||||
return Digest();
|
||||
}
|
||||
public byte[] Digest (byte[] buffer)
|
||||
{
|
||||
Update (buffer);
|
||||
return Digest ();
|
||||
}
|
||||
|
||||
public abstract byte[] Digest();
|
||||
public abstract int GetDigestLength();
|
||||
public static MessageDigest GetInstance(string algorithm)
|
||||
{
|
||||
switch (algorithm.ToLower())
|
||||
{
|
||||
case "sha-1":
|
||||
//System.Security.CryptographySHA1Managed not found
|
||||
//return new MessageDigest<SHA1Managed> ();
|
||||
return new MessageDigest<System.Security.Cryptography.SHA1>();
|
||||
case "md5":
|
||||
return new MessageDigest<Md5Managed>();
|
||||
public abstract byte[] Digest ();
|
||||
public abstract int GetDigestLength ();
|
||||
public static MessageDigest GetInstance (string algorithm)
|
||||
{
|
||||
switch (algorithm.ToLower ()) {
|
||||
case "sha-1":
|
||||
//System.Security.CryptographySHA1Managed not found
|
||||
//return new MessageDigest<SHA1Managed> ();
|
||||
return new MessageDigest<System.Security.Cryptography.SHA1>();
|
||||
case "md5":
|
||||
return new MessageDigest<Md5Managed> ();
|
||||
}
|
||||
throw new NotSupportedException(
|
||||
string.Format("The requested algorithm \"{0}\" is not supported.", algorithm));
|
||||
}
|
||||
throw new NotSupportedException (string.Format ("The requested algorithm \"{0}\" is not supported.", algorithm));
|
||||
}
|
||||
|
||||
public abstract void Reset();
|
||||
public abstract void Update(byte[] b);
|
||||
public abstract void Update(byte b);
|
||||
public abstract void Update(byte[] b, int offset, int len);
|
||||
}
|
||||
public abstract void Reset ();
|
||||
public abstract void Update (byte[] b);
|
||||
public abstract void Update (byte b);
|
||||
public abstract void Update (byte[] b, int offset, int len);
|
||||
}
|
||||
|
||||
|
||||
public class MessageDigest<TAlgorithm>
|
||||
: MessageDigest where TAlgorithm : HashAlgorithm //, new() //use static `Create` method
|
||||
{
|
||||
private TAlgorithm _hash;
|
||||
public class MessageDigest<TAlgorithm> : MessageDigest where TAlgorithm : HashAlgorithm //, new() //use static `Create` method
|
||||
{
|
||||
private TAlgorithm _hash;
|
||||
//private CryptoStream _stream; //don't work .NET Core
|
||||
private MemoryStream _stream;
|
||||
|
||||
|
||||
public MessageDigest()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
public MessageDigest ()
|
||||
{
|
||||
Init ();
|
||||
}
|
||||
|
||||
public override byte[] Digest()
|
||||
{
|
||||
public override byte[] Digest ()
|
||||
{
|
||||
//CryptoStream -> MemoryStream, needless method
|
||||
//_stream.FlushFinalBlock ();
|
||||
|
||||
@@ -65,30 +62,29 @@ namespace SharpCifs.Util.Sharpen
|
||||
//byte[] hash = _hash.Hash;
|
||||
byte[] hash = _hash.ComputeHash(_stream.ToArray());
|
||||
|
||||
Reset();
|
||||
return hash;
|
||||
Reset ();
|
||||
return hash;
|
||||
}
|
||||
|
||||
public void Dispose ()
|
||||
{
|
||||
if (_stream != null) {
|
||||
_stream.Dispose ();
|
||||
}
|
||||
_stream = null;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_stream != null)
|
||||
{
|
||||
_stream.Dispose();
|
||||
}
|
||||
_stream = null;
|
||||
}
|
||||
public override int GetDigestLength ()
|
||||
{
|
||||
return (_hash.HashSize / 8);
|
||||
}
|
||||
|
||||
public override int GetDigestLength()
|
||||
{
|
||||
return (_hash.HashSize / 8);
|
||||
}
|
||||
|
||||
private void Init()
|
||||
{
|
||||
private void Init ()
|
||||
{
|
||||
//use static `Create` method
|
||||
//_hash = Activator.CreateInstance<TAlgorithm> ();
|
||||
var createMethod = typeof(TAlgorithm).GetRuntimeMethod("Create", new Type[0]);
|
||||
_hash = (TAlgorithm)createMethod.Invoke(null, new object[] { });
|
||||
_hash = (TAlgorithm)createMethod.Invoke(null, new object[] {});
|
||||
|
||||
//HashAlgorithm cannot cast `ICryptoTransform` on .NET Core, gave up using CryptoStream.
|
||||
//_stream = new CryptoStream(Stream.Null, _hash, CryptoStreamMode.Write);
|
||||
@@ -96,27 +92,27 @@ namespace SharpCifs.Util.Sharpen
|
||||
_stream = new MemoryStream();
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
Dispose();
|
||||
Init();
|
||||
}
|
||||
public override void Reset ()
|
||||
{
|
||||
Dispose ();
|
||||
Init ();
|
||||
}
|
||||
|
||||
public override void Update(byte[] input)
|
||||
{
|
||||
_stream.Write(input, 0, input.Length);
|
||||
}
|
||||
public override void Update (byte[] input)
|
||||
{
|
||||
_stream.Write (input, 0, input.Length);
|
||||
}
|
||||
|
||||
public override void Update(byte input)
|
||||
{
|
||||
_stream.WriteByte(input);
|
||||
}
|
||||
public override void Update (byte input)
|
||||
{
|
||||
_stream.WriteByte (input);
|
||||
}
|
||||
|
||||
public override void Update(byte[] input, int index, int count)
|
||||
{
|
||||
if (count < 0)
|
||||
Console.WriteLine("Argh!");
|
||||
_stream.Write(input, index, count);
|
||||
}
|
||||
}
|
||||
public override void Update (byte[] input, int index, int count)
|
||||
{
|
||||
if (count < 0)
|
||||
Console.WriteLine ("Argh!");
|
||||
_stream.Write (input, index, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,15 +3,15 @@ using System.IO;
|
||||
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public class NetworkStream : Stream
|
||||
public class NetworkStream : Stream
|
||||
{
|
||||
SocketEx _socket;
|
||||
|
||||
|
||||
public NetworkStream(SocketEx socket)
|
||||
{
|
||||
_socket = socket;
|
||||
}
|
||||
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
@@ -29,7 +29,7 @@ namespace SharpCifs.Util.Sharpen
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
// throw new NotImplementedException();
|
||||
// throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override long Length
|
||||
|
||||
@@ -4,22 +4,22 @@ using System.IO;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal class ObjectInputStream : InputStream
|
||||
{
|
||||
private BinaryReader _reader;
|
||||
{
|
||||
private BinaryReader _reader;
|
||||
|
||||
public ObjectInputStream(InputStream s)
|
||||
{
|
||||
_reader = new BinaryReader(s.GetWrappedStream());
|
||||
}
|
||||
public ObjectInputStream (InputStream s)
|
||||
{
|
||||
_reader = new BinaryReader (s.GetWrappedStream ());
|
||||
}
|
||||
|
||||
public int ReadInt()
|
||||
{
|
||||
return _reader.ReadInt32();
|
||||
}
|
||||
public int ReadInt ()
|
||||
{
|
||||
return _reader.ReadInt32 ();
|
||||
}
|
||||
|
||||
public object ReadObject()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
public object ReadObject ()
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,17 +3,17 @@ using System.IO;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal class ObjectOutputStream : OutputStream
|
||||
{
|
||||
private BinaryWriter _bw;
|
||||
{
|
||||
private BinaryWriter _bw;
|
||||
|
||||
public ObjectOutputStream(OutputStream os)
|
||||
{
|
||||
_bw = new BinaryWriter(os.GetWrappedStream());
|
||||
}
|
||||
public ObjectOutputStream (OutputStream os)
|
||||
{
|
||||
_bw = new BinaryWriter (os.GetWrappedStream ());
|
||||
}
|
||||
|
||||
public virtual void WriteInt(int i)
|
||||
{
|
||||
_bw.Write(i);
|
||||
}
|
||||
}
|
||||
public virtual void WriteInt (int i)
|
||||
{
|
||||
_bw.Write (i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,91 +4,83 @@ using System.IO;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public class OutputStream : IDisposable
|
||||
{
|
||||
protected Stream Wrapped;
|
||||
{
|
||||
protected Stream Wrapped;
|
||||
|
||||
public static implicit operator OutputStream(Stream s)
|
||||
{
|
||||
return Wrap(s);
|
||||
}
|
||||
public static implicit operator OutputStream (Stream s)
|
||||
{
|
||||
return Wrap (s);
|
||||
}
|
||||
|
||||
public static implicit operator Stream(OutputStream s)
|
||||
{
|
||||
return s.GetWrappedStream();
|
||||
}
|
||||
|
||||
public virtual void Close()
|
||||
{
|
||||
if (Wrapped != null)
|
||||
{
|
||||
public static implicit operator Stream (OutputStream s)
|
||||
{
|
||||
return s.GetWrappedStream ();
|
||||
}
|
||||
|
||||
public virtual void Close ()
|
||||
{
|
||||
if (Wrapped != null) {
|
||||
//Stream.`Close` method deleted
|
||||
//Wrapped.Close ();
|
||||
Wrapped.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
public void Dispose ()
|
||||
{
|
||||
Close ();
|
||||
}
|
||||
|
||||
public virtual void Flush()
|
||||
{
|
||||
if (Wrapped != null)
|
||||
{
|
||||
Wrapped.Flush();
|
||||
}
|
||||
}
|
||||
public virtual void Flush ()
|
||||
{
|
||||
if (Wrapped != null) {
|
||||
Wrapped.Flush ();
|
||||
}
|
||||
}
|
||||
|
||||
internal Stream GetWrappedStream()
|
||||
{
|
||||
// Always create a wrapper stream (not directly Wrapped) since the subclass
|
||||
// may be overriding methods that need to be called when used through the Stream class
|
||||
return new WrappedSystemStream(this);
|
||||
}
|
||||
internal Stream GetWrappedStream ()
|
||||
{
|
||||
// Always create a wrapper stream (not directly Wrapped) since the subclass
|
||||
// may be overriding methods that need to be called when used through the Stream class
|
||||
return new WrappedSystemStream (this);
|
||||
}
|
||||
|
||||
static internal OutputStream Wrap(Stream s)
|
||||
{
|
||||
OutputStream stream = new OutputStream();
|
||||
stream.Wrapped = s;
|
||||
return stream;
|
||||
}
|
||||
static internal OutputStream Wrap (Stream s)
|
||||
{
|
||||
OutputStream stream = new OutputStream ();
|
||||
stream.Wrapped = s;
|
||||
return stream;
|
||||
}
|
||||
|
||||
public virtual void Write(int b)
|
||||
{
|
||||
if (Wrapped is WrappedSystemStream)
|
||||
((WrappedSystemStream)Wrapped).OutputStream.Write(b);
|
||||
else
|
||||
{
|
||||
if (Wrapped == null)
|
||||
throw new NotImplementedException();
|
||||
Wrapped.WriteByte((byte)b);
|
||||
}
|
||||
}
|
||||
public virtual void Write (int b)
|
||||
{
|
||||
if (Wrapped is WrappedSystemStream)
|
||||
((WrappedSystemStream)Wrapped).OutputStream.Write (b);
|
||||
else {
|
||||
if (Wrapped == null)
|
||||
throw new NotImplementedException ();
|
||||
Wrapped.WriteByte ((byte)b);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Write(byte[] b)
|
||||
{
|
||||
Write(b, 0, b.Length);
|
||||
}
|
||||
public virtual void Write (byte[] b)
|
||||
{
|
||||
Write (b, 0, b.Length);
|
||||
}
|
||||
|
||||
public virtual void Write(byte[] b, int offset, int len)
|
||||
{
|
||||
if (Wrapped is WrappedSystemStream)
|
||||
((WrappedSystemStream)Wrapped).OutputStream.Write(b, offset, len);
|
||||
else
|
||||
{
|
||||
if (Wrapped != null)
|
||||
{
|
||||
Wrapped.Write(b, offset, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
Write(b[i + offset]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public virtual void Write (byte[] b, int offset, int len)
|
||||
{
|
||||
if (Wrapped is WrappedSystemStream)
|
||||
((WrappedSystemStream)Wrapped).OutputStream.Write (b, offset, len);
|
||||
else {
|
||||
if (Wrapped != null) {
|
||||
Wrapped.Write (b, offset, len);
|
||||
} else {
|
||||
for (int i = 0; i < len; i++) {
|
||||
Write (b[i + offset]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,20 +4,17 @@ using System.Text;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal class OutputStreamWriter : StreamWriter
|
||||
{
|
||||
public OutputStreamWriter(OutputStream stream)
|
||||
: base(stream.GetWrappedStream())
|
||||
{
|
||||
}
|
||||
{
|
||||
public OutputStreamWriter (OutputStream stream) : base(stream.GetWrappedStream ())
|
||||
{
|
||||
}
|
||||
|
||||
public OutputStreamWriter(OutputStream stream, string encoding)
|
||||
: base(stream.GetWrappedStream(), Extensions.GetEncoding(encoding))
|
||||
{
|
||||
}
|
||||
public OutputStreamWriter (OutputStream stream, string encoding) : base(stream.GetWrappedStream (), Extensions.GetEncoding (encoding))
|
||||
{
|
||||
}
|
||||
|
||||
public OutputStreamWriter(OutputStream stream, Encoding encoding)
|
||||
: base(stream.GetWrappedStream(), encoding)
|
||||
{
|
||||
}
|
||||
}
|
||||
public OutputStreamWriter (OutputStream stream, Encoding encoding) : base(stream.GetWrappedStream (), encoding)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,206 +3,170 @@ using System.Threading;
|
||||
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal class PipedInputStream : InputStream
|
||||
{
|
||||
private byte[] _oneBuffer;
|
||||
public const int PipeSize = 1024;
|
||||
internal class PipedInputStream : InputStream
|
||||
{
|
||||
private byte[] _oneBuffer;
|
||||
public const int PipeSize = 1024;
|
||||
|
||||
protected byte[] Buffer;
|
||||
private bool _closed;
|
||||
private ManualResetEvent _dataEvent;
|
||||
private int _end;
|
||||
private int _start;
|
||||
private object _thisLock;
|
||||
private bool _allowGrow = false;
|
||||
|
||||
public int In {
|
||||
get { return _start; }
|
||||
set { _start = value; }
|
||||
}
|
||||
|
||||
public int Out {
|
||||
get { return _end; }
|
||||
set { _end = value; }
|
||||
}
|
||||
|
||||
protected byte[] Buffer;
|
||||
private bool _closed;
|
||||
private ManualResetEvent _dataEvent;
|
||||
private int _end;
|
||||
private int _start;
|
||||
private object _thisLock;
|
||||
private bool _allowGrow = false;
|
||||
public PipedInputStream ()
|
||||
{
|
||||
_thisLock = new object ();
|
||||
_dataEvent = new ManualResetEvent (false);
|
||||
Buffer = new byte[PipeSize + 1];
|
||||
}
|
||||
|
||||
public int In
|
||||
{
|
||||
get { return _start; }
|
||||
set { _start = value; }
|
||||
}
|
||||
public PipedInputStream (PipedOutputStream os): this ()
|
||||
{
|
||||
os.Attach (this);
|
||||
}
|
||||
|
||||
public int Out
|
||||
{
|
||||
get { return _end; }
|
||||
set { _end = value; }
|
||||
}
|
||||
public override void Close ()
|
||||
{
|
||||
lock (_thisLock) {
|
||||
_closed = true;
|
||||
_dataEvent.Set ();
|
||||
}
|
||||
}
|
||||
|
||||
public PipedInputStream()
|
||||
{
|
||||
_thisLock = new object();
|
||||
_dataEvent = new ManualResetEvent(false);
|
||||
Buffer = new byte[PipeSize + 1];
|
||||
}
|
||||
public override int Available ()
|
||||
{
|
||||
lock (_thisLock) {
|
||||
if (_start <= _end) {
|
||||
return (_end - _start);
|
||||
}
|
||||
return ((Buffer.Length - _start) + _end);
|
||||
}
|
||||
}
|
||||
|
||||
public PipedInputStream(PipedOutputStream os) : this()
|
||||
{
|
||||
os.Attach(this);
|
||||
}
|
||||
public override int Read ()
|
||||
{
|
||||
if (_oneBuffer == null)
|
||||
_oneBuffer = new byte[1];
|
||||
if (Read (_oneBuffer, 0, 1) == -1)
|
||||
return -1;
|
||||
return _oneBuffer[0];
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
lock (_thisLock)
|
||||
{
|
||||
_closed = true;
|
||||
_dataEvent.Set();
|
||||
}
|
||||
}
|
||||
|
||||
public override int Available()
|
||||
{
|
||||
lock (_thisLock)
|
||||
{
|
||||
if (_start <= _end)
|
||||
{
|
||||
return (_end - _start);
|
||||
}
|
||||
return ((Buffer.Length - _start) + _end);
|
||||
}
|
||||
}
|
||||
|
||||
public override int Read()
|
||||
{
|
||||
if (_oneBuffer == null)
|
||||
_oneBuffer = new byte[1];
|
||||
if (Read(_oneBuffer, 0, 1) == -1)
|
||||
return -1;
|
||||
return _oneBuffer[0];
|
||||
}
|
||||
|
||||
public override int Read(byte[] b, int offset, int len)
|
||||
{
|
||||
int length = 0;
|
||||
do
|
||||
{
|
||||
_dataEvent.WaitOne();
|
||||
lock (_thisLock)
|
||||
{
|
||||
if (_closed && Available() == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (_start < _end)
|
||||
{
|
||||
length = Math.Min(len, _end - _start);
|
||||
Array.Copy(Buffer, _start, b, offset, length);
|
||||
_start += length;
|
||||
}
|
||||
else if (_start > _end)
|
||||
{
|
||||
length = Math.Min(len, Buffer.Length - _start);
|
||||
Array.Copy(Buffer, _start, b, offset, length);
|
||||
len -= length;
|
||||
_start = (_start + length) % Buffer.Length;
|
||||
if (len > 0)
|
||||
{
|
||||
int i = Math.Min(len, _end);
|
||||
Array.Copy(Buffer, 0, b, offset + length, i);
|
||||
_start += i;
|
||||
length += i;
|
||||
}
|
||||
}
|
||||
if (_start == _end && !_closed)
|
||||
{
|
||||
_dataEvent.Reset();
|
||||
}
|
||||
Monitor.PulseAll(_thisLock);
|
||||
}
|
||||
} while (length == 0);
|
||||
return length;
|
||||
}
|
||||
|
||||
private int Allocate(int len)
|
||||
{
|
||||
int alen;
|
||||
while ((alen = TryAllocate(len)) == 0)
|
||||
{
|
||||
// Wait until somebody reads data
|
||||
try
|
||||
{
|
||||
Monitor.Wait(_thisLock);
|
||||
}
|
||||
catch
|
||||
{
|
||||
_closed = true;
|
||||
_dataEvent.Set();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return alen;
|
||||
}
|
||||
|
||||
int TryAllocate(int len)
|
||||
{
|
||||
int free;
|
||||
if (_start <= _end)
|
||||
{
|
||||
free = (Buffer.Length - _end) + _start;
|
||||
}
|
||||
else
|
||||
{
|
||||
free = _start - _end;
|
||||
}
|
||||
if (free <= len)
|
||||
{
|
||||
if (!_allowGrow)
|
||||
return free > 0 ? free - 1 : 0;
|
||||
int sizeInc = (len - free) + 1;
|
||||
byte[] destinationArray = new byte[Buffer.Length + sizeInc];
|
||||
if (_start <= _end)
|
||||
{
|
||||
Array.Copy(Buffer, _start, destinationArray, _start, _end - _start);
|
||||
}
|
||||
else
|
||||
{
|
||||
Array.Copy(Buffer,
|
||||
0,
|
||||
destinationArray,
|
||||
0,
|
||||
_end);
|
||||
Array.Copy(Buffer,
|
||||
_start,
|
||||
destinationArray,
|
||||
_start + sizeInc,
|
||||
Buffer.Length - _start);
|
||||
_start += sizeInc;
|
||||
}
|
||||
Buffer = destinationArray;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
internal void Write(int b)
|
||||
{
|
||||
lock (_thisLock)
|
||||
{
|
||||
Allocate(1);
|
||||
Buffer[_end] = (byte)b;
|
||||
_end = (_end + 1) % Buffer.Length;
|
||||
_dataEvent.Set();
|
||||
}
|
||||
}
|
||||
|
||||
internal void Write(byte[] b, int offset, int len)
|
||||
{
|
||||
do
|
||||
{
|
||||
lock (_thisLock)
|
||||
{
|
||||
int alen = Allocate(len);
|
||||
int length = Math.Min(Buffer.Length - _end, alen);
|
||||
Array.Copy(b, offset, Buffer, _end, length);
|
||||
_end = (_end + length) % Buffer.Length;
|
||||
if (length < alen)
|
||||
{
|
||||
Array.Copy(b, offset + length, Buffer, 0, alen - length);
|
||||
_end += alen - length;
|
||||
}
|
||||
_dataEvent.Set();
|
||||
len -= alen;
|
||||
offset += alen;
|
||||
}
|
||||
} while (len > 0);
|
||||
}
|
||||
}
|
||||
public override int Read (byte[] b, int offset, int len)
|
||||
{
|
||||
int length = 0;
|
||||
do {
|
||||
_dataEvent.WaitOne ();
|
||||
lock (_thisLock) {
|
||||
if (_closed && Available () == 0) {
|
||||
return -1;
|
||||
}
|
||||
if (_start < _end) {
|
||||
length = Math.Min (len, _end - _start);
|
||||
Array.Copy (Buffer, _start, b, offset, length);
|
||||
_start += length;
|
||||
} else if (_start > _end) {
|
||||
length = Math.Min (len, Buffer.Length - _start);
|
||||
Array.Copy (Buffer, _start, b, offset, length);
|
||||
len -= length;
|
||||
_start = (_start + length) % Buffer.Length;
|
||||
if (len > 0) {
|
||||
int i = Math.Min (len, _end);
|
||||
Array.Copy (Buffer, 0, b, offset + length, i);
|
||||
_start += i;
|
||||
length += i;
|
||||
}
|
||||
}
|
||||
if (_start == _end && !_closed) {
|
||||
_dataEvent.Reset ();
|
||||
}
|
||||
Monitor.PulseAll (_thisLock);
|
||||
}
|
||||
} while (length == 0);
|
||||
return length;
|
||||
}
|
||||
|
||||
private int Allocate (int len)
|
||||
{
|
||||
int alen;
|
||||
while ((alen = TryAllocate (len)) == 0) {
|
||||
// Wait until somebody reads data
|
||||
try {
|
||||
Monitor.Wait (_thisLock);
|
||||
} catch {
|
||||
_closed = true;
|
||||
_dataEvent.Set ();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return alen;
|
||||
}
|
||||
|
||||
int TryAllocate (int len)
|
||||
{
|
||||
int free;
|
||||
if (_start <= _end) {
|
||||
free = (Buffer.Length - _end) + _start;
|
||||
} else {
|
||||
free = _start - _end;
|
||||
}
|
||||
if (free <= len) {
|
||||
if (!_allowGrow)
|
||||
return free > 0 ? free - 1 : 0;
|
||||
int sizeInc = (len - free) + 1;
|
||||
byte[] destinationArray = new byte[Buffer.Length + sizeInc];
|
||||
if (_start <= _end) {
|
||||
Array.Copy (Buffer, _start, destinationArray, _start, _end - _start);
|
||||
} else {
|
||||
Array.Copy (Buffer, 0, destinationArray, 0, _end);
|
||||
Array.Copy (Buffer, _start, destinationArray, _start + sizeInc, Buffer.Length - _start);
|
||||
_start += sizeInc;
|
||||
}
|
||||
Buffer = destinationArray;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
internal void Write (int b)
|
||||
{
|
||||
lock (_thisLock) {
|
||||
Allocate (1);
|
||||
Buffer[_end] = (byte)b;
|
||||
_end = (_end + 1) % Buffer.Length;
|
||||
_dataEvent.Set ();
|
||||
}
|
||||
}
|
||||
|
||||
internal void Write (byte[] b, int offset, int len)
|
||||
{
|
||||
do {
|
||||
lock (_thisLock) {
|
||||
int alen = Allocate (len);
|
||||
int length = Math.Min (Buffer.Length - _end, alen);
|
||||
Array.Copy (b, offset, Buffer, _end, length);
|
||||
_end = (_end + length) % Buffer.Length;
|
||||
if (length < alen) {
|
||||
Array.Copy (b, offset + length, Buffer, 0, alen - length);
|
||||
_end += alen - length;
|
||||
}
|
||||
_dataEvent.Set ();
|
||||
len -= alen;
|
||||
offset += alen;
|
||||
}
|
||||
} while (len > 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal class PipedOutputStream : OutputStream
|
||||
{
|
||||
PipedInputStream _ips;
|
||||
{
|
||||
PipedInputStream _ips;
|
||||
|
||||
public PipedOutputStream()
|
||||
{
|
||||
}
|
||||
public PipedOutputStream ()
|
||||
{
|
||||
}
|
||||
|
||||
public PipedOutputStream(PipedInputStream iss) : this()
|
||||
{
|
||||
Attach(iss);
|
||||
}
|
||||
public PipedOutputStream (PipedInputStream iss) : this()
|
||||
{
|
||||
Attach (iss);
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
_ips.Close();
|
||||
base.Close();
|
||||
}
|
||||
public override void Close ()
|
||||
{
|
||||
_ips.Close ();
|
||||
base.Close ();
|
||||
}
|
||||
|
||||
internal void Attach(PipedInputStream iss)
|
||||
{
|
||||
_ips = iss;
|
||||
}
|
||||
internal void Attach (PipedInputStream iss)
|
||||
{
|
||||
_ips = iss;
|
||||
}
|
||||
|
||||
public override void Write(int b)
|
||||
{
|
||||
_ips.Write(b);
|
||||
}
|
||||
public override void Write (int b)
|
||||
{
|
||||
_ips.Write (b);
|
||||
}
|
||||
|
||||
public override void Write(byte[] b, int offset, int len)
|
||||
{
|
||||
_ips.Write(b, offset, len);
|
||||
}
|
||||
}
|
||||
public override void Write (byte[] b, int offset, int len)
|
||||
{
|
||||
_ips.Write (b, offset, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,233 +5,227 @@ using System.Text;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public class PrintWriter : TextWriter
|
||||
{
|
||||
TextWriter _writer;
|
||||
private FileStream _stream;
|
||||
|
||||
public PrintWriter(FilePath path)
|
||||
{
|
||||
{
|
||||
TextWriter _writer;
|
||||
private FileStream _stream;
|
||||
|
||||
public PrintWriter (FilePath path)
|
||||
{
|
||||
//Stream(string path) constructor deleted
|
||||
_stream = new FileStream(path, FileMode.Create, FileAccess.ReadWrite);
|
||||
_writer = new StreamWriter(_stream);
|
||||
}
|
||||
_writer = new StreamWriter (_stream);
|
||||
}
|
||||
|
||||
public PrintWriter(TextWriter other)
|
||||
{
|
||||
_writer = other;
|
||||
}
|
||||
public PrintWriter (TextWriter other)
|
||||
{
|
||||
_writer = other;
|
||||
}
|
||||
|
||||
public override Encoding Encoding
|
||||
{
|
||||
get { return _writer.Encoding; }
|
||||
}
|
||||
public override Encoding Encoding {
|
||||
get { return _writer.Encoding; }
|
||||
}
|
||||
|
||||
public void Close() // remove `override`
|
||||
{
|
||||
//Stream.`Close` method deleted
|
||||
//Stream.`Close` method deleted
|
||||
//_writer.Close ();
|
||||
_writer.Dispose();
|
||||
_stream.Dispose();
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
_writer.Flush();
|
||||
}
|
||||
|
||||
public override IFormatProvider FormatProvider
|
||||
{
|
||||
get
|
||||
{
|
||||
return _writer.FormatProvider;
|
||||
}
|
||||
}
|
||||
|
||||
public override string NewLine
|
||||
{
|
||||
get
|
||||
{
|
||||
return _writer.NewLine;
|
||||
}
|
||||
set
|
||||
{
|
||||
_writer.NewLine = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write(char[] buffer, int index, int count)
|
||||
{
|
||||
_writer.Write(buffer, index, count);
|
||||
}
|
||||
|
||||
public override void Write(char[] buffer)
|
||||
{
|
||||
_writer.Write(buffer);
|
||||
}
|
||||
|
||||
public void Write(string format, object arg0, object arg1, object arg2)
|
||||
{
|
||||
_writer.Write(format, arg0, arg1, arg2);
|
||||
}
|
||||
|
||||
public override void Write(string format, object arg0, object arg1)
|
||||
{
|
||||
_writer.Write(format, arg0, arg1);
|
||||
}
|
||||
|
||||
public override void Write(string format, object arg0)
|
||||
{
|
||||
_writer.Write(format, arg0);
|
||||
}
|
||||
|
||||
public override void Write(string format, params object[] arg)
|
||||
{
|
||||
_writer.Write(format, arg);
|
||||
}
|
||||
|
||||
public override void WriteLine(char[] buffer, int index, int count)
|
||||
{
|
||||
_writer.WriteLine(buffer, index, count);
|
||||
}
|
||||
|
||||
public override void WriteLine(char[] buffer)
|
||||
{
|
||||
_writer.WriteLine(buffer);
|
||||
}
|
||||
|
||||
public void WriteLine(string format, object arg0, object arg1, object arg2)
|
||||
{
|
||||
_writer.WriteLine(format, arg0, arg1, arg2);
|
||||
}
|
||||
|
||||
public override void WriteLine(string format, object arg0, object arg1)
|
||||
{
|
||||
_writer.WriteLine(format, arg0, arg1);
|
||||
}
|
||||
|
||||
public override void WriteLine(string format, object arg0)
|
||||
{
|
||||
_writer.WriteLine(format, arg0);
|
||||
}
|
||||
|
||||
public override void WriteLine(string format, params object[] arg)
|
||||
{
|
||||
_writer.WriteLine(format, arg);
|
||||
}
|
||||
|
||||
public override void WriteLine(ulong value)
|
||||
{
|
||||
_writer.WriteLine(value);
|
||||
}
|
||||
|
||||
public override void WriteLine(uint value)
|
||||
{
|
||||
_writer.WriteLine(value);
|
||||
}
|
||||
|
||||
public override void WriteLine(string value)
|
||||
{
|
||||
_writer.WriteLine(value);
|
||||
}
|
||||
|
||||
public override void WriteLine(float value)
|
||||
{
|
||||
_writer.WriteLine(value);
|
||||
}
|
||||
|
||||
public override void WriteLine(object value)
|
||||
{
|
||||
_writer.WriteLine(value);
|
||||
}
|
||||
|
||||
public override void WriteLine(long value)
|
||||
{
|
||||
_writer.WriteLine(value);
|
||||
}
|
||||
|
||||
public override void WriteLine(int value)
|
||||
{
|
||||
_writer.WriteLine(value);
|
||||
}
|
||||
|
||||
public override void WriteLine(double value)
|
||||
{
|
||||
_writer.WriteLine(value);
|
||||
}
|
||||
|
||||
public override void WriteLine(decimal value)
|
||||
{
|
||||
_writer.WriteLine(value);
|
||||
}
|
||||
|
||||
public override void WriteLine(char value)
|
||||
{
|
||||
_writer.WriteLine(value);
|
||||
}
|
||||
|
||||
public override void WriteLine(bool value)
|
||||
{
|
||||
_writer.WriteLine(value);
|
||||
}
|
||||
|
||||
public override void WriteLine()
|
||||
{
|
||||
_writer.WriteLine();
|
||||
}
|
||||
|
||||
public override void Write(bool value)
|
||||
{
|
||||
_writer.Write(value);
|
||||
}
|
||||
|
||||
public override void Write(char value)
|
||||
{
|
||||
_writer.Write(value);
|
||||
}
|
||||
|
||||
public override void Write(decimal value)
|
||||
{
|
||||
_writer.Write(value);
|
||||
}
|
||||
|
||||
public override void Write(double value)
|
||||
{
|
||||
_writer.Write(value);
|
||||
}
|
||||
|
||||
public override void Write(int value)
|
||||
{
|
||||
_writer.Write(value);
|
||||
}
|
||||
|
||||
public override void Write(long value)
|
||||
{
|
||||
_writer.Write(value);
|
||||
}
|
||||
|
||||
public override void Write(object value)
|
||||
{
|
||||
_writer.Write(value);
|
||||
}
|
||||
|
||||
public override void Write(float value)
|
||||
{
|
||||
_writer.Write(value);
|
||||
}
|
||||
|
||||
public override void Write(string value)
|
||||
{
|
||||
_writer.Write(value);
|
||||
}
|
||||
|
||||
public override void Write(uint value)
|
||||
{
|
||||
_writer.Write(value);
|
||||
}
|
||||
|
||||
public override void Write(ulong value)
|
||||
{
|
||||
_writer.Write(value);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Flush ()
|
||||
{
|
||||
_writer.Flush ();
|
||||
}
|
||||
|
||||
public override IFormatProvider FormatProvider {
|
||||
get {
|
||||
return _writer.FormatProvider;
|
||||
}
|
||||
}
|
||||
|
||||
public override string NewLine {
|
||||
get {
|
||||
return _writer.NewLine;
|
||||
}
|
||||
set {
|
||||
_writer.NewLine = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write (char[] buffer, int index, int count)
|
||||
{
|
||||
_writer.Write (buffer, index, count);
|
||||
}
|
||||
|
||||
public override void Write (char[] buffer)
|
||||
{
|
||||
_writer.Write (buffer);
|
||||
}
|
||||
|
||||
public void Write (string format, object arg0, object arg1, object arg2)
|
||||
{
|
||||
_writer.Write (format, arg0, arg1, arg2);
|
||||
}
|
||||
|
||||
public override void Write (string format, object arg0, object arg1)
|
||||
{
|
||||
_writer.Write (format, arg0, arg1);
|
||||
}
|
||||
|
||||
public override void Write (string format, object arg0)
|
||||
{
|
||||
_writer.Write (format, arg0);
|
||||
}
|
||||
|
||||
public override void Write (string format, params object[] arg)
|
||||
{
|
||||
_writer.Write (format, arg);
|
||||
}
|
||||
|
||||
public override void WriteLine (char[] buffer, int index, int count)
|
||||
{
|
||||
_writer.WriteLine (buffer, index, count);
|
||||
}
|
||||
|
||||
public override void WriteLine (char[] buffer)
|
||||
{
|
||||
_writer.WriteLine (buffer);
|
||||
}
|
||||
|
||||
public void WriteLine (string format, object arg0, object arg1, object arg2)
|
||||
{
|
||||
_writer.WriteLine (format, arg0, arg1, arg2);
|
||||
}
|
||||
|
||||
public override void WriteLine (string format, object arg0, object arg1)
|
||||
{
|
||||
_writer.WriteLine (format, arg0, arg1);
|
||||
}
|
||||
|
||||
public override void WriteLine (string format, object arg0)
|
||||
{
|
||||
_writer.WriteLine (format, arg0);
|
||||
}
|
||||
|
||||
public override void WriteLine (string format, params object[] arg)
|
||||
{
|
||||
_writer.WriteLine (format, arg);
|
||||
}
|
||||
|
||||
public override void WriteLine (ulong value)
|
||||
{
|
||||
_writer.WriteLine (value);
|
||||
}
|
||||
|
||||
public override void WriteLine (uint value)
|
||||
{
|
||||
_writer.WriteLine (value);
|
||||
}
|
||||
|
||||
public override void WriteLine (string value)
|
||||
{
|
||||
_writer.WriteLine (value);
|
||||
}
|
||||
|
||||
public override void WriteLine (float value)
|
||||
{
|
||||
_writer.WriteLine (value);
|
||||
}
|
||||
|
||||
public override void WriteLine (object value)
|
||||
{
|
||||
_writer.WriteLine (value);
|
||||
}
|
||||
|
||||
public override void WriteLine (long value)
|
||||
{
|
||||
_writer.WriteLine (value);
|
||||
}
|
||||
|
||||
public override void WriteLine (int value)
|
||||
{
|
||||
_writer.WriteLine (value);
|
||||
}
|
||||
|
||||
public override void WriteLine (double value)
|
||||
{
|
||||
_writer.WriteLine (value);
|
||||
}
|
||||
|
||||
public override void WriteLine (decimal value)
|
||||
{
|
||||
_writer.WriteLine (value);
|
||||
}
|
||||
|
||||
public override void WriteLine (char value)
|
||||
{
|
||||
_writer.WriteLine (value);
|
||||
}
|
||||
|
||||
public override void WriteLine (bool value)
|
||||
{
|
||||
_writer.WriteLine (value);
|
||||
}
|
||||
|
||||
public override void WriteLine ()
|
||||
{
|
||||
_writer.WriteLine ();
|
||||
}
|
||||
|
||||
public override void Write (bool value)
|
||||
{
|
||||
_writer.Write (value);
|
||||
}
|
||||
|
||||
public override void Write (char value)
|
||||
{
|
||||
_writer.Write (value);
|
||||
}
|
||||
|
||||
public override void Write (decimal value)
|
||||
{
|
||||
_writer.Write (value);
|
||||
}
|
||||
|
||||
public override void Write (double value)
|
||||
{
|
||||
_writer.Write (value);
|
||||
}
|
||||
|
||||
public override void Write (int value)
|
||||
{
|
||||
_writer.Write (value);
|
||||
}
|
||||
|
||||
public override void Write (long value)
|
||||
{
|
||||
_writer.Write (value);
|
||||
}
|
||||
|
||||
public override void Write (object value)
|
||||
{
|
||||
_writer.Write (value);
|
||||
}
|
||||
|
||||
public override void Write (float value)
|
||||
{
|
||||
_writer.Write (value);
|
||||
}
|
||||
|
||||
public override void Write (string value)
|
||||
{
|
||||
_writer.Write (value);
|
||||
}
|
||||
|
||||
public override void Write (uint value)
|
||||
{
|
||||
_writer.Write (value);
|
||||
}
|
||||
|
||||
public override void Write (ulong value)
|
||||
{
|
||||
_writer.Write (value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,76 +6,81 @@ namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
protected Hashtable _properties;
|
||||
|
||||
|
||||
public Properties()
|
||||
{
|
||||
this._properties = new Hashtable();
|
||||
_properties = new Hashtable();
|
||||
}
|
||||
|
||||
public Properties(Properties defaultProp) : this()
|
||||
public Properties(Properties defaultProp): this()
|
||||
{
|
||||
this.PutAll(defaultProp._properties);
|
||||
PutAll(defaultProp._properties);
|
||||
}
|
||||
|
||||
public void PutAll(Hashtable properties)
|
||||
{
|
||||
foreach (var key in properties.Keys)
|
||||
{
|
||||
this._properties.Put(key, properties[key]);
|
||||
//_properties.Add(key, properties[key]);
|
||||
_properties.Put(key, properties[key]);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetProperty(object key, object value)
|
||||
{
|
||||
this._properties.Put(key, value);
|
||||
//_properties.Add(key, value);
|
||||
_properties.Put(key, value);
|
||||
}
|
||||
|
||||
public object GetProperty(object key)
|
||||
{
|
||||
return this._properties.Keys.Contains(key)
|
||||
? this._properties[key]
|
||||
: null;
|
||||
return _properties.Keys.Contains(key) ? _properties[key] : null;
|
||||
}
|
||||
|
||||
public object GetProperty(object key, object def)
|
||||
{
|
||||
return this._properties.Get(key) ?? def;
|
||||
/*if (_properties.ContainsKey(key))
|
||||
{
|
||||
return _properties[key];
|
||||
}
|
||||
return def;*/
|
||||
object value = _properties.Get(key);
|
||||
|
||||
return value ?? def;
|
||||
}
|
||||
|
||||
public void Load(InputStream input)
|
||||
{
|
||||
using (var reader = new StreamReader(input))
|
||||
StreamReader sr = new StreamReader(input);
|
||||
while (!sr.EndOfStream)
|
||||
{
|
||||
while (!reader.EndOfStream)
|
||||
string line = sr.ReadLine();
|
||||
|
||||
if (!string.IsNullOrEmpty(line))
|
||||
{
|
||||
var line = reader.ReadLine();
|
||||
|
||||
if (string.IsNullOrEmpty(line))
|
||||
continue;
|
||||
|
||||
var tokens = line.Split('=');
|
||||
|
||||
if (tokens.Length < 2)
|
||||
continue;
|
||||
|
||||
this._properties.Put(tokens[0], tokens[1]);
|
||||
string[] tokens = line.Split('=');
|
||||
//_properties.Add(tokens[0], tokens[1]);
|
||||
_properties.Put(tokens[0], tokens[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Store(OutputStream output)
|
||||
{
|
||||
using (var writer = new StreamWriter(output))
|
||||
StreamWriter sw = new StreamWriter(output);
|
||||
foreach (var key in _properties.Keys)
|
||||
{
|
||||
foreach (var pair in this._properties)
|
||||
writer.WriteLine($"{pair.Key}={pair.Value}");
|
||||
string line = string.Format("{0}={1}", key, _properties[key]);
|
||||
sw.WriteLine(line);
|
||||
}
|
||||
}
|
||||
|
||||
public void Store(TextWriter output)
|
||||
{
|
||||
foreach (var pair in this._properties)
|
||||
output.WriteLine($"{pair.Key}={pair.Value}");
|
||||
{
|
||||
foreach (var key in _properties.Keys)
|
||||
{
|
||||
string line = string.Format("{0}={1}", key, _properties[key]);
|
||||
output.WriteLine(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,86 +4,84 @@ using System.IO;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public class RandomAccessFile
|
||||
{
|
||||
private FileStream _stream;
|
||||
{
|
||||
private FileStream _stream;
|
||||
|
||||
public RandomAccessFile(FilePath file, string mode) : this(file.GetPath(), mode)
|
||||
{
|
||||
}
|
||||
public RandomAccessFile (FilePath file, string mode) : this(file.GetPath (), mode)
|
||||
{
|
||||
}
|
||||
|
||||
public RandomAccessFile(string file, string mode)
|
||||
{
|
||||
if (mode.IndexOf('w') != -1)
|
||||
_stream = new FileStream(file, FileMode.OpenOrCreate, FileAccess.ReadWrite);
|
||||
else
|
||||
_stream = new FileStream(file, FileMode.Open, FileAccess.Read);
|
||||
}
|
||||
public RandomAccessFile (string file, string mode)
|
||||
{
|
||||
if (mode.IndexOf ('w') != -1)
|
||||
_stream = new FileStream (file, FileMode.OpenOrCreate, FileAccess.ReadWrite);
|
||||
else
|
||||
_stream = new FileStream (file, FileMode.Open, FileAccess.Read);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
public void Close ()
|
||||
{
|
||||
//Stream.`Close` method deleted
|
||||
//_stream.Close ();
|
||||
_stream.Dispose();
|
||||
}
|
||||
|
||||
public long GetFilePointer()
|
||||
{
|
||||
return _stream.Position;
|
||||
}
|
||||
public long GetFilePointer ()
|
||||
{
|
||||
return _stream.Position;
|
||||
}
|
||||
|
||||
public long Length()
|
||||
{
|
||||
return _stream.Length;
|
||||
}
|
||||
public long Length ()
|
||||
{
|
||||
return _stream.Length;
|
||||
}
|
||||
|
||||
public int Read(byte[] buffer)
|
||||
{
|
||||
int r = _stream.Read(buffer, 0, buffer.Length);
|
||||
return r > 0 ? r : -1;
|
||||
}
|
||||
public int Read (byte[] buffer)
|
||||
{
|
||||
int r = _stream.Read (buffer, 0, buffer.Length);
|
||||
return r > 0 ? r : -1;
|
||||
}
|
||||
|
||||
public int Read(byte[] buffer, int start, int size)
|
||||
{
|
||||
return _stream.Read(buffer, start, size);
|
||||
}
|
||||
public int Read (byte[] buffer, int start, int size)
|
||||
{
|
||||
return _stream.Read (buffer, start, size);
|
||||
}
|
||||
|
||||
public void ReadFully(byte[] buffer, int start, int size)
|
||||
{
|
||||
while (size > 0)
|
||||
{
|
||||
int num = _stream.Read(buffer, start, size);
|
||||
if (num == 0)
|
||||
{
|
||||
throw new EofException();
|
||||
}
|
||||
size -= num;
|
||||
start += num;
|
||||
}
|
||||
}
|
||||
public void ReadFully (byte[] buffer, int start, int size)
|
||||
{
|
||||
while (size > 0) {
|
||||
int num = _stream.Read (buffer, start, size);
|
||||
if (num == 0) {
|
||||
throw new EofException ();
|
||||
}
|
||||
size -= num;
|
||||
start += num;
|
||||
}
|
||||
}
|
||||
|
||||
public void Seek(long pos)
|
||||
{
|
||||
_stream.Position = pos;
|
||||
}
|
||||
public void Seek (long pos)
|
||||
{
|
||||
_stream.Position = pos;
|
||||
}
|
||||
|
||||
public void SetLength(long len)
|
||||
{
|
||||
_stream.SetLength(len);
|
||||
}
|
||||
public void SetLength (long len)
|
||||
{
|
||||
_stream.SetLength (len);
|
||||
}
|
||||
|
||||
public void Write(int value)
|
||||
{
|
||||
_stream.Write(BitConverter.GetBytes(value), 0, 4);
|
||||
}
|
||||
public void Write (int value)
|
||||
{
|
||||
_stream.Write (BitConverter.GetBytes (value), 0, 4);
|
||||
}
|
||||
|
||||
public void Write (byte[] buffer)
|
||||
{
|
||||
_stream.Write (buffer, 0, buffer.Length);
|
||||
}
|
||||
|
||||
public void Write(byte[] buffer)
|
||||
{
|
||||
_stream.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
|
||||
public void Write(byte[] buffer, int start, int size)
|
||||
{
|
||||
_stream.Write(buffer, start, size);
|
||||
}
|
||||
}
|
||||
public void Write (byte[] buffer, int start, int size)
|
||||
{
|
||||
_stream.Write (buffer, start, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,20 +3,20 @@ using System.Threading;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal class ReentrantLock
|
||||
{
|
||||
public void Lock()
|
||||
{
|
||||
Monitor.Enter(this);
|
||||
}
|
||||
{
|
||||
public void Lock ()
|
||||
{
|
||||
Monitor.Enter (this);
|
||||
}
|
||||
|
||||
public bool TryLock()
|
||||
{
|
||||
return Monitor.TryEnter(this);
|
||||
}
|
||||
public bool TryLock ()
|
||||
{
|
||||
return Monitor.TryEnter (this);
|
||||
}
|
||||
|
||||
public void Unlock()
|
||||
{
|
||||
Monitor.Exit(this);
|
||||
}
|
||||
}
|
||||
public void Unlock ()
|
||||
{
|
||||
Monitor.Exit (this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal abstract class Reference<T>
|
||||
{
|
||||
public abstract T Get();
|
||||
}
|
||||
{
|
||||
public abstract T Get ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,208 +8,205 @@ using System.Threading;
|
||||
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public class Runtime
|
||||
{
|
||||
private static Runtime _instance;
|
||||
private List<ShutdownHook> _shutdownHooks = new List<ShutdownHook>();
|
||||
public class Runtime
|
||||
{
|
||||
private static Runtime _instance;
|
||||
private List<ShutdownHook> _shutdownHooks = new List<ShutdownHook> ();
|
||||
|
||||
internal void AddShutdownHook(IRunnable r)
|
||||
{
|
||||
ShutdownHook item = new ShutdownHook();
|
||||
item.Runnable = r;
|
||||
_shutdownHooks.Add(item);
|
||||
}
|
||||
internal void AddShutdownHook (IRunnable r)
|
||||
{
|
||||
ShutdownHook item = new ShutdownHook ();
|
||||
item.Runnable = r;
|
||||
_shutdownHooks.Add (item);
|
||||
}
|
||||
|
||||
internal int AvailableProcessors()
|
||||
{
|
||||
return Environment.ProcessorCount;
|
||||
}
|
||||
internal int AvailableProcessors ()
|
||||
{
|
||||
return Environment.ProcessorCount;
|
||||
}
|
||||
|
||||
public static long CurrentTimeMillis()
|
||||
{
|
||||
return DateTime.UtcNow.ToMillisecondsSinceEpoch();
|
||||
}
|
||||
public static long CurrentTimeMillis ()
|
||||
{
|
||||
return DateTime.UtcNow.ToMillisecondsSinceEpoch ();
|
||||
}
|
||||
|
||||
static Hashtable _properties;
|
||||
|
||||
public static Hashtable GetProperties ()
|
||||
{
|
||||
if (_properties == null) {
|
||||
_properties = new Hashtable ();
|
||||
_properties ["jgit.fs.debug"] = "false";
|
||||
_properties["file.encoding"] = "UTF-8";
|
||||
if (Path.DirectorySeparatorChar != '\\')
|
||||
_properties ["os.name"] = "Unix";
|
||||
else
|
||||
_properties ["os.name"] = "Windows";
|
||||
}
|
||||
return _properties;
|
||||
}
|
||||
|
||||
static Hashtable _properties;
|
||||
|
||||
public static Hashtable GetProperties()
|
||||
{
|
||||
if (_properties == null)
|
||||
{
|
||||
_properties = new Hashtable();
|
||||
_properties["jgit.fs.debug"] = "false";
|
||||
_properties["file.encoding"] = "UTF-8";
|
||||
if (Path.DirectorySeparatorChar != '\\')
|
||||
_properties["os.name"] = "Unix";
|
||||
else
|
||||
_properties["os.name"] = "Windows";
|
||||
}
|
||||
return _properties;
|
||||
}
|
||||
|
||||
public static string GetProperty(string key)
|
||||
{
|
||||
if (GetProperties().Keys.Contains(key))
|
||||
public static string GetProperty (string key)
|
||||
{
|
||||
if (GetProperties().Keys.Contains(key))
|
||||
{
|
||||
return ((string)GetProperties()[key]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void SetProperty(string key, string value)
|
||||
{
|
||||
GetProperties()[key] = value;
|
||||
}
|
||||
public static void SetProperty (string key, string value)
|
||||
{
|
||||
GetProperties () [key] = value;
|
||||
}
|
||||
|
||||
public static Runtime GetRuntime()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new Runtime();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
public static Runtime GetRuntime ()
|
||||
{
|
||||
if (_instance == null) {
|
||||
_instance = new Runtime ();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
public static int IdentityHashCode(object ob)
|
||||
{
|
||||
return RuntimeHelpers.GetHashCode(ob);
|
||||
}
|
||||
public static int IdentityHashCode (object ob)
|
||||
{
|
||||
return RuntimeHelpers.GetHashCode (ob);
|
||||
}
|
||||
|
||||
internal long MaxMemory()
|
||||
{
|
||||
return int.MaxValue;
|
||||
}
|
||||
internal long MaxMemory ()
|
||||
{
|
||||
return int.MaxValue;
|
||||
}
|
||||
|
||||
private class ShutdownHook
|
||||
{
|
||||
public IRunnable Runnable;
|
||||
private class ShutdownHook
|
||||
{
|
||||
public IRunnable Runnable;
|
||||
|
||||
~ShutdownHook()
|
||||
{
|
||||
Runnable.Run();
|
||||
}
|
||||
}
|
||||
~ShutdownHook ()
|
||||
{
|
||||
Runnable.Run ();
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeleteCharAt (StringBuilder sb, int index)
|
||||
{
|
||||
sb.Remove (index, 1);
|
||||
}
|
||||
|
||||
public static byte[] GetBytesForString (string str)
|
||||
{
|
||||
return Encoding.UTF8.GetBytes (str);
|
||||
}
|
||||
|
||||
public static void DeleteCharAt(StringBuilder sb, int index)
|
||||
{
|
||||
sb.Remove(index, 1);
|
||||
}
|
||||
public static byte[] GetBytesForString (string str, string encoding)
|
||||
{
|
||||
return Encoding.GetEncoding (encoding).GetBytes (str);
|
||||
}
|
||||
|
||||
public static byte[] GetBytesForString(string str)
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(str);
|
||||
}
|
||||
|
||||
public static byte[] GetBytesForString(string str, string encoding)
|
||||
{
|
||||
return Encoding.GetEncoding(encoding).GetBytes(str);
|
||||
}
|
||||
|
||||
public static FieldInfo[] GetDeclaredFields(Type t)
|
||||
{
|
||||
public static FieldInfo[] GetDeclaredFields (Type t)
|
||||
{
|
||||
throw new NotImplementedException("Type.GetFields not found on .NetStandard");
|
||||
//return t.GetFields (BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
|
||||
}
|
||||
//return t.GetFields (BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
|
||||
}
|
||||
|
||||
public static void NotifyAll(object ob)
|
||||
{
|
||||
Monitor.PulseAll(ob);
|
||||
}
|
||||
public static void NotifyAll (object ob)
|
||||
{
|
||||
Monitor.PulseAll (ob);
|
||||
}
|
||||
|
||||
public static void Notify(object obj)
|
||||
{
|
||||
Monitor.Pulse(obj);
|
||||
}
|
||||
public static void Notify(object obj)
|
||||
{
|
||||
Monitor.Pulse(obj);
|
||||
}
|
||||
|
||||
public static void PrintStackTrace(Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
public static void PrintStackTrace (Exception ex)
|
||||
{
|
||||
Console.WriteLine (ex);
|
||||
}
|
||||
|
||||
public static void PrintStackTrace(Exception ex, TextWriter tw)
|
||||
{
|
||||
tw.WriteLine(ex);
|
||||
}
|
||||
public static void PrintStackTrace (Exception ex, TextWriter tw)
|
||||
{
|
||||
tw.WriteLine (ex);
|
||||
}
|
||||
|
||||
public static string Substring(string str, int index)
|
||||
{
|
||||
return str.Substring(index);
|
||||
}
|
||||
public static string Substring (string str, int index)
|
||||
{
|
||||
return str.Substring (index);
|
||||
}
|
||||
|
||||
public static string Substring(string str, int index, int endIndex)
|
||||
{
|
||||
return str.Substring(index, endIndex - index);
|
||||
}
|
||||
public static string Substring (string str, int index, int endIndex)
|
||||
{
|
||||
return str.Substring (index, endIndex - index);
|
||||
}
|
||||
|
||||
public static void Wait(object ob)
|
||||
{
|
||||
Monitor.Wait(ob);
|
||||
}
|
||||
public static void Wait (object ob)
|
||||
{
|
||||
Monitor.Wait (ob);
|
||||
}
|
||||
|
||||
public static bool Wait(object ob, long milis)
|
||||
{
|
||||
return Monitor.Wait(ob, (int)milis);
|
||||
}
|
||||
|
||||
public static Type GetType(string name)
|
||||
{
|
||||
throw new NotImplementedException(
|
||||
"AppDomain.CurrentDomain.GetAssemblies not found on .NetStandard");
|
||||
//foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies ()) {
|
||||
// Type t = a.GetType (name);
|
||||
// if (t != null)
|
||||
// return t;
|
||||
//}
|
||||
public static bool Wait (object ob, long milis)
|
||||
{
|
||||
return Monitor.Wait (ob, (int)milis);
|
||||
}
|
||||
|
||||
public static Type GetType (string name)
|
||||
{
|
||||
throw new NotImplementedException("AppDomain.CurrentDomain.GetAssemblies not found on .NetStandard");
|
||||
//foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies ()) {
|
||||
// Type t = a.GetType (name);
|
||||
// if (t != null)
|
||||
// return t;
|
||||
//}
|
||||
//never used
|
||||
//throw new InvalidOperationException ("Type not found: " + name);
|
||||
}
|
||||
//throw new InvalidOperationException ("Type not found: " + name);
|
||||
}
|
||||
|
||||
public static void SetCharAt (StringBuilder sb, int index, char c)
|
||||
{
|
||||
sb [index] = c;
|
||||
}
|
||||
|
||||
public static bool EqualsIgnoreCase (string s1, string s2)
|
||||
{
|
||||
return s1.Equals (s2, StringComparison.CurrentCultureIgnoreCase);
|
||||
}
|
||||
|
||||
internal static long NanoTime ()
|
||||
{
|
||||
return Environment.TickCount * 1000 * 1000;
|
||||
}
|
||||
|
||||
internal static int CompareOrdinal (string s1, string s2)
|
||||
{
|
||||
return string.CompareOrdinal (s1, s2);
|
||||
}
|
||||
|
||||
public static void SetCharAt(StringBuilder sb, int index, char c)
|
||||
{
|
||||
sb[index] = c;
|
||||
}
|
||||
public static string GetStringForBytes (byte[] chars)
|
||||
{
|
||||
return Encoding.UTF8.GetString (chars, 0, chars.Length);
|
||||
}
|
||||
|
||||
public static bool EqualsIgnoreCase(string s1, string s2)
|
||||
{
|
||||
return s1.Equals(s2, StringComparison.CurrentCultureIgnoreCase);
|
||||
}
|
||||
public static string GetStringForBytes (byte[] chars, string encoding)
|
||||
{
|
||||
return GetEncoding (encoding).GetString (chars, 0, chars.Length);
|
||||
}
|
||||
|
||||
internal static long NanoTime()
|
||||
{
|
||||
return Environment.TickCount * 1000 * 1000;
|
||||
}
|
||||
public static string GetStringForBytes (byte[] chars, int start, int len)
|
||||
{
|
||||
return Encoding.UTF8.GetString (chars, start, len);
|
||||
}
|
||||
|
||||
internal static int CompareOrdinal(string s1, string s2)
|
||||
{
|
||||
return string.CompareOrdinal(s1, s2);
|
||||
}
|
||||
|
||||
public static string GetStringForBytes(byte[] chars)
|
||||
{
|
||||
return Encoding.UTF8.GetString(chars, 0, chars.Length);
|
||||
}
|
||||
|
||||
public static string GetStringForBytes(byte[] chars, string encoding)
|
||||
{
|
||||
return GetEncoding(encoding).GetString(chars, 0, chars.Length);
|
||||
}
|
||||
|
||||
public static string GetStringForBytes(byte[] chars, int start, int len)
|
||||
{
|
||||
return Encoding.UTF8.GetString(chars, start, len);
|
||||
}
|
||||
|
||||
public static string GetStringForBytes(byte[] chars, int start, int len, string encoding)
|
||||
{
|
||||
return GetEncoding(encoding).Decode(chars, start, len);
|
||||
}
|
||||
|
||||
public static Encoding GetEncoding(string name)
|
||||
{
|
||||
Encoding e = Encoding.GetEncoding(name.Replace('_', '-'));
|
||||
if (e is UTF8Encoding)
|
||||
return new UTF8Encoding(false, true);
|
||||
return e;
|
||||
}
|
||||
}
|
||||
public static string GetStringForBytes (byte[] chars, int start, int len, string encoding)
|
||||
{
|
||||
return GetEncoding (encoding).Decode (chars, start, len);
|
||||
}
|
||||
|
||||
public static Encoding GetEncoding (string name)
|
||||
{
|
||||
Encoding e = Encoding.GetEncoding (name.Replace ('_','-'));
|
||||
if (e is UTF8Encoding)
|
||||
return new UTF8Encoding (false, true);
|
||||
return e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,63 +4,59 @@ using System.Globalization;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public class SimpleDateFormat : DateFormat
|
||||
{
|
||||
string _format;
|
||||
{
|
||||
string _format;
|
||||
|
||||
CultureInfo Culture
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
CultureInfo Culture {
|
||||
get; set;
|
||||
}
|
||||
|
||||
bool Lenient
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
bool Lenient {
|
||||
get; set;
|
||||
}
|
||||
|
||||
public SimpleDateFormat (): this ("g")
|
||||
{
|
||||
}
|
||||
|
||||
public SimpleDateFormat() : this("g")
|
||||
{
|
||||
}
|
||||
public SimpleDateFormat (string format): this (format, CultureInfo.CurrentCulture)
|
||||
{
|
||||
}
|
||||
|
||||
public SimpleDateFormat(string format) : this(format, CultureInfo.CurrentCulture)
|
||||
{
|
||||
}
|
||||
public SimpleDateFormat (string format, CultureInfo c)
|
||||
{
|
||||
Culture = c;
|
||||
this._format = format.Replace ("EEE", "ddd");
|
||||
this._format = this._format.Replace ("Z", "zzz");
|
||||
SetTimeZone (TimeZoneInfo.Local);
|
||||
}
|
||||
|
||||
public SimpleDateFormat(string format, CultureInfo c)
|
||||
{
|
||||
Culture = c;
|
||||
this._format = format.Replace("EEE", "ddd");
|
||||
this._format = this._format.Replace("Z", "zzz");
|
||||
SetTimeZone(TimeZoneInfo.Local);
|
||||
}
|
||||
public bool IsLenient ()
|
||||
{
|
||||
return Lenient;
|
||||
}
|
||||
|
||||
public bool IsLenient()
|
||||
{
|
||||
return Lenient;
|
||||
}
|
||||
public void SetLenient (bool lenient)
|
||||
{
|
||||
Lenient = lenient;
|
||||
}
|
||||
|
||||
public void SetLenient(bool lenient)
|
||||
{
|
||||
Lenient = lenient;
|
||||
}
|
||||
public override DateTime Parse (string value)
|
||||
{
|
||||
if (IsLenient ())
|
||||
return DateTime.Parse (value);
|
||||
return DateTime.ParseExact (value, _format, Culture);
|
||||
}
|
||||
|
||||
public override DateTime Parse(string value)
|
||||
{
|
||||
if (IsLenient())
|
||||
return DateTime.Parse(value);
|
||||
return DateTime.ParseExact(value, _format, Culture);
|
||||
}
|
||||
|
||||
public override string Format(DateTime date)
|
||||
{
|
||||
date += GetTimeZone().BaseUtcOffset;
|
||||
return date.ToString(_format);
|
||||
}
|
||||
|
||||
public string Format(long date)
|
||||
{
|
||||
return Extensions.MillisToDateTimeOffset(date, (int)GetTimeZone().BaseUtcOffset
|
||||
.TotalMinutes)
|
||||
.DateTime.ToString(_format);
|
||||
}
|
||||
}
|
||||
public override string Format (DateTime date)
|
||||
{
|
||||
date += GetTimeZone().BaseUtcOffset;
|
||||
return date.ToString (_format);
|
||||
}
|
||||
|
||||
public string Format (long date)
|
||||
{
|
||||
return Extensions.MillisToDateTimeOffset (date, (int)GetTimeZone ().BaseUtcOffset.TotalMinutes).DateTime.ToString (_format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public class SocketEx : Socket
|
||||
{
|
||||
private int _soTimeOut = -1;
|
||||
private int _soTimeOut = -1;
|
||||
|
||||
public int SoTimeOut
|
||||
{
|
||||
@@ -46,9 +46,7 @@ namespace SharpCifs.Util.Sharpen
|
||||
}
|
||||
}
|
||||
|
||||
public SocketEx(AddressFamily addressFamily,
|
||||
SocketType socketType,
|
||||
ProtocolType protocolType)
|
||||
public SocketEx(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
|
||||
: base(addressFamily, socketType, protocolType)
|
||||
{
|
||||
|
||||
|
||||
@@ -4,120 +4,103 @@ using System.Collections.Generic;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal class SynchronizedList<T> : IList<T>
|
||||
{
|
||||
private IList<T> _list;
|
||||
{
|
||||
private IList<T> _list;
|
||||
|
||||
public SynchronizedList(IList<T> list)
|
||||
{
|
||||
this._list = list;
|
||||
}
|
||||
public SynchronizedList (IList<T> list)
|
||||
{
|
||||
this._list = list;
|
||||
}
|
||||
|
||||
public int IndexOf(T item)
|
||||
{
|
||||
lock (_list)
|
||||
{
|
||||
return _list.IndexOf(item);
|
||||
}
|
||||
}
|
||||
public int IndexOf (T item)
|
||||
{
|
||||
lock (_list) {
|
||||
return _list.IndexOf (item);
|
||||
}
|
||||
}
|
||||
|
||||
public void Insert(int index, T item)
|
||||
{
|
||||
lock (_list)
|
||||
{
|
||||
_list.Insert(index, item);
|
||||
}
|
||||
}
|
||||
public void Insert (int index, T item)
|
||||
{
|
||||
lock (_list) {
|
||||
_list.Insert (index, item);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
lock (_list)
|
||||
{
|
||||
_list.RemoveAt(index);
|
||||
}
|
||||
}
|
||||
public void RemoveAt (int index)
|
||||
{
|
||||
lock (_list) {
|
||||
_list.RemoveAt (index);
|
||||
}
|
||||
}
|
||||
|
||||
void ICollection<T>.Add(T item)
|
||||
{
|
||||
lock (_list)
|
||||
{
|
||||
_list.Add(item);
|
||||
}
|
||||
}
|
||||
void ICollection<T>.Add (T item)
|
||||
{
|
||||
lock (_list) {
|
||||
_list.Add (item);
|
||||
}
|
||||
}
|
||||
|
||||
void ICollection<T>.Clear()
|
||||
{
|
||||
lock (_list)
|
||||
{
|
||||
_list.Clear();
|
||||
}
|
||||
}
|
||||
void ICollection<T>.Clear ()
|
||||
{
|
||||
lock (_list) {
|
||||
_list.Clear ();
|
||||
}
|
||||
}
|
||||
|
||||
bool ICollection<T>.Contains(T item)
|
||||
{
|
||||
lock (_list)
|
||||
{
|
||||
return _list.Contains(item);
|
||||
}
|
||||
}
|
||||
bool ICollection<T>.Contains (T item)
|
||||
{
|
||||
lock (_list) {
|
||||
return _list.Contains (item);
|
||||
}
|
||||
}
|
||||
|
||||
void ICollection<T>.CopyTo(T[] array, int arrayIndex)
|
||||
{
|
||||
lock (_list)
|
||||
{
|
||||
_list.CopyTo(array, arrayIndex);
|
||||
}
|
||||
}
|
||||
void ICollection<T>.CopyTo (T[] array, int arrayIndex)
|
||||
{
|
||||
lock (_list) {
|
||||
_list.CopyTo (array, arrayIndex);
|
||||
}
|
||||
}
|
||||
|
||||
bool ICollection<T>.Remove(T item)
|
||||
{
|
||||
lock (_list)
|
||||
{
|
||||
return _list.Remove(item);
|
||||
}
|
||||
}
|
||||
bool ICollection<T>.Remove (T item)
|
||||
{
|
||||
lock (_list) {
|
||||
return _list.Remove (item);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator<T> IEnumerable<T>.GetEnumerator()
|
||||
{
|
||||
return _list.GetEnumerator();
|
||||
}
|
||||
IEnumerator<T> IEnumerable<T>.GetEnumerator ()
|
||||
{
|
||||
return _list.GetEnumerator ();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return _list.GetEnumerator();
|
||||
}
|
||||
IEnumerator IEnumerable.GetEnumerator ()
|
||||
{
|
||||
return _list.GetEnumerator ();
|
||||
}
|
||||
|
||||
public T this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_list)
|
||||
{
|
||||
return _list[index];
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
lock (_list)
|
||||
{
|
||||
_list[index] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
public T this[int index] {
|
||||
get {
|
||||
lock (_list) {
|
||||
return _list[index];
|
||||
}
|
||||
}
|
||||
set {
|
||||
lock (_list) {
|
||||
_list[index] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ICollection<T>.Count
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_list)
|
||||
{
|
||||
return _list.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
int ICollection<T>.Count {
|
||||
get {
|
||||
lock (_list) {
|
||||
return _list.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ICollection<T>.IsReadOnly
|
||||
{
|
||||
get { return _list.IsReadOnly; }
|
||||
}
|
||||
}
|
||||
bool ICollection<T>.IsReadOnly {
|
||||
get { return _list.IsReadOnly; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,314 +1,193 @@
|
||||
using SharpCifs.Util.DbsHelper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
public class Thread : IRunnable
|
||||
{
|
||||
private static ThreadGroup DefaultGroup = new ThreadGroup();
|
||||
{
|
||||
private static ThreadGroup _defaultGroup = new ThreadGroup ();
|
||||
private bool _interrupted;
|
||||
private IRunnable _runnable;
|
||||
private ThreadGroup _tgroup;
|
||||
private System.Threading.Thread _thread;
|
||||
|
||||
[ThreadStatic]
|
||||
private static Thread _wrapperThread;
|
||||
|
||||
[ThreadStatic]
|
||||
private static Thread WrapperThread;
|
||||
public Thread () : this(null, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
public static Thread CurrentThread()
|
||||
{
|
||||
if (Thread.WrapperThread == null)
|
||||
{
|
||||
Thread.WrapperThread = new Thread(System.Environment.CurrentManagedThreadId);
|
||||
}
|
||||
public Thread (string name) : this (null, null, name)
|
||||
{
|
||||
}
|
||||
|
||||
return Thread.WrapperThread;
|
||||
}
|
||||
public Thread (ThreadGroup grp, string name) : this (null, grp, name)
|
||||
{
|
||||
}
|
||||
|
||||
public Thread (IRunnable runnable): this (runnable, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
Thread (IRunnable runnable, ThreadGroup grp, string name)
|
||||
{
|
||||
_thread = new System.Threading.Thread (InternalRun);
|
||||
|
||||
this._runnable = runnable ?? this;
|
||||
_tgroup = grp ?? _defaultGroup;
|
||||
_tgroup.Add (this);
|
||||
if (name != null)
|
||||
_thread.Name = name;
|
||||
}
|
||||
|
||||
public CancellationTokenSource Canceller => this._canceller;
|
||||
private Thread (System.Threading.Thread t)
|
||||
{
|
||||
_thread = t;
|
||||
_tgroup = _defaultGroup;
|
||||
_tgroup.Add (this);
|
||||
}
|
||||
|
||||
public bool IsCanceled
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._canceller?.IsCancellationRequested == true
|
||||
&& !this._isCanceled)
|
||||
{
|
||||
this._isCanceled = true;
|
||||
}
|
||||
public static Thread CurrentThread ()
|
||||
{
|
||||
if (_wrapperThread == null) {
|
||||
_wrapperThread = new Thread (System.Threading.Thread.CurrentThread);
|
||||
}
|
||||
return _wrapperThread;
|
||||
}
|
||||
|
||||
return this._isCanceled;
|
||||
public string GetName ()
|
||||
{
|
||||
return _thread.Name;
|
||||
}
|
||||
|
||||
public ThreadGroup GetThreadGroup ()
|
||||
{
|
||||
return _tgroup;
|
||||
}
|
||||
|
||||
private void InternalRun ()
|
||||
{
|
||||
_wrapperThread = this;
|
||||
try {
|
||||
_runnable.Run ();
|
||||
} catch (Exception exception) {
|
||||
Console.WriteLine (exception);
|
||||
} finally {
|
||||
_tgroup.Remove (this);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Yield ()
|
||||
{
|
||||
}
|
||||
|
||||
public void Interrupt ()
|
||||
{
|
||||
lock (_thread) {
|
||||
_interrupted = true;
|
||||
//thread.Interrupt ();
|
||||
|
||||
//TODO: implement CancellationToken
|
||||
//_thread.Abort();
|
||||
throw new NotImplementedException("implement CancellationToken for thread");
|
||||
}
|
||||
}
|
||||
|
||||
private IRunnable _runnable;
|
||||
private ThreadGroup _tgroup;
|
||||
private System.Threading.Tasks.Task _task = null;
|
||||
private CancellationTokenSource _canceller = null;
|
||||
public static bool Interrupted ()
|
||||
{
|
||||
if (Thread._wrapperThread == null) {
|
||||
return false;
|
||||
}
|
||||
Thread wrapperThread = Thread._wrapperThread;
|
||||
lock (wrapperThread) {
|
||||
bool interrupted = Thread._wrapperThread._interrupted;
|
||||
Thread._wrapperThread._interrupted = false;
|
||||
return interrupted;
|
||||
}
|
||||
}
|
||||
|
||||
private string _name = string.Empty;
|
||||
private bool _isBackground = true;
|
||||
private bool _interrupted = false;
|
||||
private int? _id = null;
|
||||
private bool _isRunning = false;
|
||||
private bool _isCanceled = false;
|
||||
public bool IsAlive ()
|
||||
{
|
||||
return _thread.IsAlive;
|
||||
}
|
||||
|
||||
public void Join ()
|
||||
{
|
||||
_thread.Join ();
|
||||
}
|
||||
|
||||
public void Join (long timeout)
|
||||
{
|
||||
_thread.Join ((int)timeout);
|
||||
}
|
||||
|
||||
public Thread() : this(null, null, null)
|
||||
{
|
||||
public virtual void Run ()
|
||||
{
|
||||
}
|
||||
|
||||
public void SetDaemon (bool daemon)
|
||||
{
|
||||
_thread.IsBackground = daemon;
|
||||
}
|
||||
|
||||
public void SetName (string name)
|
||||
{
|
||||
_thread.Name = name;
|
||||
}
|
||||
|
||||
public static void Sleep (long milis)
|
||||
{
|
||||
System.Threading.Thread.Sleep ((int)milis);
|
||||
}
|
||||
|
||||
public void Start ()
|
||||
{
|
||||
_thread.Start ();
|
||||
}
|
||||
|
||||
public void Abort ()
|
||||
{
|
||||
//TODO: implement CancellationToken
|
||||
//_thread.Abort ();
|
||||
throw new NotImplementedException("implement CancellationToken for thread");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ThreadGroup
|
||||
{
|
||||
private List<Thread> _threads = new List<Thread> ();
|
||||
|
||||
public ThreadGroup()
|
||||
{
|
||||
}
|
||||
|
||||
public ThreadGroup (string name)
|
||||
{
|
||||
}
|
||||
|
||||
public Thread(string name) : this(null, null, name)
|
||||
{
|
||||
}
|
||||
internal void Add (Thread t)
|
||||
{
|
||||
lock (_threads) {
|
||||
_threads.Add (t);
|
||||
}
|
||||
}
|
||||
|
||||
internal void Remove (Thread t)
|
||||
{
|
||||
lock (_threads) {
|
||||
_threads.Remove (t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Thread(ThreadGroup grp, string name) : this(null, grp, name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public Thread(IRunnable runnable) : this(runnable, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
private Thread(IRunnable runnable, ThreadGroup grp, string name)
|
||||
{
|
||||
this._runnable = runnable ?? this;
|
||||
this._tgroup = grp ?? DefaultGroup;
|
||||
this._tgroup.Add(this);
|
||||
|
||||
if (name != null)
|
||||
{
|
||||
this._name = name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Thread(int threadId)
|
||||
{
|
||||
this._id = threadId;
|
||||
|
||||
this._tgroup = DefaultGroup;
|
||||
this._tgroup.Add(this);
|
||||
}
|
||||
|
||||
|
||||
public string GetName()
|
||||
{
|
||||
return this._name;
|
||||
}
|
||||
|
||||
|
||||
public ThreadGroup GetThreadGroup()
|
||||
{
|
||||
return this._tgroup;
|
||||
}
|
||||
|
||||
|
||||
public static void Yield()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public void Interrupt()
|
||||
{
|
||||
this._interrupted = true;
|
||||
this._canceller?.Cancel(true);
|
||||
}
|
||||
|
||||
|
||||
public static bool Interrupted()
|
||||
{
|
||||
if (Thread.WrapperThread == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Thread wrapperThread = Thread.WrapperThread;
|
||||
lock (wrapperThread)
|
||||
{
|
||||
bool interrupted = Thread.WrapperThread._interrupted;
|
||||
Thread.WrapperThread._interrupted = false;
|
||||
return interrupted;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool IsAlive()
|
||||
{
|
||||
if (this._task == null)
|
||||
return true; //実行されていない
|
||||
|
||||
//Taskが存在し、続行中のときtrue
|
||||
return (!this._task.IsCanceled
|
||||
&& !this._task.IsFaulted
|
||||
&& !this._task.IsCompleted);
|
||||
}
|
||||
|
||||
|
||||
public void Join()
|
||||
{
|
||||
this._task?.Wait();
|
||||
}
|
||||
|
||||
|
||||
public void Join(long timeout)
|
||||
{
|
||||
this._task?.Wait((int) timeout);
|
||||
}
|
||||
|
||||
|
||||
public virtual void Run()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public void SetDaemon(bool daemon)
|
||||
{
|
||||
this._isBackground = daemon;
|
||||
}
|
||||
|
||||
|
||||
public void SetName(string name)
|
||||
{
|
||||
this._name = name;
|
||||
}
|
||||
|
||||
|
||||
public static void Sleep(long milis)
|
||||
{
|
||||
System.Threading.Tasks.Task.Delay((int) milis).Wait();
|
||||
}
|
||||
|
||||
|
||||
public void Start(bool isSynced = false)
|
||||
{
|
||||
if (this._isRunning)
|
||||
throw new InvalidOperationException("Thread Already started.");
|
||||
|
||||
this._canceller = new CancellationTokenSource();
|
||||
|
||||
this._task = System.Threading.Tasks.Task.Run(() =>
|
||||
{
|
||||
Thread.WrapperThread = this;
|
||||
this._id = System.Environment.CurrentManagedThreadId;
|
||||
|
||||
//Log.Out("Thread.Start - Task Start");
|
||||
this._isRunning = true;
|
||||
|
||||
try
|
||||
{
|
||||
this._runnable.Run();
|
||||
//Log.Out("Thread.Start - Task Normaly End");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
//Log.Out("Thread.Start - Task Error End");
|
||||
Console.WriteLine(exception);
|
||||
}
|
||||
finally
|
||||
{
|
||||
this._isRunning = false;
|
||||
|
||||
this._tgroup?.Remove(this);
|
||||
|
||||
this._canceller?.Dispose();
|
||||
this._canceller = null;
|
||||
|
||||
//Log.Out("Thread.Start - Task Close Completed");
|
||||
}
|
||||
}, this._canceller.Token);
|
||||
|
||||
//同期的に実行するとき、動作中フラグONまで待つ。
|
||||
if (isSynced)
|
||||
while (!this._isRunning)
|
||||
System.Threading.Tasks.Task.Delay(300).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
|
||||
public void Cancel(bool isSynced = false)
|
||||
{
|
||||
//Log.Out("Thread.Cancel");
|
||||
|
||||
this._isCanceled = true;
|
||||
this._canceller?.Cancel(true);
|
||||
|
||||
//同期的に実行するとき、動作中フラグOFFまで待つ。
|
||||
if (isSynced)
|
||||
while (this._isRunning)
|
||||
System.Threading.Tasks.Task.Delay(300).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
|
||||
public bool Equals(Thread thread)
|
||||
{
|
||||
//渡し値スレッドがnullのとき、合致しない
|
||||
if (thread == null)
|
||||
return false;
|
||||
|
||||
//自身か渡し値スレッドの、スレッドIDが取得出来ていない(=スレッド未生成)
|
||||
// →合致しない
|
||||
if (this._id == null
|
||||
|| thread._id == null)
|
||||
return false;
|
||||
|
||||
return (this._id == thread._id);
|
||||
}
|
||||
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
//Log.Out("Thread.Dispose");
|
||||
|
||||
this._runnable = null;
|
||||
this._tgroup = null;
|
||||
this._task = null;
|
||||
this._canceller?.Dispose();
|
||||
this._canceller = null;
|
||||
this._name = null;
|
||||
this._isRunning = false;
|
||||
this._id = null;
|
||||
}
|
||||
}
|
||||
|
||||
public class ThreadGroup
|
||||
{
|
||||
private List<Thread> _threads = new List<Thread>();
|
||||
|
||||
public ThreadGroup()
|
||||
{
|
||||
}
|
||||
|
||||
public ThreadGroup(string name)
|
||||
{
|
||||
}
|
||||
|
||||
internal void Add(Thread t)
|
||||
{
|
||||
lock (_threads)
|
||||
{
|
||||
_threads.Add(t);
|
||||
}
|
||||
}
|
||||
|
||||
internal void Remove(Thread t)
|
||||
{
|
||||
lock (_threads)
|
||||
{
|
||||
_threads.Remove(t);
|
||||
}
|
||||
}
|
||||
|
||||
public int Enumerate(Thread[] array)
|
||||
{
|
||||
lock (_threads)
|
||||
{
|
||||
int count = Math.Min(array.Length, _threads.Count);
|
||||
_threads.CopyTo(0, array, 0, count);
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
||||
public int Enumerate (Thread[] array)
|
||||
{
|
||||
lock (_threads) {
|
||||
int count = Math.Min (array.Length, _threads.Count);
|
||||
_threads.CopyTo (0, array, 0, count);
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal class ThreadFactory
|
||||
{
|
||||
public Thread NewThread(IRunnable r)
|
||||
{
|
||||
Thread t = new Thread(r);
|
||||
t.SetDaemon(true);
|
||||
t.Start(true);
|
||||
|
||||
return t;
|
||||
}
|
||||
}
|
||||
internal class ThreadFactory
|
||||
{
|
||||
public Thread NewThread (IRunnable r)
|
||||
{
|
||||
Thread t = new Thread (r);
|
||||
t.SetDaemon (true);
|
||||
t.Start ();
|
||||
return t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,180 +4,163 @@ using ST = System.Threading;
|
||||
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
class ThreadPoolExecutor
|
||||
{
|
||||
ThreadFactory _tf;
|
||||
int _corePoolSize;
|
||||
int _maxPoolSize;
|
||||
List<Thread> _pool = new List<Thread>();
|
||||
int _runningThreads;
|
||||
int _freeThreads;
|
||||
bool _shutdown;
|
||||
Queue<IRunnable> _pendingTasks = new Queue<IRunnable>();
|
||||
|
||||
public ThreadPoolExecutor(int corePoolSize, ThreadFactory factory)
|
||||
{
|
||||
this._corePoolSize = corePoolSize;
|
||||
_maxPoolSize = corePoolSize;
|
||||
_tf = factory;
|
||||
}
|
||||
|
||||
public void SetMaximumPoolSize(int size)
|
||||
{
|
||||
_maxPoolSize = size;
|
||||
}
|
||||
|
||||
public bool IsShutdown()
|
||||
{
|
||||
return _shutdown;
|
||||
}
|
||||
|
||||
public virtual bool IsTerminated()
|
||||
{
|
||||
lock (_pendingTasks)
|
||||
{
|
||||
return _shutdown && _pendingTasks.Count == 0;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool IsTerminating()
|
||||
{
|
||||
lock (_pendingTasks)
|
||||
{
|
||||
return _shutdown && !IsTerminated();
|
||||
}
|
||||
}
|
||||
|
||||
public int GetCorePoolSize()
|
||||
{
|
||||
return _corePoolSize;
|
||||
}
|
||||
|
||||
public void PrestartAllCoreThreads()
|
||||
{
|
||||
lock (_pendingTasks)
|
||||
{
|
||||
while (_runningThreads < _corePoolSize)
|
||||
StartPoolThread();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetThreadFactory(ThreadFactory f)
|
||||
{
|
||||
_tf = f;
|
||||
}
|
||||
|
||||
public void Execute(IRunnable r)
|
||||
{
|
||||
InternalExecute(r, true);
|
||||
}
|
||||
|
||||
internal void InternalExecute(IRunnable r, bool checkShutdown)
|
||||
{
|
||||
lock (_pendingTasks)
|
||||
{
|
||||
if (_shutdown && checkShutdown)
|
||||
throw new InvalidOperationException();
|
||||
if (_runningThreads < _corePoolSize)
|
||||
{
|
||||
StartPoolThread();
|
||||
}
|
||||
else if (_freeThreads > 0)
|
||||
{
|
||||
_freeThreads--;
|
||||
}
|
||||
else if (_runningThreads < _maxPoolSize)
|
||||
{
|
||||
StartPoolThread();
|
||||
}
|
||||
_pendingTasks.Enqueue(r);
|
||||
ST.Monitor.PulseAll(_pendingTasks);
|
||||
}
|
||||
}
|
||||
|
||||
void StartPoolThread()
|
||||
{
|
||||
_runningThreads++;
|
||||
_pool.Add(_tf.NewThread(new RunnableAction(RunPoolThread)));
|
||||
}
|
||||
|
||||
public void RunPoolThread()
|
||||
{
|
||||
while (!IsTerminated())
|
||||
{
|
||||
try
|
||||
{
|
||||
IRunnable r = null;
|
||||
lock (_pendingTasks)
|
||||
{
|
||||
_freeThreads++;
|
||||
while (!IsTerminated() && _pendingTasks.Count == 0)
|
||||
ST.Monitor.Wait(_pendingTasks);
|
||||
if (IsTerminated())
|
||||
break;
|
||||
r = _pendingTasks.Dequeue();
|
||||
}
|
||||
if (r != null)
|
||||
r.Run();
|
||||
}
|
||||
class ThreadPoolExecutor
|
||||
{
|
||||
ThreadFactory _tf;
|
||||
int _corePoolSize;
|
||||
int _maxPoolSize;
|
||||
List<Thread> _pool = new List<Thread> ();
|
||||
int _runningThreads;
|
||||
int _freeThreads;
|
||||
bool _shutdown;
|
||||
Queue<IRunnable> _pendingTasks = new Queue<IRunnable> ();
|
||||
|
||||
public ThreadPoolExecutor (int corePoolSize, ThreadFactory factory)
|
||||
{
|
||||
this._corePoolSize = corePoolSize;
|
||||
_maxPoolSize = corePoolSize;
|
||||
_tf = factory;
|
||||
}
|
||||
|
||||
public void SetMaximumPoolSize (int size)
|
||||
{
|
||||
_maxPoolSize = size;
|
||||
}
|
||||
|
||||
public bool IsShutdown ()
|
||||
{
|
||||
return _shutdown;
|
||||
}
|
||||
|
||||
public virtual bool IsTerminated ()
|
||||
{
|
||||
lock (_pendingTasks) {
|
||||
return _shutdown && _pendingTasks.Count == 0;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool IsTerminating ()
|
||||
{
|
||||
lock (_pendingTasks) {
|
||||
return _shutdown && !IsTerminated ();
|
||||
}
|
||||
}
|
||||
|
||||
public int GetCorePoolSize ()
|
||||
{
|
||||
return _corePoolSize;
|
||||
}
|
||||
|
||||
public void PrestartAllCoreThreads ()
|
||||
{
|
||||
lock (_pendingTasks) {
|
||||
while (_runningThreads < _corePoolSize)
|
||||
StartPoolThread ();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetThreadFactory (ThreadFactory f)
|
||||
{
|
||||
_tf = f;
|
||||
}
|
||||
|
||||
public void Execute (IRunnable r)
|
||||
{
|
||||
InternalExecute (r, true);
|
||||
}
|
||||
|
||||
internal void InternalExecute (IRunnable r, bool checkShutdown)
|
||||
{
|
||||
lock (_pendingTasks) {
|
||||
if (_shutdown && checkShutdown)
|
||||
throw new InvalidOperationException ();
|
||||
if (_runningThreads < _corePoolSize) {
|
||||
StartPoolThread ();
|
||||
}
|
||||
else if (_freeThreads > 0) {
|
||||
_freeThreads--;
|
||||
}
|
||||
else if (_runningThreads < _maxPoolSize) {
|
||||
StartPoolThread ();
|
||||
}
|
||||
_pendingTasks.Enqueue (r);
|
||||
ST.Monitor.PulseAll (_pendingTasks);
|
||||
}
|
||||
}
|
||||
|
||||
void StartPoolThread ()
|
||||
{
|
||||
_runningThreads++;
|
||||
_pool.Add (_tf.NewThread (new RunnableAction (RunPoolThread)));
|
||||
}
|
||||
|
||||
public void RunPoolThread ()
|
||||
{
|
||||
while (!IsTerminated ()) {
|
||||
try {
|
||||
IRunnable r = null;
|
||||
lock (_pendingTasks) {
|
||||
_freeThreads++;
|
||||
while (!IsTerminated () && _pendingTasks.Count == 0)
|
||||
ST.Monitor.Wait (_pendingTasks);
|
||||
if (IsTerminated ())
|
||||
break;
|
||||
r = _pendingTasks.Dequeue ();
|
||||
}
|
||||
if (r != null)
|
||||
r.Run ();
|
||||
}
|
||||
//supress all errors, anyway
|
||||
//catch (ST.ThreadAbortException) {
|
||||
// // Do not catch a thread abort. If we've been aborted just let the thread die.
|
||||
// // Currently reseting an abort which was issued because the appdomain is being
|
||||
// // torn down results in the process living forever and consuming 100% cpu time.
|
||||
// return;
|
||||
//}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Shutdown()
|
||||
{
|
||||
lock (_pendingTasks)
|
||||
{
|
||||
_shutdown = true;
|
||||
ST.Monitor.PulseAll(_pendingTasks);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual List<IRunnable> ShutdownNow()
|
||||
{
|
||||
lock (_pendingTasks)
|
||||
{
|
||||
_shutdown = true;
|
||||
foreach (var t in _pool)
|
||||
{
|
||||
try
|
||||
{
|
||||
t.Cancel(true);
|
||||
t.Dispose();
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
_pool.Clear();
|
||||
_freeThreads = 0;
|
||||
_runningThreads = 0;
|
||||
var res = new List<IRunnable>(_pendingTasks);
|
||||
_pendingTasks.Clear();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class RunnableAction : IRunnable
|
||||
{
|
||||
Action _action;
|
||||
|
||||
public RunnableAction(Action a)
|
||||
{
|
||||
_action = a;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
_action();
|
||||
}
|
||||
}
|
||||
//catch (ST.ThreadAbortException) {
|
||||
// // Do not catch a thread abort. If we've been aborted just let the thread die.
|
||||
// // Currently reseting an abort which was issued because the appdomain is being
|
||||
// // torn down results in the process living forever and consuming 100% cpu time.
|
||||
// return;
|
||||
//}
|
||||
catch {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Shutdown ()
|
||||
{
|
||||
lock (_pendingTasks) {
|
||||
_shutdown = true;
|
||||
ST.Monitor.PulseAll (_pendingTasks);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual List<IRunnable> ShutdownNow ()
|
||||
{
|
||||
lock (_pendingTasks) {
|
||||
_shutdown = true;
|
||||
foreach (var t in _pool) {
|
||||
try {
|
||||
t.Abort ();
|
||||
} catch {}
|
||||
}
|
||||
_pool.Clear ();
|
||||
_freeThreads = 0;
|
||||
_runningThreads = 0;
|
||||
var res = new List<IRunnable> (_pendingTasks);
|
||||
_pendingTasks.Clear ();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class RunnableAction: IRunnable
|
||||
{
|
||||
Action _action;
|
||||
|
||||
public RunnableAction (Action a)
|
||||
{
|
||||
_action = a;
|
||||
}
|
||||
|
||||
public void Run ()
|
||||
{
|
||||
_action ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,153 +4,136 @@ using System.IO;
|
||||
namespace SharpCifs.Util.Sharpen
|
||||
{
|
||||
internal class WrappedSystemStream : Stream
|
||||
{
|
||||
private InputStream _ist;
|
||||
private OutputStream _ost;
|
||||
int _position;
|
||||
int _markedPosition;
|
||||
{
|
||||
private InputStream _ist;
|
||||
private OutputStream _ost;
|
||||
int _position;
|
||||
int _markedPosition;
|
||||
|
||||
public WrappedSystemStream(InputStream ist)
|
||||
{
|
||||
this._ist = ist;
|
||||
}
|
||||
public WrappedSystemStream (InputStream ist)
|
||||
{
|
||||
this._ist = ist;
|
||||
}
|
||||
|
||||
public WrappedSystemStream(OutputStream ost)
|
||||
{
|
||||
this._ost = ost;
|
||||
}
|
||||
public WrappedSystemStream (OutputStream ost)
|
||||
{
|
||||
this._ost = ost;
|
||||
}
|
||||
|
||||
public InputStream InputStream {
|
||||
get { return _ist; }
|
||||
}
|
||||
|
||||
public InputStream InputStream
|
||||
{
|
||||
get { return _ist; }
|
||||
}
|
||||
|
||||
public OutputStream OutputStream
|
||||
{
|
||||
get { return _ost; }
|
||||
}
|
||||
public OutputStream OutputStream {
|
||||
get { return _ost; }
|
||||
}
|
||||
|
||||
public void Close() //remove `override`
|
||||
{
|
||||
if (_ist != null)
|
||||
{
|
||||
if (_ist != null) {
|
||||
//Stream.`Close` method deleted
|
||||
//_ist.Close ();
|
||||
//_ist.Close ();
|
||||
_ist.Dispose();
|
||||
}
|
||||
if (_ost != null)
|
||||
{
|
||||
}
|
||||
if (_ost != null) {
|
||||
//Stream.`Close` method deleted
|
||||
//_ost.Close ();
|
||||
//_ost.Close ();
|
||||
_ost.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
_ost.Flush();
|
||||
}
|
||||
public override void Flush ()
|
||||
{
|
||||
_ost.Flush ();
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
int res = _ist.Read(buffer, offset, count);
|
||||
if (res != -1)
|
||||
{
|
||||
_position += res;
|
||||
return res;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public override int Read (byte[] buffer, int offset, int count)
|
||||
{
|
||||
int res = _ist.Read (buffer, offset, count);
|
||||
if (res != -1) {
|
||||
_position += res;
|
||||
return res;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override int ReadByte()
|
||||
{
|
||||
int res = _ist.Read();
|
||||
if (res != -1)
|
||||
_position++;
|
||||
return res;
|
||||
}
|
||||
public override int ReadByte ()
|
||||
{
|
||||
int res = _ist.Read ();
|
||||
if (res != -1)
|
||||
_position++;
|
||||
return res;
|
||||
}
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
if (origin == SeekOrigin.Begin)
|
||||
Position = offset;
|
||||
else if (origin == SeekOrigin.Current)
|
||||
Position = Position + offset;
|
||||
else if (origin == SeekOrigin.End)
|
||||
Position = Length + offset;
|
||||
return Position;
|
||||
}
|
||||
public override long Seek (long offset, SeekOrigin origin)
|
||||
{
|
||||
if (origin == SeekOrigin.Begin)
|
||||
Position = offset;
|
||||
else if (origin == SeekOrigin.Current)
|
||||
Position = Position + offset;
|
||||
else if (origin == SeekOrigin.End)
|
||||
Position = Length + offset;
|
||||
return Position;
|
||||
}
|
||||
|
||||
public override void SetLength(long value)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
public override void SetLength (long value)
|
||||
{
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
_ost.Write(buffer, offset, count);
|
||||
_position += count;
|
||||
}
|
||||
public override void Write (byte[] buffer, int offset, int count)
|
||||
{
|
||||
_ost.Write (buffer, offset, count);
|
||||
_position += count;
|
||||
}
|
||||
|
||||
public override void WriteByte(byte value)
|
||||
{
|
||||
_ost.Write(value);
|
||||
_position++;
|
||||
}
|
||||
public override void WriteByte (byte value)
|
||||
{
|
||||
_ost.Write (value);
|
||||
_position++;
|
||||
}
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get { return (_ist != null); }
|
||||
}
|
||||
public override bool CanRead {
|
||||
get { return (_ist != null); }
|
||||
}
|
||||
|
||||
public override bool CanSeek
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public override bool CanSeek {
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool CanWrite
|
||||
{
|
||||
get { return (_ost != null); }
|
||||
}
|
||||
public override bool CanWrite {
|
||||
get { return (_ost != null); }
|
||||
}
|
||||
|
||||
public override long Length
|
||||
{
|
||||
get { return _ist.Length; }
|
||||
}
|
||||
|
||||
internal void OnMark(int nb)
|
||||
{
|
||||
_markedPosition = _position;
|
||||
_ist.Mark(nb);
|
||||
}
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_ist != null && _ist.CanSeek())
|
||||
return _ist.Position;
|
||||
return _position;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == _position)
|
||||
return;
|
||||
|
||||
if (value == _markedPosition
|
||||
&& _ist.MarkSupported())
|
||||
{
|
||||
_ist.Reset();
|
||||
}
|
||||
else if (_ist != null && _ist.CanSeek())
|
||||
{
|
||||
_ist.Position = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public override long Length {
|
||||
get { return _ist.Length; }
|
||||
}
|
||||
|
||||
internal void OnMark (int nb)
|
||||
{
|
||||
_markedPosition = _position;
|
||||
_ist.Mark (nb);
|
||||
}
|
||||
|
||||
public override long Position {
|
||||
get
|
||||
{
|
||||
if (_ist != null && _ist.CanSeek ())
|
||||
return _ist.Position;
|
||||
return _position;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == _position)
|
||||
return;
|
||||
if (value == _markedPosition)
|
||||
_ist.Reset ();
|
||||
else if (_ist != null && _ist.CanSeek ()) {
|
||||
_ist.Position = value;
|
||||
}
|
||||
else
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
namespace SharpCifs.Util.Transport
|
||||
{
|
||||
public interface IRequest
|
||||
{
|
||||
}
|
||||
public interface IRequest
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
namespace SharpCifs.Util.Transport
|
||||
{
|
||||
public abstract class Response
|
||||
{
|
||||
public long Expiration;
|
||||
public abstract class Response
|
||||
{
|
||||
public long Expiration;
|
||||
|
||||
public bool IsReceived;
|
||||
}
|
||||
public bool IsReceived;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,303 +18,275 @@ using System;
|
||||
using System.IO;
|
||||
using SharpCifs.Smb;
|
||||
using SharpCifs.Util.Sharpen;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharpCifs.Util.Transport
|
||||
{
|
||||
/// <summary>
|
||||
/// This class simplifies communication for protocols that support
|
||||
/// multiplexing requests.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This class simplifies communication for protocols that support
|
||||
/// multiplexing requests. It encapsulates a stream and some protocol
|
||||
/// knowledge (provided by a concrete subclass) so that connecting,
|
||||
/// disconnecting, sending, and receiving can be syncronized
|
||||
/// properly. Apparatus is provided to send and receive requests
|
||||
/// concurrently.
|
||||
/// </remarks>
|
||||
public abstract class Transport : IRunnable
|
||||
{
|
||||
internal static int Id;
|
||||
/// <summary>
|
||||
/// This class simplifies communication for protocols that support
|
||||
/// multiplexing requests.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This class simplifies communication for protocols that support
|
||||
/// multiplexing requests. It encapsulates a stream and some protocol
|
||||
/// knowledge (provided by a concrete subclass) so that connecting,
|
||||
/// disconnecting, sending, and receiving can be syncronized
|
||||
/// properly. Apparatus is provided to send and receive requests
|
||||
/// concurrently.
|
||||
/// </remarks>
|
||||
public abstract class Transport : IRunnable
|
||||
{
|
||||
internal static int Id;
|
||||
|
||||
//internal static LogStream log = LogStream.GetInstance();
|
||||
//internal static LogStream log = LogStream.GetInstance();
|
||||
|
||||
public LogStream Log
|
||||
{
|
||||
get
|
||||
{
|
||||
return LogStream.GetInstance();
|
||||
}
|
||||
}
|
||||
public LogStream Log
|
||||
{
|
||||
get
|
||||
{
|
||||
return LogStream.GetInstance();
|
||||
}
|
||||
}
|
||||
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
public static int Readn(InputStream @in, byte[] b, int off, int len)
|
||||
{
|
||||
int i = 0;
|
||||
int n = -5;
|
||||
while (i < len)
|
||||
{
|
||||
n = @in.Read(b, off + i, len - i);
|
||||
if (n <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
i += n;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
public static int Readn(InputStream @in, byte[] b, int off, int len)
|
||||
{
|
||||
int i = 0;
|
||||
int n = -5;
|
||||
while (i < len)
|
||||
{
|
||||
n = @in.Read(b, off + i, len - i);
|
||||
if (n <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
i += n;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
internal int State;
|
||||
internal int State;
|
||||
|
||||
internal string Name = "Transport" + Id++;
|
||||
internal string Name = "Transport" + Id++;
|
||||
|
||||
internal Thread Thread;
|
||||
internal Thread Thread;
|
||||
|
||||
internal TransportException Te;
|
||||
internal TransportException Te;
|
||||
|
||||
protected internal Hashtable ResponseMap = new Hashtable();
|
||||
protected internal Hashtable ResponseMap = new Hashtable();
|
||||
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
protected internal abstract void MakeKey(ServerMessageBlock request);
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
protected internal abstract void MakeKey(ServerMessageBlock request);
|
||||
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
protected internal abstract ServerMessageBlock PeekKey();
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
protected internal abstract ServerMessageBlock PeekKey();
|
||||
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
protected internal abstract void DoSend(ServerMessageBlock request);
|
||||
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
protected internal abstract void DoRecv(Response response);
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
protected internal abstract void DoRecv(Response response);
|
||||
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
protected internal abstract void DoSkip();
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
protected internal abstract void DoSkip();
|
||||
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
public virtual void Sendrecv(ServerMessageBlock request, Response response, long timeout)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
MakeKey(request);
|
||||
response.IsReceived = false;
|
||||
try
|
||||
{
|
||||
ResponseMap.Put(request, response);
|
||||
DoSend(request);
|
||||
response.Expiration = Runtime.CurrentTimeMillis() + timeout;
|
||||
while (!response.IsReceived)
|
||||
{
|
||||
Runtime.Wait(this, timeout);
|
||||
timeout = response.Expiration - Runtime.CurrentTimeMillis();
|
||||
if (timeout <= 0)
|
||||
{
|
||||
throw new TransportException(
|
||||
Name + " timedout waiting for response to " + request);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
if (Log.Level > 2)
|
||||
{
|
||||
Runtime.PrintStackTrace(ioe, Log);
|
||||
}
|
||||
try
|
||||
{
|
||||
Disconnect(true);
|
||||
}
|
||||
catch (IOException ioe2)
|
||||
{
|
||||
Runtime.PrintStackTrace(ioe2, Log);
|
||||
}
|
||||
throw;
|
||||
}
|
||||
catch (Exception ie)
|
||||
{
|
||||
throw new TransportException(ie);
|
||||
}
|
||||
finally
|
||||
{
|
||||
//Sharpen.Collections.Remove(response_map, request);
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
public virtual void Sendrecv(ServerMessageBlock request, Response response, long timeout)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
MakeKey(request);
|
||||
response.IsReceived = false;
|
||||
try
|
||||
{
|
||||
ResponseMap.Put(request, response);
|
||||
DoSend(request);
|
||||
response.Expiration = Runtime.CurrentTimeMillis() + timeout;
|
||||
while (!response.IsReceived)
|
||||
{
|
||||
Runtime.Wait(this, timeout);
|
||||
timeout = response.Expiration - Runtime.CurrentTimeMillis();
|
||||
if (timeout <= 0)
|
||||
{
|
||||
throw new TransportException(Name + " timedout waiting for response to " + request
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
if (Log.Level > 2)
|
||||
{
|
||||
Runtime.PrintStackTrace(ioe, Log);
|
||||
}
|
||||
try
|
||||
{
|
||||
Disconnect(true);
|
||||
}
|
||||
catch (IOException ioe2)
|
||||
{
|
||||
Runtime.PrintStackTrace(ioe2, Log);
|
||||
}
|
||||
throw;
|
||||
}
|
||||
catch (Exception ie)
|
||||
{
|
||||
throw new TransportException(ie);
|
||||
}
|
||||
finally
|
||||
{
|
||||
//Sharpen.Collections.Remove(response_map, request);
|
||||
ResponseMap.Remove(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Loop()
|
||||
{
|
||||
while (Thread.CurrentThread().Equals(Thread))
|
||||
{
|
||||
if (Thread.IsCanceled)
|
||||
break;
|
||||
private void Loop()
|
||||
{
|
||||
while (Thread == Thread.CurrentThread())
|
||||
{
|
||||
try
|
||||
{
|
||||
ServerMessageBlock key = PeekKey();
|
||||
if (key == null)
|
||||
{
|
||||
throw new IOException("end of stream");
|
||||
}
|
||||
|
||||
|
||||
lock (this)
|
||||
{
|
||||
Response response = (Response)ResponseMap.Get(key);
|
||||
if (response == null)
|
||||
{
|
||||
if (Log.Level >= 4)
|
||||
{
|
||||
Log.WriteLine("Invalid key, skipping message");
|
||||
}
|
||||
DoSkip();
|
||||
}
|
||||
else
|
||||
{
|
||||
DoRecv(response);
|
||||
response.IsReceived = true;
|
||||
Runtime.NotifyAll(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string msg = ex.Message;
|
||||
bool timeout = msg != null && msg.Equals("Read timed out");
|
||||
bool hard = timeout == false;
|
||||
if (!timeout && Log.Level >= 3)
|
||||
{
|
||||
Runtime.PrintStackTrace(ex, Log);
|
||||
}
|
||||
try
|
||||
{
|
||||
Disconnect(hard);
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
Runtime.PrintStackTrace(ioe, Log);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ServerMessageBlock key = PeekKey();
|
||||
if (key == null)
|
||||
{
|
||||
throw new IOException("end of stream");
|
||||
}
|
||||
/// <exception cref="System.Exception"></exception>
|
||||
protected internal abstract void DoConnect();
|
||||
|
||||
lock (this)
|
||||
{
|
||||
if (Thread.IsCanceled)
|
||||
break;
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
protected internal abstract void DoDisconnect(bool hard);
|
||||
|
||||
Response response = (Response)ResponseMap.Get(key);
|
||||
if (response == null)
|
||||
{
|
||||
if (Log.Level >= 4)
|
||||
{
|
||||
Log.WriteLine("Invalid key, skipping message");
|
||||
}
|
||||
DoSkip();
|
||||
}
|
||||
else
|
||||
{
|
||||
DoRecv(response);
|
||||
/// <exception cref="SharpCifs.Util.Transport.TransportException"></exception>
|
||||
public virtual void Connect(long timeout)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (State)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (Thread.IsCanceled)
|
||||
break;
|
||||
case 3:
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
response.IsReceived = true;
|
||||
Runtime.NotifyAll(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string msg = ex.Message;
|
||||
bool timeout = msg != null && msg.Equals("Read timed out");
|
||||
bool hard = timeout == false;
|
||||
case 4:
|
||||
{
|
||||
// already connected
|
||||
State = 0;
|
||||
throw new TransportException("Connection in error", Te);
|
||||
}
|
||||
|
||||
if (!timeout && Log.Level >= 3)
|
||||
{
|
||||
Runtime.PrintStackTrace(ex, Log);
|
||||
}
|
||||
default:
|
||||
{
|
||||
//TransportException te = new TransportException("Invalid state: " + state);
|
||||
State = 0;
|
||||
throw new TransportException("Invalid state: " + State);
|
||||
}
|
||||
}
|
||||
State = 1;
|
||||
Te = null;
|
||||
Thread = new Thread(this);
|
||||
Thread.SetDaemon(true);
|
||||
lock (Thread)
|
||||
{
|
||||
Thread.Start();
|
||||
Runtime.Wait(Thread, timeout);
|
||||
switch (State)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
State = 0;
|
||||
Thread = null;
|
||||
throw new TransportException("Connection timeout");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Disconnect(hard);
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
Runtime.PrintStackTrace(ioe, Log);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
if (Te != null)
|
||||
{
|
||||
State = 4;
|
||||
Thread = null;
|
||||
throw Te;
|
||||
}
|
||||
State = 3;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ie)
|
||||
{
|
||||
State = 0;
|
||||
Thread = null;
|
||||
throw new TransportException(ie);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (State != 0 && State != 3 && State != 4)
|
||||
{
|
||||
if (Log.Level >= 1)
|
||||
{
|
||||
Log.WriteLine("Invalid state: " + State);
|
||||
}
|
||||
State = 0;
|
||||
Thread = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <exception cref="System.Exception"></exception>
|
||||
protected internal abstract void DoConnect();
|
||||
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
protected internal abstract void DoDisconnect(bool hard);
|
||||
|
||||
/// <exception cref="SharpCifs.Util.Transport.TransportException"></exception>
|
||||
public virtual void Connect(long timeout)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (State)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case 3:
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
case 4:
|
||||
{
|
||||
// already connected
|
||||
State = 0;
|
||||
throw new TransportException("Connection in error", Te);
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
//TransportException te = new TransportException("Invalid state: " + state);
|
||||
State = 0;
|
||||
throw new TransportException("Invalid state: " + State);
|
||||
}
|
||||
}
|
||||
State = 1;
|
||||
Te = null;
|
||||
|
||||
if (Thread != null)
|
||||
{
|
||||
Thread.Cancel(true);
|
||||
Thread.Dispose();
|
||||
}
|
||||
|
||||
Thread = new Thread(this);
|
||||
Thread.SetDaemon(true);
|
||||
lock (Thread)
|
||||
{
|
||||
Thread.Start(true);
|
||||
|
||||
Runtime.Wait(Thread, timeout);
|
||||
switch (State)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
State = 0;
|
||||
Thread?.Cancel();
|
||||
Thread?.Dispose();
|
||||
Thread = null;
|
||||
throw new TransportException("Connection timeout");
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
if (Te != null)
|
||||
{
|
||||
State = 4;
|
||||
Thread?.Cancel();
|
||||
Thread?.Dispose();
|
||||
Thread = null;
|
||||
throw Te;
|
||||
}
|
||||
State = 3;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ie)
|
||||
{
|
||||
State = 0;
|
||||
Thread?.Cancel();
|
||||
Thread?.Dispose();
|
||||
Thread = null;
|
||||
throw new TransportException(ie);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (State != 0 && State != 3 && State != 4)
|
||||
{
|
||||
if (Log.Level >= 1)
|
||||
{
|
||||
Log.WriteLine("Invalid state: " + State);
|
||||
}
|
||||
State = 0;
|
||||
Thread?.Cancel();
|
||||
Thread?.Dispose();
|
||||
Thread = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
public virtual void Disconnect(bool hard)
|
||||
{
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
public virtual void Disconnect(bool hard)
|
||||
{
|
||||
|
||||
if (hard)
|
||||
{
|
||||
@@ -351,8 +323,6 @@ namespace SharpCifs.Util.Transport
|
||||
|
||||
case 4:
|
||||
{
|
||||
Thread?.Cancel();
|
||||
Thread?.Dispose();
|
||||
Thread = null;
|
||||
State = 0;
|
||||
break;
|
||||
@@ -364,8 +334,6 @@ namespace SharpCifs.Util.Transport
|
||||
{
|
||||
Log.WriteLine("Invalid state: " + State);
|
||||
}
|
||||
Thread?.Cancel();
|
||||
Thread?.Dispose();
|
||||
Thread = null;
|
||||
State = 0;
|
||||
break;
|
||||
@@ -378,124 +346,109 @@ namespace SharpCifs.Util.Transport
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
lock (this)
|
||||
{
|
||||
IOException ioe = null;
|
||||
switch (State)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
return;
|
||||
}
|
||||
{
|
||||
IOException ioe = null;
|
||||
switch (State)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
hard = true;
|
||||
goto case 3;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
hard = true;
|
||||
goto case 3;
|
||||
}
|
||||
|
||||
case 3:
|
||||
{
|
||||
if (ResponseMap.Count != 0 && !hard)
|
||||
{
|
||||
break;
|
||||
}
|
||||
try
|
||||
{
|
||||
DoDisconnect(hard);
|
||||
}
|
||||
catch (IOException ioe0)
|
||||
{
|
||||
ioe = ioe0;
|
||||
}
|
||||
goto case 4;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
if (ResponseMap.Count != 0 && !hard)
|
||||
{
|
||||
break;
|
||||
}
|
||||
try
|
||||
{
|
||||
DoDisconnect(hard);
|
||||
}
|
||||
catch (IOException ioe0)
|
||||
{
|
||||
ioe = ioe0;
|
||||
}
|
||||
goto case 4;
|
||||
}
|
||||
|
||||
case 4:
|
||||
{
|
||||
Thread?.Cancel();
|
||||
Thread?.Dispose();
|
||||
Thread = null;
|
||||
State = 0;
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
Thread = null;
|
||||
State = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
if (Log.Level >= 1)
|
||||
{
|
||||
Log.WriteLine("Invalid state: " + State);
|
||||
}
|
||||
Thread?.Cancel();
|
||||
Thread?.Dispose();
|
||||
Thread = null;
|
||||
State = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ioe != null)
|
||||
{
|
||||
throw ioe;
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (Log.Level >= 1)
|
||||
{
|
||||
Log.WriteLine("Invalid state: " + State);
|
||||
}
|
||||
Thread = null;
|
||||
State = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ioe != null)
|
||||
{
|
||||
throw ioe;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Run()
|
||||
{
|
||||
Thread runThread = Thread.CurrentThread();
|
||||
public virtual void Run()
|
||||
{
|
||||
Thread runThread = Thread.CurrentThread();
|
||||
Exception ex0 = null;
|
||||
try
|
||||
{
|
||||
DoConnect();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex0 = ex;
|
||||
// Defer to below where we're locked
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
lock (runThread)
|
||||
{
|
||||
if (runThread != Thread)
|
||||
{
|
||||
if (ex0 != null)
|
||||
{
|
||||
if (Log.Level >= 2)
|
||||
{
|
||||
Runtime.PrintStackTrace(ex0, Log);
|
||||
}
|
||||
}
|
||||
//return;
|
||||
}
|
||||
if (ex0 != null)
|
||||
{
|
||||
Te = new TransportException(ex0);
|
||||
}
|
||||
State = 2;
|
||||
// run connected
|
||||
Runtime.Notify(runThread);
|
||||
}
|
||||
}
|
||||
Loop();
|
||||
}
|
||||
|
||||
if (runThread.IsCanceled)
|
||||
return;
|
||||
|
||||
Exception ex0 = null;
|
||||
try
|
||||
{
|
||||
DoConnect();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex0 = ex;
|
||||
// Defer to below where we're locked
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
lock (runThread)
|
||||
{
|
||||
if (!runThread.IsCanceled)
|
||||
{
|
||||
if (!runThread.Equals(Thread))
|
||||
{
|
||||
if (ex0 != null)
|
||||
{
|
||||
if (Log.Level >= 2)
|
||||
{
|
||||
Runtime.PrintStackTrace(ex0, Log);
|
||||
}
|
||||
}
|
||||
//return;
|
||||
}
|
||||
if (ex0 != null)
|
||||
{
|
||||
Te = new TransportException(ex0);
|
||||
}
|
||||
State = 2;
|
||||
// run connected
|
||||
Runtime.Notify(runThread);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (runThread.IsCanceled)
|
||||
return;
|
||||
|
||||
Loop();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,43 +21,43 @@ using SharpCifs.Util.Sharpen;
|
||||
namespace SharpCifs.Util.Transport
|
||||
{
|
||||
|
||||
public class TransportException : IOException
|
||||
{
|
||||
private Exception _rootCause;
|
||||
public class TransportException : IOException
|
||||
{
|
||||
private Exception _rootCause;
|
||||
|
||||
public TransportException()
|
||||
{
|
||||
}
|
||||
public TransportException()
|
||||
{
|
||||
}
|
||||
|
||||
public TransportException(string msg) : base(msg)
|
||||
{
|
||||
}
|
||||
public TransportException(string msg) : base(msg)
|
||||
{
|
||||
}
|
||||
|
||||
public TransportException(Exception rootCause)
|
||||
{
|
||||
this._rootCause = rootCause;
|
||||
}
|
||||
public TransportException(Exception rootCause)
|
||||
{
|
||||
this._rootCause = rootCause;
|
||||
}
|
||||
|
||||
public TransportException(string msg, Exception rootCause) : base(msg)
|
||||
{
|
||||
this._rootCause = rootCause;
|
||||
}
|
||||
public TransportException(string msg, Exception rootCause) : base(msg)
|
||||
{
|
||||
this._rootCause = rootCause;
|
||||
}
|
||||
|
||||
public virtual Exception GetRootCause()
|
||||
{
|
||||
return _rootCause;
|
||||
}
|
||||
public virtual Exception GetRootCause()
|
||||
{
|
||||
return _rootCause;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (_rootCause != null)
|
||||
{
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
Runtime.PrintStackTrace(_rootCause, pw);
|
||||
return base.ToString() + "\n" + sw;
|
||||
}
|
||||
return base.ToString();
|
||||
}
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
if (_rootCause != null)
|
||||
{
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
Runtime.PrintStackTrace(_rootCause, pw);
|
||||
return base.ToString() + "\n" + sw;
|
||||
}
|
||||
return base.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user