CharsetFilter Class

A charset filter for incrementally converting text streams from one charset encoding to another.

Definition

Namespace: MimeKit.IO.Filters
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public class CharsetFilter : MimeFilterBase
Inheritance
Object    MimeFilterBase    CharsetFilter

Remarks

Incrementally converts text from one charset encoding to another.

Example

C#
                    public static string ConvertToUtf8 (Stream input, string charset)
{
    using (var memory = new MemoryStream ()) {
        using (var filtered = new FilteredStream (memory)) {
            // Convert the text from the source charset to UTF-8 while it is being copied.
            filtered.Add (new CharsetFilter (charset, "utf-8"));

            // Normalize the line endings to Unix-style LF line endings as well.
            filtered.Add (new Dos2UnixFilter ());

            input.CopyTo (filtered);
            filtered.Flush ();
        }

        return Encoding.UTF8.GetString (memory.GetBuffer (), 0, (int) memory.Length);
    }
}
                  

Constructors

CharsetFilter(Encoding, Encoding) Initialize a new instance of the CharsetFilter class.
CharsetFilter(Int32, Int32) Initialize a new instance of the CharsetFilter class.
CharsetFilter(String, String) Initialize a new instance of the CharsetFilter class.

Properties

OutputBuffer Get the output buffer.
(Inherited from MimeFilterBase)
SourceEncoding Get the source encoding.
TargetEncoding Get the target encoding.

Methods

EnsureOutputSize Ensure that the output buffer is greater than or equal to the specified size.
(Inherited from MimeFilterBase)
Equals Determines whether the specified object is equal to the current object.
(Inherited from Object)
Filter(Byte, Int32, Int32, Int32, Int32) Filter the specified input.
(Inherited from MimeFilterBase)
Filter(Byte, Int32, Int32, Int32, Int32, Boolean) Filter the specified input.
(Overrides MimeFilterBaseFilter(Byte, Int32, Int32, Int32, Int32, Boolean))
Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
Flush Filter the specified input, flushing all internally buffered data to the output.
(Inherited from MimeFilterBase)
GetHashCode Serves as the default hash function.
(Inherited from Object)
GetType Gets the Type of the current instance.
(Inherited from Object)
MemberwiseClone Creates a shallow copy of the current Object.
(Inherited from Object)
Reset Reset the filter.
(Overrides MimeFilterBaseReset)
SaveRemainingInput Save the remaining input for the next round of processing.
(Inherited from MimeFilterBase)
ToString Returns a string that represents the current object.
(Inherited from Object)

See Also