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
        public static java.lang.Throwable TranslateException(java.lang.Throwable exc)
        {
            System.Exception newExc = null;

            if (exc is system.Exception)
            {
                return(exc);
            }

            var dlg = (ExceptionTranslator)exceptionMap.get(
                ((java.lang.Object)(object) exc).getClass());

            if (dlg != null)
            {
                newExc = dlg(exc);
            }

            if (newExc == null)
            {
                if (exc is java.lang.NullPointerException)
                {
                    newExc = new System.NullReferenceException();
                }

                /*if (exc is java.lang.IllegalArgumentException)
                 *  newExc = new System.ArgumentException();*/

                if (exc is java.lang.ArithmeticException && exc.getMessage() == "/ by zero")
                {
                    newExc = new System.DivideByZeroException(); // "Attempted to divide by zero."
                }
                // also: IndexOutOfRangeException.  define in Array?  not necessarily.
                // fixme:  move these to specialized exceptionMap ?

                if (newExc == null)
                {
                    return(exc);
                }

                /*if (newExc == null)
                 * {
                 *  // any throwable not deriving from system.Exception is assumed
                 *  // to be coming from the JVM or java code.  If it was not mapped
                 *  // to some known .NET exception, wrap it in an ExternalException
                 *  // newExc = new Exception("Java exception: " + exc.GetType());
                 *  // fixme System.Runtime.InteropServices.ExternalException ???
                 *  Console.WriteLine("Created New Exception: ");
                 *  Console.WriteLine(newExc);
                 *  Console.WriteLine("Continuing...");
                 * }*/
            }

            java.lang.Throwable newThrowable = (java.lang.Throwable)newExc;
            newThrowable.setStackTrace(exc.getStackTrace());
            return(newThrowable);
        }
Beispiel #3
0
        public static int SizeOf(System.Type t)
        {
            var j = ((system.RuntimeType)t).JavaClassForArray();

            return((j == java.lang.Boolean.TYPE || j == java.lang.Byte.TYPE)   ? 1
                   : (j == java.lang.Character.TYPE || j == java.lang.Short.TYPE)  ? 2
                   : (j == java.lang.Integer.TYPE || j == java.lang.Float.TYPE)  ? 4
                   : (j == java.lang.Long.TYPE || j == java.lang.Double.TYPE) ? 8
                   : MarshalTypes.get(t) is int sz                                 ? sz
                   : throw new System.PlatformNotSupportedException());
        }