Example #1
0
        public static string get(java.nio.charset.Charset charset)
        {
            string modernName = charset.name();
            string result     = historicalNames.get(modernName);

            return((result != null) ? result : modernName);
        }
Example #2
0
 internal CharsetEncoder(java.nio.charset.Charset cs, float averageBytesPerChar_1,
                         float maxBytesPerChar_1, byte[] replacement_1, bool trusted)
 {
     // internal status indicates encode(CharBuffer) operation is finished
     // decoder instance for this encoder's charset, used for replacement value checking
     if (averageBytesPerChar_1 <= 0 || maxBytesPerChar_1 <= 0)
     {
         throw new System.ArgumentException("averageBytesPerChar and maxBytesPerChar must both be positive"
                                            );
     }
     if (averageBytesPerChar_1 > maxBytesPerChar_1)
     {
         throw new System.ArgumentException("averageBytesPerChar is greater than maxBytesPerChar"
                                            );
     }
     this.cs = cs;
     this._averageBytesPerChar = averageBytesPerChar_1;
     this._maxBytesPerChar     = maxBytesPerChar_1;
     status = INIT;
     _malformedInputAction      = java.nio.charset.CodingErrorAction.REPORT;
     _unmappableCharacterAction = java.nio.charset.CodingErrorAction.REPORT;
     if (trusted)
     {
         // The RI enforces unnecessary restrictions on the replacement bytes. We trust ICU to
         // know what it's doing. Doing so lets us support ICU's EUC-JP, SCSU, and Shift_JIS.
         this.replacementBytes = replacement_1;
     }
     else
     {
         replaceWith(replacement_1);
     }
 }
Example #3
0
 public string encode(string s, java.nio.charset.Charset charset)
 {
     // Guess a bit larger for encoded form
     java.lang.StringBuilder builder = new java.lang.StringBuilder(s.Length + 16);
     appendEncoded(builder, s, charset, false);
     return(builder.ToString());
 }
Example #4
0
 /// <summary>
 /// Constructs a new InputStreamReader on the InputStream
 /// <code>in</code>
 /// and
 /// Charset
 /// <code>charset</code>
 /// .
 /// </summary>
 /// <param name="in">the source InputStream from which to read characters.</param>
 /// <param name="charset">the Charset that defines the character converter</param>
 public InputStreamReader(java.io.InputStream @in, java.nio.charset.Charset charset
                          ) : base(@in)
 {
     this.@in = @in;
     decoder  = charset.newDecoder().onMalformedInput(java.nio.charset.CodingErrorAction
                                                      .REPLACE).onUnmappableCharacter(java.nio.charset.CodingErrorAction.REPLACE);
     bytes.limit(0);
 }
Example #5
0
 private static void appendHex(java.lang.StringBuilder builder, string s, java.nio.charset.Charset
                               charset)
 {
     foreach (byte b in XobotOS.Runtime.Util.GetBytesForString(s, charset))
     {
         appendHex(builder, b);
     }
 }
Example #6
0
 /// <summary>
 /// Constructs a new OutputStreamWriter using
 /// <code>out</code>
 /// as the target
 /// stream to write converted characters to and
 /// <code>cs</code>
 /// as the character
 /// encoding.
 /// </summary>
 /// <param name="out">the target stream to write converted bytes to.</param>
 /// <param name="cs">
 /// the
 /// <code>Charset</code>
 /// that specifies the character encoding.
 /// </param>
 public OutputStreamWriter(java.io.OutputStream @out, java.nio.charset.Charset cs)
     : base(@out)
 {
     this.@out = @out;
     encoder   = cs.newEncoder();
     encoder.onMalformedInput(java.nio.charset.CodingErrorAction.REPLACE);
     encoder.onUnmappableCharacter(java.nio.charset.CodingErrorAction.REPLACE);
 }
