Show / Hide Table of Contents

Class IOMiscUtils

Misc utils for I/O

Inheritance
System.Object
IOMiscUtils
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: NFX
Assembly: NFX.dll
Syntax
public static class IOMiscUtils

Fields

IO_WAIT_DEFAULT_TIMEOUT

Declaration
public const int IO_WAIT_DEFAULT_TIMEOUT = 2000
Field Value
Type Description
System.Int32

IO_WAIT_GRANULARITY_MS

Declaration
public const int IO_WAIT_GRANULARITY_MS = 200
Field Value
Type Description
System.Int32

IO_WAIT_MIN_TIMEOUT

Declaration
public const int IO_WAIT_MIN_TIMEOUT = 100
Field Value
Type Description
System.Int32

Methods

AsCharEnumerable(Stream)

Declaration
public static IEnumerable<char> AsCharEnumerable(this Stream stream)
Parameters
Type Name Description
System.IO.Stream stream
Returns
Type Description
System.Collections.Generic.IEnumerable<System.Char>

AsCharEnumerable(TextReader)

Declaration
public static IEnumerable<char> AsCharEnumerable(this TextReader reader)
Parameters
Type Name Description
System.IO.TextReader reader
Returns
Type Description
System.Collections.Generic.IEnumerable<System.Char>

CopyStream(Stream, Stream, Boolean)

Copies one stream into another using temp buffer

Declaration
public static void CopyStream(Stream from, Stream to, bool noCache = false)
Parameters
Type Name Description
System.IO.Stream from
System.IO.Stream to
System.Boolean noCache

EnsureAccessibleDirectory(String)

Creates directory and immediately grants it accessibility rules for everyone if it does not exists, or returns the existing directory

Declaration
public static DirectoryInfo EnsureAccessibleDirectory(string path)
Parameters
Type Name Description
System.String path
Returns
Type Description
System.IO.DirectoryInfo

EnsureDirectoryDeleted(String, Int32)

Tries to delete the specified directory if it exists BLOCKING for up to the specified interval until directory is PHYSICALLY deleted. Returns true when directory either did not exist in the first place or was successfully deleted (with confirmation). Returns false when directory could not be confirmed to be deleted within the specified timeout, this does not mean that the OS will not delete the directory later, so calling this function in a loop is expected. NOTE: Directory.Delete() does not guarantee that directory is no longer on disk upon its return

Declaration
public static bool EnsureDirectoryDeleted(string dirName, int timeoutMs = 2000)
Parameters
Type Name Description
System.String dirName

Directory to delete

System.Int32 timeoutMs

Timeout in ms

Returns
Type Description
System.Boolean

EnsureFileEventuallyDeleted(String)

Deleted file if it exists - does not block until file is deleted, the behavior is up to the OS

Declaration
public static void EnsureFileEventuallyDeleted(string fileName)
Parameters
Type Name Description
System.String fileName

Full file name with path

GetURL(String, Int32)

Fetch the content of a given URL.

Declaration
public static KeyValuePair<HttpStatusCode, string> GetURL(string urlAddress, int timeout = 5000)
Parameters
Type Name Description
System.String urlAddress
System.Int32 timeout
Returns
Type Description
System.Collections.Generic.KeyValuePair<System.Net.HttpStatusCode, System.String>

Return fetched URL as a string, or null string when resulting status code is not HttpStatusCode.OK.

GuidFromNetworkByteOrder(Byte[], Int32)

Declaration
public static Guid GuidFromNetworkByteOrder(this byte[] buf, int offset = 0)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 offset
Returns
Type Description
System.Guid

MemBufferEquals(Byte[], Byte[])

Returns true if both buffers contain the same number of the same bytes. The implementation uses quad-word comparison as much as possible for speed. Requires UNSAFE switch

Declaration
public static bool MemBufferEquals(this byte[] buf1, byte[] buf2)
Parameters
Type Name Description
System.Byte[] buf1
System.Byte[] buf2
Returns
Type Description
System.Boolean

PackISO3CodeToInt(String)

Represents an ISO code as 4 byte integer filled with up to 3 ASCII chars converted to upper case, the highest byte is free to be used by the application

Declaration
public static int PackISO3CodeToInt(string iso)
Parameters
Type Name Description
System.String iso
Returns
Type Description
System.Int32

ReadBEInt32(Byte[])

Reads an integer encoded as big endian from buffer at index 0

