示例#1
0
        }         // equals()

        /// <summary>
        /// A routine for parsing the MIME type out of a String.
        /// </summary>
        /// <exception cref="NullPointerException"> if <code>rawdata</code> is null </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void parse(String rawdata) throws MimeTypeParseException
        private void Parse(String rawdata)
        {
            int slashIndex = rawdata.IndexOf('/');
            int semIndex   = rawdata.IndexOf(';');

            if ((slashIndex < 0) && (semIndex < 0))
            {
                //    neither character is present, so treat it
                //    as an error
                throw new MimeTypeParseException("Unable to find a sub type.");
            }
            else if ((slashIndex < 0) && (semIndex >= 0))
            {
                //    we have a ';' (and therefore a parameter list),
                //    but no '/' indicating a sub type is present
                throw new MimeTypeParseException("Unable to find a sub type.");
            }
            else if ((slashIndex >= 0) && (semIndex < 0))
            {
                //    we have a primary and sub type but no parameter list
                PrimaryType_Renamed = rawdata.Substring(0, slashIndex).Trim().ToLowerCase(Locale.ENGLISH);
                SubType_Renamed     = rawdata.Substring(slashIndex + 1).Trim().ToLowerCase(Locale.ENGLISH);
                Parameters_Renamed  = new MimeTypeParameterList();
            }
            else if (slashIndex < semIndex)
            {
                //    we have all three items in the proper sequence
                PrimaryType_Renamed = rawdata.Substring(0, slashIndex).Trim().ToLowerCase(Locale.ENGLISH);
                SubType_Renamed     = StringHelperClass.SubstringSpecial(rawdata, slashIndex + 1, semIndex).Trim().ToLowerCase(Locale.ENGLISH);
                Parameters_Renamed  = new MimeTypeParameterList(rawdata.Substring(semIndex));
            }
            else
            {
                //    we have a ';' lexically before a '/' which means we have a primary type
                //    & a parameter list but no sub type
                throw new MimeTypeParseException("Unable to find a sub type.");
            }

            //    now validate the primary and sub types

            //    check to see if primary is valid
            if (!IsValidToken(PrimaryType_Renamed))
            {
                throw new MimeTypeParseException("Primary type is invalid.");
            }

            //    check to see if sub is valid
            if (!IsValidToken(SubType_Renamed))
            {
                throw new MimeTypeParseException("Sub type is invalid.");
            }
        }
        /// <returns> a clone of this object </returns>

        public virtual Object Clone()
        {
            MimeTypeParameterList newObj = null;

            try
            {
                newObj = (MimeTypeParameterList)base.Clone();
            }
            catch (CloneNotSupportedException)
            {
            }
            newObj.Parameters = (Hashtable)Parameters.clone();
            return(newObj);
        }
        }         // hashCode()

        /// <summary>
        /// Two parameter lists are considered equal if they have exactly
        /// the same set of parameter names and associated values. The
        /// order of the parameters is not considered.
        /// </summary>
        public override bool Equals(Object thatObject)
        {
            //System.out.println("MimeTypeParameterList.equals("+this+","+thatObject+")");
            if (!(thatObject is MimeTypeParameterList))
            {
                return(false);
            }
            MimeTypeParameterList that = (MimeTypeParameterList)thatObject;

            if (this.Size() != that.Size())
            {
                return(false);
            }
            String name      = null;
            String thisValue = null;
            String thatValue = null;
//JAVA TO C# CONVERTER TODO TASK: There is no .NET Dictionary equivalent to the Java 'entrySet' method:
            Set <java.util.Map_Entry <String, String> >         entries  = Parameters.entrySet();
            IEnumerator <java.util.Map_Entry <String, String> > iterator = entries.Iterator();

            java.util.Map_Entry <String, String> entry = null;
            while (iterator.MoveNext())
            {
                entry     = iterator.Current;
                name      = entry.Key;
                thisValue = entry.Value;
                thatValue = that.Parameters[name];
                if ((thisValue == null) || (thatValue == null))
                {
                    // both null -> equal, only one null -> not equal
                    if (thisValue != thatValue)
                    {
                        return(false);
                    }
                }
                else if (!thisValue.Equals(thatValue))
                {
                    return(false);
                }
            }             // while iterator

            return(true);
        }         // equals()
示例#4
0
        /// <summary>
        /// Builds a <code>MimeType</code> with a pre-defined
        /// and valid (or empty) parameter list.
        /// </summary>
        /// <param name="primary"> the primary type of this <code>MimeType</code> </param>
        /// <param name="sub"> the subtype of this <code>MimeType</code> </param>
        /// <param name="mtpl"> the requested parameter list </param>
        /// <exception cref="NullPointerException"> if either <code>primary</code>,
        ///         <code>sub</code> or <code>mtpl</code> is null </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public MimeType(String primary, String sub, MimeTypeParameterList mtpl) throws MimeTypeParseException
        public MimeType(String primary, String sub, MimeTypeParameterList mtpl)
        {
            //    check to see if primary is valid
            if (IsValidToken(primary))
            {
                PrimaryType_Renamed = primary.ToLowerCase(Locale.ENGLISH);
            }
            else
            {
                throw new MimeTypeParseException("Primary type is invalid.");
            }

            //    check to see if sub is valid
            if (IsValidToken(sub))
            {
                SubType_Renamed = sub.ToLowerCase(Locale.ENGLISH);
            }
            else
            {
                throw new MimeTypeParseException("Sub type is invalid.");
            }

            Parameters_Renamed = (MimeTypeParameterList)mtpl.Clone();
        }