
var Binary = exports.Binary = function(bytes) {
    this.bytes = bytes;
};

Binary.prototype.getLength = function() {
    return this.bytes.length;
};

Binary.prototype.toString = function(encoding) {
    var jstr = encoding ?
               new java.lang.String(this.bytes, encoding) :
               new java.lang.String(this.bytes);
    return String(jstr);
};

String.prototype.toBinary = function(encoding) {
    var bytes = encoding ?
                new java.lang.String(this).getBytes(encoding) :
                new java.lang.String(this).getBytes();
    return new Binary(bytes);
};

Binary.prototype.forEach = function(block) {
    block(this);
};

Binary.prototype.toBinary = function() {
    return this;
};



var asJavaObject = require('helma/system').asJavaObject;

var Binary = exports.Binary = function(bytes) {
    this.bytes = bytes;
};

Binary.prototype.getLength = function() {
    return this.bytes.length;
};

Binary.prototype.toString = function(encoding) {
    var jstr = encoding ?
               new java.lang.String(this.bytes, encoding) :
               new java.lang.String(this.bytes);
    return String(jstr);
};

String.prototype.toBinary = function(encoding) {
    var bytes = encoding ?
                asJavaObject(this.toString()).getBytes(encoding) :
                asJavaObject(this.toString()).getBytes();
    return new Binary(bytes);
};

Binary.prototype.forEach = function(block) {
    block(this);
};

Binary.prototype.toBinary = function() {
    return this;
};


Use helma/system.asJavaObject() to prevent allocating new java.lang.Strings in String.toBinary().
Use helma/system.asJavaObject() to prevent allocating new java.lang.Strings in String.toBinary().

git-svn-id: fac99be8204c57f0935f741ea919b5bf0077cdf6@9703 688a9155-6ab5-4160-a077-9df41f55a9e9