Example #7
0
        /// <summary>
        /// Encodes
        /// <code>s</code>
        /// and appends the result to
        /// <code>builder</code>
        /// .
        /// </summary>
        /// <param name="isPartiallyEncoded">
        /// true to fix input that has already been
        /// partially or fully encoded. For example, input of "hello%20world" is
        /// unchanged with isPartiallyEncoded=true but would be double-escaped to
        /// "hello%2520world" otherwise.
        /// </param>
        private void appendEncoded(java.lang.StringBuilder builder, string s, java.nio.charset.Charset
                                   charset, bool isPartiallyEncoded)
        {
            if (s == null)
            {
                throw new System.ArgumentNullException();
            }
            int escapeStart = -1;

            {
                for (int i = 0; i < s.Length; i++)
                {
                    char c = s[i];
                    if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') ||
                        isRetained(c) || (c == '%' && isPartiallyEncoded))
                    {
                        if (escapeStart != -1)
                        {
                            appendHex(builder, Sharpen.StringHelper.Substring(s, escapeStart, i), charset);
                            escapeStart = -1;
                        }
                        if (c == '%' && isPartiallyEncoded)
                        {
                            // this is an encoded 3-character sequence like "%20"
                            builder.append(java.lang.CharSequenceProxy.Wrap(s), i, i + 3);
                            i += 2;
                        }
                        else
                        {
                            if (c == ' ')
                            {
                                builder.append('+');
                            }
                            else
                            {
                                builder.append(c);
                            }
                        }
                    }
                    else
                    {
                        if (escapeStart == -1)
                        {
                            escapeStart = i;
                        }
                    }
                }
            }
            if (escapeStart != -1)
            {
                appendHex(builder, Sharpen.StringHelper.Substring(s, escapeStart, s.Length), charset
                          );
            }
        }
Example #8
0
 public override bool contains(java.nio.charset.Charset arg0)
 {
     global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
     if (!IsClrObject)
     {
         return(@__env.CallBooleanMethod(this.JvmHandle, global::java.nio.charset.Charset_._contains14694, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0)));
     }
     else
     {
         return(@__env.CallNonVirtualBooleanMethod(this.JvmHandle, global::java.nio.charset.Charset_.staticClass, global::java.nio.charset.Charset_._contains14694, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0)));
     }
 }
Example #9
0
 public virtual int compareTo(java.nio.charset.Charset arg0)
 {
     global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
     if (!IsClrObject)
     {
         return(@__env.CallIntMethod(this.JvmHandle, global::java.nio.charset.Charset._compareTo14678, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0)));
     }
     else
     {
         return(@__env.CallNonVirtualIntMethod(this.JvmHandle, global::java.nio.charset.Charset.staticClass, global::java.nio.charset.Charset._compareTo14678, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0)));
     }
 }
Example #10
0
            public Reader resolve(URI absoluteURI, string encoding, Configuration config)
            {
                if (encoding == null)
                {
                    encodings.TryGetValue(new Uri(absoluteURI.ToString()), out encoding);
                }
                if (encoding == null)
                {
                    encoding = "utf-8";
                }
                try
                {
                    // The following is necessary to ensure that encoding errors are not recovered.
                    java.nio.charset.Charset        charset = java.nio.charset.Charset.forName(encoding);
                    java.nio.charset.CharsetDecoder decoder = charset.newDecoder();
                    decoder = decoder.onMalformedInput(java.nio.charset.CodingErrorAction.REPORT);
                    decoder = decoder.onUnmappableCharacter(java.nio.charset.CodingErrorAction.REPORT);
                    Object obj;
                    resources.TryGetValue(new Uri(absoluteURI.ToString()), out obj);
                    if (obj is java.io.File)
                    {
                        return(new BufferedReader(new InputStreamReader(new FileInputStream((java.io.File)obj), decoder)));
                    }
                    else
                    {
                        resources.TryGetValue(new Uri(absoluteURI.ToString()), out obj);
                        URL resource = (URL)obj;
                        if (resource == null)
                        {
                            resource = absoluteURI.toURL();
                            //throw new XPathException("Unparsed text resource " + absoluteURI + " not registered in catalog", "FOUT1170");
                        }
                        java.io.InputStream in1 = resource.openConnection().getInputStream();
                        return(new BufferedReader(new InputStreamReader(in1, decoder)));
                    }
                    //   return new InputStreamReader(new FileInputStream(resources.get(absoluteURI)), encoding);
                }
                catch (java.lang.Exception ioe)
                {
                    throw new Exception(ioe.getMessage() + "FOUT1170");
                }

                /*catch (IllegalCharsetNameException icne)
                 * {
                 *  throw new XPathException("Invalid encoding name: " + encoding, "FOUT1190");
                 * }
                 * catch (UnsupportedCharsetException uce)
                 * {
                 *  throw new XPathException("Invalid encoding name: " + encoding, "FOUT1190");
                 * }*/
            }
