Click here to Skip to main content
15,885,278 members
Articles / Programming Languages / C#

Repair RealMedia Files

Rate me:
Please Sign up or sign in to vote.
4.50/5 (13 votes)
3 Jan 2007CPOL2 min read 71K   1.7K   32  
Check and fix errors, rebuild index chunks, cut real media files.
using System;
using System.Collections.Generic;
using System.Text;

namespace QiHe.CodeLib
{
    public class TextEncoding
    {
        /// <summary>
        /// check if all charaters in text are ASCII charater
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static bool FitsInASCIIEncoding(string text)
        {
            if(string.IsNullOrEmpty(text))return true;
            byte[] bytes = Encoding.UTF8.GetBytes(text);
            for (int i = 0; i < bytes.Length; i++)
            {
                if (bytes[i] > 127)
                {
                    return false;
                }
            }
            return true;
        }

        public static bool EncodingIsRight(Encoding encoding, byte[] data)
        {
            string text = encoding.GetString(data);
            byte[] bytes = encoding.GetBytes(text);
            if (Algorithm.ArrayEqual(bytes, data))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public static object SafeDecodeString(Encoding encoding, byte[] data)
        {
            string text = encoding.GetString(data);
            byte[] bytes = encoding.GetBytes(text);
            if (Algorithm.ArrayEqual(bytes, data))
            {
                return text;
            }
            else
            {
                return data;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect YunCheDa Hangzhou
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions