Beispiel #1
0
        private object PerThreadJavaCoder(int index)
        {
            var elem = perThreadJavaCodersMap.get(this);

            if (elem == null)
            {
                var elemNew = new java.util.concurrent.atomic.AtomicReferenceArray(2);
                elem = perThreadJavaCodersMap.putIfAbsent(this, elemNew) ?? elemNew;
            }
            var coders = (java.util.concurrent.atomic.AtomicReferenceArray)elem;

            elem = coders.get(index);
            if (elem == null)
            {
                var elemNew = (index == 0)
                            ? (object)JavaCharset.newDecoder()
                              .onUnmappableCharacter(java.nio.charset.CodingErrorAction.REPLACE)
                              .onMalformedInput(java.nio.charset.CodingErrorAction.REPLACE)
                            : (object)JavaCharset.newEncoder()
                              .onUnmappableCharacter(java.nio.charset.CodingErrorAction.REPLACE)
                              .onMalformedInput(java.nio.charset.CodingErrorAction.REPLACE);
                elem = coders.getAndSet(index, elemNew) ?? elemNew;
            }
            return(elem);
        }
Beispiel #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);
 }
Beispiel #3
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");
                 * }*/
            }
Beispiel #4
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());
 }