Example #11
0
 /// <param name="convertPlus">true to convert '+' to ' '.</param>
 public static string decode(string s, bool convertPlus, java.nio.charset.Charset
                             charset)
 {
     if (s.IndexOf('%') == -1 && (!convertPlus || s.IndexOf('+') == -1))
     {
         return(s);
     }
     java.lang.StringBuilder       result = new java.lang.StringBuilder(s.Length);
     java.io.ByteArrayOutputStream @out   = new java.io.ByteArrayOutputStream();
     {
         for (int i = 0; i < s.Length;)
         {
             char c = s[i];
             if (c == '%')
             {
                 do
                 {
                     if (i + 2 >= s.Length)
                     {
                         throw new System.ArgumentException("Incomplete % sequence at: " + i);
                     }
                     int d1 = hexToInt(s[i + 1]);
                     int d2 = hexToInt(s[i + 2]);
                     if (d1 == -1 || d2 == -1)
                     {
                         throw new System.ArgumentException("Invalid % sequence " + Sharpen.StringHelper.Substring
                                                                (s, i, i + 3) + " at " + i);
                     }
                     @out.write(unchecked ((byte)((d1 << 4) + d2)));
                     i += 3;
                 }while (i < s.Length && s[i] == '%');
                 result.append(XobotOS.Runtime.Util.GetStringForBytes(@out.toByteArray(), charset)
                               );
                 @out.reset();
             }
             else
             {
                 if (convertPlus && c == '+')
                 {
                     c = ' ';
                 }
                 result.append(c);
                 i++;
             }
         }
     }
     return(result.ToString());
 }
Example #12
0
 /// <summary>
 /// Constructs a new <code>CharsetDecoder</code> using the given
 /// <code>Charset</code>, average number and maximum number of characters
 /// created by this decoder for one input byte, and the default replacement
 /// string "\uFFFD".
 /// </summary>
 /// <remarks>
 /// Constructs a new <code>CharsetDecoder</code> using the given
 /// <code>Charset</code>, average number and maximum number of characters
 /// created by this decoder for one input byte, and the default replacement
 /// string "\uFFFD".
 /// </remarks>
 /// <param name="charset">the <code>Charset</code> to be used by this decoder.</param>
 /// <param name="averageCharsPerByte">
 /// the average number of characters created by this decoder for
 /// one input byte, must be positive.
 /// </param>
 /// <param name="maxCharsPerByte">
 /// the maximum number of characters created by this decoder for
 /// one input byte, must be positive.
 /// </param>
 /// <exception cref="System.ArgumentException">
 /// if <code>averageCharsPerByte</code> or
 /// <code>maxCharsPerByte</code> is negative.
 /// </exception>
 protected internal CharsetDecoder(java.nio.charset.Charset charset_1, float averageCharsPerByte_1
                                   , float maxCharsPerByte_1)
 {
     if (averageCharsPerByte_1 <= 0 || maxCharsPerByte_1 <= 0)
     {
         throw new System.ArgumentException("averageCharsPerByte and maxCharsPerByte must be positive"
                                            );
     }
     if (averageCharsPerByte_1 > maxCharsPerByte_1)
     {
         throw new System.ArgumentException("averageCharsPerByte is greater than maxCharsPerByte"
                                            );
     }
     this._averageCharsPerByte = averageCharsPerByte_1;
     this._maxCharsPerByte     = maxCharsPerByte_1;
     cs     = charset_1;
     status = INIT;
     _malformedInputAction      = java.nio.charset.CodingErrorAction.REPORT;
     _unmappableCharacterAction = java.nio.charset.CodingErrorAction.REPORT;
     replacementChars           = "\ufffd";
 }
