示例#1
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");
                 * }*/
            }
示例#2
0
 // default implementation is empty
 /// <summary>
 /// Checks if the given argument is legal as this encoder's replacement byte
 /// array.
 /// </summary>
 /// <remarks>
 /// Checks if the given argument is legal as this encoder's replacement byte
 /// array.
 /// The given byte array is legal if and only if it can be decode into
 /// sixteen bits Unicode characters.
 /// This method can be overridden for performance improvement.
 /// </remarks>
 /// <param name="replacement">the given byte array to be checked.</param>
 /// <returns>
 /// true if the the given argument is legal as this encoder's
 /// replacement byte array.
 /// </returns>
 public virtual bool isLegalReplacement(byte[] replacement_1)
 {
     if (decoder == null)
     {
         decoder = cs.newDecoder();
         decoder.onMalformedInput(java.nio.charset.CodingErrorAction.REPORT);
         decoder.onUnmappableCharacter(java.nio.charset.CodingErrorAction.REPORT);
     }
     java.nio.ByteBuffer @in  = java.nio.ByteBuffer.wrap(replacement_1);
     java.nio.CharBuffer @out = java.nio.CharBuffer.allocate((int)(replacement_1.Length
                                                                   * decoder.maxCharsPerByte()));
     java.nio.charset.CoderResult result = decoder.decode(@in, @out, true);
     return(!result.isError());
 }
示例#3
0
		// default implementation is empty
		/// <summary>
		/// Checks if the given argument is legal as this encoder's replacement byte
		/// array.
		/// </summary>
		/// <remarks>
		/// Checks if the given argument is legal as this encoder's replacement byte
		/// array.
		/// The given byte array is legal if and only if it can be decode into
		/// sixteen bits Unicode characters.
		/// This method can be overridden for performance improvement.
		/// </remarks>
		/// <param name="replacement">the given byte array to be checked.</param>
		/// <returns>
		/// true if the the given argument is legal as this encoder's
		/// replacement byte array.
		/// </returns>
		public virtual bool isLegalReplacement(byte[] replacement_1)
		{
			if (decoder == null)
			{
				decoder = cs.newDecoder();
				decoder.onMalformedInput(java.nio.charset.CodingErrorAction.REPORT);
				decoder.onUnmappableCharacter(java.nio.charset.CodingErrorAction.REPORT);
			}
			java.nio.ByteBuffer @in = java.nio.ByteBuffer.wrap(replacement_1);
			java.nio.CharBuffer @out = java.nio.CharBuffer.allocate((int)(replacement_1.Length
				 * decoder.maxCharsPerByte()));
			java.nio.charset.CoderResult result = decoder.decode(@in, @out, true);
			return !result.isError();
		}