Class Binary

  • All Implemented Interfaces:
    java.io.Serializable, org.mozilla.javascript.ConstProperties, org.mozilla.javascript.debug.DebuggableObject, org.mozilla.javascript.Scriptable, org.mozilla.javascript.SymbolScriptable, org.mozilla.javascript.Wrapper

    public class Binary
    extends org.mozilla.javascript.ScriptableObject
    implements org.mozilla.javascript.Wrapper

    A wrapper around a Java byte array compliant to the Binary/ByteArray/ByteString classes defined in the Binary/B proposal. To register Binary, ByteArray and ByteString as a host objects in Rhino call the defineClass() function with this class as argument.

    defineClass(org.ringojs.wrappers.Binary);
    The JavaScript Binary class serves as common base class for ByteArray and ByteString and can't be instantiated. ByteArray implements a modifiable and resizable byte buffer, while ByteString implements an immutable byte sequence. The ByteArray and ByteString constructors can take several arguments. Have a look at the proposal for details. When passed to a Java method that expects a byte array, instances of thes class are automatically unwrapped.
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.mozilla.javascript.ScriptableObject

        org.mozilla.javascript.ScriptableObject.KeyComparator
    • Field Summary

      • Fields inherited from class org.mozilla.javascript.ScriptableObject

        CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
      • Fields inherited from interface org.mozilla.javascript.Scriptable

        NOT_FOUND
    • Constructor Summary

      Constructors 
      Constructor Description
      Binary()  
      Binary​(org.mozilla.javascript.Scriptable scope, org.ringojs.wrappers.Binary.Type type, byte[] bytes)  
      Binary​(org.mozilla.javascript.Scriptable scope, org.ringojs.wrappers.Binary.Type type, byte[] bytes, int offset, int length)  
      Binary​(org.mozilla.javascript.Scriptable scope, org.ringojs.wrappers.Binary.Type type, int length)  
      Binary​(org.ringojs.wrappers.Binary.Type type)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object byteAt​(java.lang.Object index)  
      java.lang.Object charAt​(java.lang.Object index)  
      java.lang.Object charCodeAt​(java.lang.Object index)  
      static java.lang.Object concat​(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] args, org.mozilla.javascript.Function func)  
      static java.lang.Object construct​(org.mozilla.javascript.Context cx, java.lang.Object[] args, org.mozilla.javascript.Function ctorObj, boolean inNewExpr)  
      void copy​(int srcStartIndex, int srcEndIndex, Binary target, java.lang.Object targetIndex)  
      java.lang.String decodeToString​(java.lang.Object charset)  
      protected void ensureLength​(int minLength)  
      static void finishInit​(org.mozilla.javascript.Scriptable scope, org.mozilla.javascript.FunctionObject ctor, org.mozilla.javascript.Scriptable prototype)  
      java.lang.Object get​(int index, org.mozilla.javascript.Scriptable start)  
      java.lang.Object get​(java.lang.Object index)  
      byte[] getBytes()  
      java.lang.String getClassName()  
      int getLength()  
      org.ringojs.wrappers.Binary.Type getType()  
      boolean has​(int index, org.mozilla.javascript.Scriptable start)  
      int indexOf​(java.lang.Object arg, java.lang.Object from, java.lang.Object to)  
      java.lang.Object jsunwrap()  
      int lastIndexOf​(java.lang.Object arg, java.lang.Object from, java.lang.Object to)  
      void put​(int index, org.mozilla.javascript.Scriptable start, java.lang.Object value)  
      void set​(java.lang.Object index, int value)  
      protected void setLength​(int newLength)  
      void setLength​(java.lang.Object length)  
      java.lang.Object slice​(java.lang.Object begin, java.lang.Object end)  
      java.lang.Object split​(java.lang.Object delim, java.lang.Object options)  
      java.lang.Object toArray​(java.lang.Object charset)  
      java.lang.Object toByteArray​(java.lang.Object sourceCharset, java.lang.Object targetCharset)  
      java.lang.Object toByteString​(java.lang.Object sourceCharset, java.lang.Object targetCharset)  
      java.lang.String toString()  
      java.lang.Object unwrap()
      Unwrap the object by returning the wrapped value.
      protected static Binary wrap​(org.ringojs.wrappers.Binary.Type type, byte[] bytes, org.mozilla.javascript.Scriptable scope, org.mozilla.javascript.Scriptable prototype)  
      • Methods inherited from class org.mozilla.javascript.ScriptableObject

        applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, equivalentValues, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasInstance, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, putProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setParentScope, setPrototype, size
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Binary

        public Binary()
      • Binary

        public Binary​(org.ringojs.wrappers.Binary.Type type)
      • Binary

        public Binary​(org.mozilla.javascript.Scriptable scope,
                      org.ringojs.wrappers.Binary.Type type,
                      int length)
      • Binary

        public Binary​(org.mozilla.javascript.Scriptable scope,
                      org.ringojs.wrappers.Binary.Type type,
                      byte[] bytes)
      • Binary

        public Binary​(org.mozilla.javascript.Scriptable scope,
                      org.ringojs.wrappers.Binary.Type type,
                      byte[] bytes,
                      int offset,
                      int length)
    • Method Detail

      • construct

        @JSConstructor
        public static java.lang.Object construct​(org.mozilla.javascript.Context cx,
                                                 java.lang.Object[] args,
                                                 org.mozilla.javascript.Function ctorObj,
                                                 boolean inNewExpr)
      • finishInit

        public static void finishInit​(org.mozilla.javascript.Scriptable scope,
                                      org.mozilla.javascript.FunctionObject ctor,
                                      org.mozilla.javascript.Scriptable prototype)
                               throws java.lang.NoSuchMethodException
        Throws:
        java.lang.NoSuchMethodException
      • getType

        public org.ringojs.wrappers.Binary.Type getType()
      • get

        public java.lang.Object get​(int index,
                                    org.mozilla.javascript.Scriptable start)
        Specified by:
        get in interface org.mozilla.javascript.Scriptable
        Overrides:
        get in class org.mozilla.javascript.ScriptableObject
      • has

        public boolean has​(int index,
                           org.mozilla.javascript.Scriptable start)
        Specified by:
        has in interface org.mozilla.javascript.Scriptable
        Overrides:
        has in class org.mozilla.javascript.ScriptableObject
      • put

        public void put​(int index,
                        org.mozilla.javascript.Scriptable start,
                        java.lang.Object value)
        Specified by:
        put in interface org.mozilla.javascript.Scriptable
        Overrides:
        put in class org.mozilla.javascript.ScriptableObject
      • getLength

        @JSGetter
        public int getLength()
      • setLength

        @JSSetter
        public void setLength​(java.lang.Object length)
      • setLength

        protected void setLength​(int newLength)
      • get

        @JSFunction
        public java.lang.Object get​(java.lang.Object index)
        Overrides:
        get in class org.mozilla.javascript.ScriptableObject
      • charCodeAt

        @JSFunction
        public java.lang.Object charCodeAt​(java.lang.Object index)
      • byteAt

        @JSFunction
        public java.lang.Object byteAt​(java.lang.Object index)
      • charAt

        @JSFunction
        public java.lang.Object charAt​(java.lang.Object index)
      • set

        @JSFunction
        public void set​(java.lang.Object index,
                        int value)
      • toByteArray

        @JSFunction
        public java.lang.Object toByteArray​(java.lang.Object sourceCharset,
                                            java.lang.Object targetCharset)
                                     throws java.io.UnsupportedEncodingException
        Throws:
        java.io.UnsupportedEncodingException
      • toByteString

        @JSFunction
        public java.lang.Object toByteString​(java.lang.Object sourceCharset,
                                             java.lang.Object targetCharset)
                                      throws java.io.UnsupportedEncodingException
        Throws:
        java.io.UnsupportedEncodingException
      • copy

        @JSFunction
        public void copy​(int srcStartIndex,
                         int srcEndIndex,
                         Binary target,
                         java.lang.Object targetIndex)
      • toArray

        @JSFunction
        public java.lang.Object toArray​(java.lang.Object charset)
                                 throws java.io.UnsupportedEncodingException
        Throws:
        java.io.UnsupportedEncodingException
      • toString

        @JSFunction
        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • slice

        @JSFunction
        public java.lang.Object slice​(java.lang.Object begin,
                                      java.lang.Object end)
      • concat

        @JSFunction
        public static java.lang.Object concat​(org.mozilla.javascript.Context cx,
                                              org.mozilla.javascript.Scriptable thisObj,
                                              java.lang.Object[] args,
                                              org.mozilla.javascript.Function func)
      • decodeToString

        @JSFunction
        public java.lang.String decodeToString​(java.lang.Object charset)
      • indexOf

        @JSFunction
        public int indexOf​(java.lang.Object arg,
                           java.lang.Object from,
                           java.lang.Object to)
      • lastIndexOf

        @JSFunction
        public int lastIndexOf​(java.lang.Object arg,
                               java.lang.Object from,
                               java.lang.Object to)
      • split

        @JSFunction
        public java.lang.Object split​(java.lang.Object delim,
                                      java.lang.Object options)
      • wrap

        protected static Binary wrap​(org.ringojs.wrappers.Binary.Type type,
                                     byte[] bytes,
                                     org.mozilla.javascript.Scriptable scope,
                                     org.mozilla.javascript.Scriptable prototype)
      • jsunwrap

        @JSFunction("unwrap")
        public java.lang.Object jsunwrap()
      • unwrap

        public java.lang.Object unwrap()
        Unwrap the object by returning the wrapped value.
        Specified by:
        unwrap in interface org.mozilla.javascript.Wrapper
        Returns:
        a wrapped value
      • getBytes

        public byte[] getBytes()
      • getClassName

        public java.lang.String getClassName()
        Specified by:
        getClassName in interface org.mozilla.javascript.Scriptable
        Specified by:
        getClassName in class org.mozilla.javascript.ScriptableObject
      • ensureLength

        protected void ensureLength​(int minLength)