Example #13
0
// Generating method code for getContentAsString
        public virtual string GetContentAsString(java.nio.charset.Charset encoding, bool ignoreUtf8Bom)
        {
            return(WObj.getContentAsString(encoding, ignoreUtf8Bom));
        }
Example #14
0
 public abstract bool contains(java.nio.charset.Charset arg0);
Example #15
0
 /// <summary>
 /// Constructs a new <code>CharsetEncoder</code> using the given
 /// <code>Charset</code>, replacement byte array, average number and
 /// maximum number of bytes created by this encoder for one input character.
 /// </summary>
 /// <remarks>
 /// Constructs a new <code>CharsetEncoder</code> using the given
 /// <code>Charset</code>, replacement byte array, average number and
 /// maximum number of bytes created by this encoder for one input character.
 /// </remarks>
 /// <param name="cs">the <code>Charset</code> to be used by this encoder.</param>
 /// <param name="averageBytesPerChar">
 /// average number of bytes created by this encoder for one single
 /// input character, must be positive.
 /// </param>
 /// <param name="maxBytesPerChar">
 /// maximum number of bytes which can be created by this encoder
 /// for one single input character, must be positive.
 /// </param>
 /// <param name="replacement">
 /// the replacement byte array, cannot be null or empty, its
 /// length cannot be larger than <code>maxBytesPerChar</code>,
 /// and must be a legal replacement, which can be justified by
 /// <see cref="isLegalReplacement(byte[])">isLegalReplacement</see>
 /// .
 /// </param>
 /// <exception cref="System.ArgumentException">if any parameters are invalid.</exception>
 protected internal CharsetEncoder(java.nio.charset.Charset cs, float averageBytesPerChar_1
                                   , float maxBytesPerChar_1, byte[] replacement_1) : this(cs, averageBytesPerChar_1
                                                                                           , maxBytesPerChar_1, replacement_1, false)
 {
 }
Example #16
0
 /// <summary>
 /// Constructs a new
 /// <code>CharsetEncoder</code>
 /// using the given parameters and
 /// the replacement byte array
 /// <code></code>
 ///
 /// (byte) '?' }}.
 /// </summary>
 protected internal CharsetEncoder(java.nio.charset.Charset cs, float averageBytesPerChar_1
                                   , float maxBytesPerChar_1) : this(cs, averageBytesPerChar_1, maxBytesPerChar_1,
                                                                     new byte[] { unchecked ((byte)(byte)('?')) })
 {
 }
Example #17
0
 /// <summary>
 /// Executes the SQL commands in a script file against a database.
 /// </summary>
 /// <param name="url">the database URL</param>
 /// <param name="user">the user name</param>
 /// <param name="password">the password</param>
 /// <param name="fileName">the script file</param>
 /// <param name="charsetName">the character set name or null for UTF-8</param>
 /// <param name="continueOnError">if execution should be continued if an error occurs</param>
 public static void RunScript(String url, String user, String password, String fileName, java.nio.charset.Charset charsetName, bool continueOnError)
 => org.h2.tools.RunScript.execute(url, user, password, fileName, charsetName, continueOnError);
Example #18
0
 public StringWebResponse(string content, java.nio.charset.Charset charset, java.net.URL originatingURL)
     : this(new com.gargoylesoftware.htmlunit.StringWebResponse(content, charset, originatingURL))
 {
 }
Example #19
0
 protected CharsetDecoder(java.nio.charset.Charset arg0, float arg1, float arg2)  : base(global::MonoJavaBridge.JNIEnv.ThreadEnv)
 {
     global::MonoJavaBridge.JNIEnv         @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
     global::MonoJavaBridge.JniLocalHandle handle = @__env.NewObject(java.nio.charset.CharsetDecoder.staticClass, global::java.nio.charset.CharsetDecoder._CharsetDecoder14719, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg2));
     Init(@__env, handle);
 }