Declaration
public static int ReadBEInt32(this byte[] buf)
Parameters
Type Name Description
System.Byte[] buf
Returns
Type Description
System.Int32

ReadBEInt32(Byte[], ref Int32)

Reads an integer encoded as big endian from buffer at the specified index and increments the idx by the number of bytes read

Declaration
public static int ReadBEInt32(this byte[] buf, ref int idx)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 idx
Returns
Type Description
System.Int32

ReadBEInt32(Byte[], ref Int64)

Reads an integer encoded as big endian from buffer at the specified index and increments the idx by the number of bytes read

Declaration
public static int ReadBEInt32(this byte[] buf, ref long idx)
Parameters
Type Name Description
System.Byte[] buf
System.Int64 idx
Returns
Type Description
System.Int32

ReadBEInt32(Stream)

Reads an integer encoded as big endian from buffer at the specified index

Declaration
public static int ReadBEInt32(this Stream s)
Parameters
Type Name Description
System.IO.Stream s
Returns
Type Description
System.Int32

ReadBEShort(Byte[], ref Int32)

Reads a short encoded as big endian from buffer at the specified index

Declaration
public static short ReadBEShort(this byte[] buf, ref int idx)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 idx
Returns
Type Description
System.Int16

ReadBEShort(Stream)

Reads a short encoded as big endian from stream

Declaration
public static short ReadBEShort(this Stream s)
Parameters
Type Name Description
System.IO.Stream s
Returns
Type Description
System.Int16

ReadBEUInt32(Byte[])

Reads an unsigned integer encoded as big endian from buffer at index 0

Declaration
public static uint ReadBEUInt32(this byte[] buf)
Parameters
Type Name Description
System.Byte[] buf
Returns
Type Description
System.UInt32

ReadBEUInt32(Byte[], ref Int32)

Reads an unsigned integer encoded as big endian from buffer at the specified index and increments the idx by the number of bytes read

Declaration
public static uint ReadBEUInt32(this byte[] buf, ref int idx)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 idx
Returns
Type Description
System.UInt32

ReadBEUInt32(Byte[], ref Int64)

Reads an unsigned integer encoded as big endian from buffer at the specified index and increments the idx by the number of bytes read

Declaration
public static uint ReadBEUInt32(this byte[] buf, ref long idx)
Parameters
Type Name Description
System.Byte[] buf
System.Int64 idx
Returns
Type Description
System.UInt32

ReadBEUInt64(Byte[], Int32)

Reads an integer encoded as big endian from buffer at the specified index and increments the idx by the number of bytes read

Declaration
public static ulong ReadBEUInt64(this byte[] buf, int idx = 0)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 idx
Returns
Type Description
System.UInt64

ReadBEUInt64(Byte[], ref Int32)

Reads an integer encoded as big endian from buffer at the specified index and increments the idx by the number of bytes read

Declaration
public static ulong ReadBEUInt64(this byte[] buf, ref int idx)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 idx
Returns
Type Description
System.UInt64

ReadBEUInt64(Stream)

Reads an integer encoded as big endian from buffer at the specified index

Declaration
public static ulong ReadBEUInt64(this Stream s)
Parameters
Type Name Description
System.IO.Stream s
Returns
Type Description
System.UInt64

ReadBEUShort(Stream)

Reads an ushort encoded as big endian from stream

Declaration
public static ushort ReadBEUShort(this Stream s)
Parameters
Type Name Description
System.IO.Stream s
Returns
Type Description
System.UInt16

ReadLEInt32(Byte[])

Reads an integer encoded as little endian from buffer at index 0

Declaration
public static int ReadLEInt32(this byte[] buf)
Parameters
Type Name Description
System.Byte[] buf
Returns
Type Description
System.Int32

ReadLEInt32(Byte[], ref Int32)

Reads an integer encoded as little endian from buffer at the specified index and increments the idx by the number of bytes read

Declaration
public static int ReadLEInt32(this byte[] buf, ref int idx)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 idx
Returns
Type Description
System.Int32

ReadLEInt32(Byte[], ref Int64)

Reads an integer encoded as little endian from buffer at the specified index and increments the idx by the number of bytes read

Declaration
public static int ReadLEInt32(this byte[] buf, ref long idx)
Parameters
Type Name Description
System.Byte[] buf
System.Int64 idx
Returns
Type Description
System.Int32

ReadLEInt32(Stream)

Reads an integer encoded as little endian from buffer at the specified index

