示例#1
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);
		}
示例#2
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);
 }
示例#3
0
		/// <summary>
		/// Constructs a new InputStreamReader on the InputStream
		/// <code>in</code>
		/// and
		/// CharsetDecoder
		/// <code>dec</code>
		/// .
		/// </summary>
		/// <param name="in">the source InputStream from which to read characters.</param>
		/// <param name="dec">the CharsetDecoder used by the character conversion.</param>
		public InputStreamReader(java.io.InputStream @in, java.nio.charset.CharsetDecoder
			 dec) : base(@in)
		{
			dec.averageCharsPerByte();
			this.@in = @in;
			decoder = dec;
			bytes.limit(0);
		}
示例#4
0
 /// <summary>
 /// Constructs a new InputStreamReader on the InputStream
 /// <code>in</code>
 /// and
 /// CharsetDecoder
 /// <code>dec</code>
 /// .
 /// </summary>
 /// <param name="in">the source InputStream from which to read characters.</param>
 /// <param name="dec">the CharsetDecoder used by the character conversion.</param>
 public InputStreamReader(java.io.InputStream @in, java.nio.charset.CharsetDecoder
                          dec) : base(@in)
 {
     dec.averageCharsPerByte();
     this.@in = @in;
     decoder  = dec;
     bytes.limit(0);
 }
示例#5
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");
                 * }*/
            }
示例#6
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());
 }
示例#7
0
 public override void close()
 {
     lock (@lock)
     {
         if (decoder != null)
         {
             decoder.reset();
         }
         decoder = null;
         if (@in != null)
         {
             @in.close();
             @in = null;
         }
     }
 }
示例#8
0
		public override void close()
		{
			lock (@lock)
			{
				if (decoder != null)
				{
					decoder.reset();
				}
				decoder = null;
				if (@in != null)
				{
					@in.close();
					@in = null;
				}
			}
		}
示例#9
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();
		}