Example #20
0
// Generating method code for getContentAsString
        public virtual string GetContentAsString(java.nio.charset.Charset encoding)
        {
            return(WObj.getContentAsString(encoding));
        }
Example #21
0
 public KeyDataPair(string key, java.io.File file, string fileName, string mimeType, java.nio.charset.Charset charset)
     : this(new com.gargoylesoftware.htmlunit.util.KeyDataPair(key, file, fileName, mimeType, charset))
 {
 }
Example #22
0
		/// <summary>
		/// Constructs a new <code>CharsetDecoder</code> using the given
		/// <code>Charset</code>, average number and maximum number of characters
		/// created by this decoder for one input byte, and the default replacement
		/// string "\uFFFD".
		/// </summary>
		/// <remarks>
		/// Constructs a new <code>CharsetDecoder</code> using the given
		/// <code>Charset</code>, average number and maximum number of characters
		/// created by this decoder for one input byte, and the default replacement
		/// string "\uFFFD".
		/// </remarks>
		/// <param name="charset">the <code>Charset</code> to be used by this decoder.</param>
		/// <param name="averageCharsPerByte">
		/// the average number of characters created by this decoder for
		/// one input byte, must be positive.
		/// </param>
		/// <param name="maxCharsPerByte">
		/// the maximum number of characters created by this decoder for
		/// one input byte, must be positive.
		/// </param>
		/// <exception cref="System.ArgumentException">
		/// if <code>averageCharsPerByte</code> or
		/// <code>maxCharsPerByte</code> is negative.
		/// </exception>
		protected internal CharsetDecoder(java.nio.charset.Charset charset_1, float averageCharsPerByte_1
			, float maxCharsPerByte_1)
		{
			if (averageCharsPerByte_1 <= 0 || maxCharsPerByte_1 <= 0)
			{
				throw new System.ArgumentException("averageCharsPerByte and maxCharsPerByte must be positive"
					);
			}
			if (averageCharsPerByte_1 > maxCharsPerByte_1)
			{
				throw new System.ArgumentException("averageCharsPerByte is greater than maxCharsPerByte"
					);
			}
			this._averageCharsPerByte = averageCharsPerByte_1;
			this._maxCharsPerByte = maxCharsPerByte_1;
			cs = charset_1;
			status = INIT;
			_malformedInputAction = java.nio.charset.CodingErrorAction.REPORT;
			_unmappableCharacterAction = java.nio.charset.CodingErrorAction.REPORT;
			replacementChars = "\ufffd";
		}
Example #23
0
		internal CharsetEncoder(java.nio.charset.Charset cs, float averageBytesPerChar_1, 
			float maxBytesPerChar_1, byte[] replacement_1, bool trusted)
		{
			// internal status indicates encode(CharBuffer) operation is finished
			// decoder instance for this encoder's charset, used for replacement value checking
			if (averageBytesPerChar_1 <= 0 || maxBytesPerChar_1 <= 0)
			{
				throw new System.ArgumentException("averageBytesPerChar and maxBytesPerChar must both be positive"
					);
			}
			if (averageBytesPerChar_1 > maxBytesPerChar_1)
			{
				throw new System.ArgumentException("averageBytesPerChar is greater than maxBytesPerChar"
					);
			}
			this.cs = cs;
			this._averageBytesPerChar = averageBytesPerChar_1;
			this._maxBytesPerChar = maxBytesPerChar_1;
			status = INIT;
			_malformedInputAction = java.nio.charset.CodingErrorAction.REPORT;
			_unmappableCharacterAction = java.nio.charset.CodingErrorAction.REPORT;
			if (trusted)
			{
				// The RI enforces unnecessary restrictions on the replacement bytes. We trust ICU to
				// know what it's doing. Doing so lets us support ICU's EUC-JP, SCSU, and Shift_JIS.
				this.replacementBytes = replacement_1;
			}
			else
			{
				replaceWith(replacement_1);
			}
		}