Declaration
public static int ReadLEInt32(this Stream s)
Parameters
Type Name Description
System.IO.Stream s
Returns
Type Description
System.Int32

ReadLEShort(Byte[], ref Int32)

Reads a short encoded as little endian from buffer at the specified index

Declaration
public static short ReadLEShort(this byte[] buf, ref int idx)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 idx
Returns
Type Description
System.Int16

ReadLEShort(Stream)

Reads a short encoded as little endian from stream

Declaration
public static short ReadLEShort(this Stream s)
Parameters
Type Name Description
System.IO.Stream s
Returns
Type Description
System.Int16

ReadLEUInt32(Byte[])

Reads an unsigned integer encoded as little endian from buffer at index 0

Declaration
public static uint ReadLEUInt32(this byte[] buf)
Parameters
Type Name Description
System.Byte[] buf
Returns
Type Description
System.UInt32

ReadLEUInt32(Byte[], ref Int32)

Reads an unsigned integer encoded as little endian from buffer at the specified index and increments the idx by the number of bytes read

Declaration
public static uint ReadLEUInt32(this byte[] buf, ref int idx)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 idx
Returns
Type Description
System.UInt32

ReadLEUInt32(Byte[], ref Int64)

Reads an unsigned integer encoded as little endian from buffer at the specified index and increments the idx by the number of bytes read

Declaration
public static uint ReadLEUInt32(this byte[] buf, ref long idx)
Parameters
Type Name Description
System.Byte[] buf
System.Int64 idx
Returns
Type Description
System.UInt32

ReadLEUInt64(Byte[], Int32)

Reads an integer encoded as little endian from buffer at the specified index and increments the idx by the number of bytes read

Declaration
public static ulong ReadLEUInt64(this byte[] buf, int idx = 0)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 idx
Returns
Type Description
System.UInt64

ReadLEUInt64(Byte[], ref Int32)

Reads an integer encoded as little endian from buffer at the specified index and increments the idx by the number of bytes read

Declaration
public static ulong ReadLEUInt64(this byte[] buf, ref int idx)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 idx
Returns
Type Description
System.UInt64

ReadLEUInt64(Stream)

Reads an integer encoded as little endian from buffer at the specified index

Declaration
public static ulong ReadLEUInt64(this Stream s)
Parameters
Type Name Description
System.IO.Stream s
Returns
Type Description
System.UInt64

ReadLEUShort(Stream)

Reads an ushort encoded as little endian from stream

Declaration
public static ushort ReadLEUShort(this Stream s)
Parameters
Type Name Description
System.IO.Stream s
Returns
Type Description
System.UInt16

ReadLine(String)

Reads first line from the string

Declaration
public static string ReadLine(this string str)
Parameters
Type Name Description
System.String str
Returns
Type Description
System.String

ToNetworkByteOrder(Guid)

Declaration
public static byte[] ToNetworkByteOrder(this Guid guid)
Parameters
Type Name Description
System.Guid guid
Returns
Type Description
System.Byte[]

UnpackISO3CodeFromInt(Int32)

Unpacks an ISO code from int which was packed with PackISO3CodeToInt

Declaration
public static string UnpackISO3CodeFromInt(int iso)
Parameters
Type Name Description
System.Int32 iso
Returns
Type Description
System.String

WriteBEInt32(Byte[], Int32)

Writes an integer encoded as big endian to buffer at index 0

Declaration
public static void WriteBEInt32(this byte[] buf, int value)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 value

WriteBEInt32(Byte[], Int32, Int32)

Writes an integer encoded as big endian to buffer at the specified index

Declaration
public static void WriteBEInt32(this byte[] buf, int idx, int value)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 idx
System.Int32 value

WriteBEInt32(Stream, Int32)

Writes an integer encoded as big endian to the given stream

Declaration
public static void WriteBEInt32(this Stream s, int value)
Parameters
Type Name Description
System.IO.Stream s
System.Int32 value

WriteBEShort(Byte[], Int32, Int16)

Writes a short encoded as big endian to buffer at the specified index

Declaration
public static void WriteBEShort(this byte[] buf, int idx, short value)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 idx
System.Int16 value

WriteBEShort(Stream, Int16)

Writes a short encoded as big endian to the given stream

Declaration
public static void WriteBEShort(this Stream s, short value)
Parameters
Type Name Description
System.IO.Stream s
System.Int16 value

WriteBEUInt32(Byte[], Int32, UInt32)

Writes an unsigned integer encoded as big endian to buffer at the specified index

Declaration
public static void WriteBEUInt32(this byte[] buf, int idx, uint value)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 idx
System.UInt32 value

WriteBEUInt32(Byte[], UInt32)

Writes an unsigned integer encoded as big endian to buffer at index 0

Declaration
public static void WriteBEUInt32(this byte[] buf, uint value)
Parameters
Type Name Description
System.Byte[] buf
System.UInt32 value

WriteBEUInt64(Byte[], Int32, UInt64)

Writes an unsigned long integer encoded as big endian to buffer at the specified index

Declaration
public static void WriteBEUInt64(this byte[] buf, int idx, ulong value)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 idx
System.UInt64 value

WriteBEUInt64(Byte[], UInt64)

Writes an unsigned long integer encoded as big endian to buffer at the beginning

Declaration
public static void WriteBEUInt64(this byte[] buf, ulong value)
Parameters
Type Name Description
System.Byte[] buf
System.UInt64 value

WriteBEUInt64(Stream, UInt64)

Writes an unsigned long integer encoded as big endian to the given stream

Declaration
public static void WriteBEUInt64(this Stream s, ulong value)
Parameters
Type Name Description
System.IO.Stream s
System.UInt64 value

WriteBEUShort(Stream, UInt16)

Writes an ushort encoded as big endian to the given stream

Declaration
public static void WriteBEUShort(this Stream s, ushort value)
Parameters
Type Name Description
System.IO.Stream s
System.UInt16 value

WriteLEInt32(Byte[], Int32)

Writes an integer encoded as little endian to buffer at index 0

Declaration
public static void WriteLEInt32(this byte[] buf, int value)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 value

WriteLEInt32(Byte[], Int32, Int32)

Writes an integer encoded as little endian to buffer at the specified index

Declaration
public static void WriteLEInt32(this byte[] buf, int idx, int value)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 idx
System.Int32 value

WriteLEInt32(Stream, Int32)

Writes an integer encoded as little endian to the given stream

Declaration
public static void WriteLEInt32(this Stream s, int value)
Parameters
Type Name Description
System.IO.Stream s
System.Int32 value

WriteLEShort(Byte[], Int32, Int16)

Writes a short encoded as little endian to buffer at the specified index

Declaration
public static void WriteLEShort(this byte[] buf, int idx, short value)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 idx
System.Int16 value

WriteLEShort(Stream, Int16)

Writes a short encoded as little endian to the given stream

Declaration
public static void WriteLEShort(this Stream s, short value)
Parameters
Type Name Description
System.IO.Stream s
System.Int16 value

WriteLEUInt32(Byte[], Int32, UInt32)

Writes an unsigned integer encoded as little endian to buffer at the specified index

Declaration
public static void WriteLEUInt32(this byte[] buf, int idx, uint value)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 idx
System.UInt32 value

WriteLEUInt32(Byte[], UInt32)

Writes an unsigned integer encoded as little endian to buffer at index 0

Declaration
public static void WriteLEUInt32(this byte[] buf, uint value)
Parameters
Type Name Description
System.Byte[] buf
System.UInt32 value

WriteLEUInt64(Byte[], Int32, UInt64)

Writes an unsigned long integer encoded as little endian to buffer at the specified index

Declaration
public static void WriteLEUInt64(this byte[] buf, int idx, ulong value)
Parameters
Type Name Description
System.Byte[] buf
System.Int32 idx
System.UInt64 value

WriteLEUInt64(Byte[], UInt64)

Writes an unsigned long integer encoded as little endian to buffer at the beginning

Declaration
public static void WriteLEUInt64(this byte[] buf, ulong value)
Parameters
Type Name Description
System.Byte[] buf
System.UInt64 value

WriteLEUInt64(Stream, UInt64)

Writes an unsigned long integer encoded as little endian to the given stream

Declaration
public static void WriteLEUInt64(this Stream s, ulong value)
Parameters
Type Name Description
System.IO.Stream s
System.UInt64 value

WriteLEUShort(Stream, UInt16)

Writes an ushort encoded as little endian to the given stream

Declaration
public static void WriteLEUShort(this Stream s, ushort value)
Parameters
Type Name Description
System.IO.Stream s
System.UInt16 value
Back to top Copyright © 2006-2018 Agnicore Inc
Generated by DocFX