1 jls.loader.provide('jls.io.cs.CharDecoder');
  2 
  3 jls.loader.require('jls.lang.CharBuffer');
  4 
  5 jls.io.cs.CharDecoder = jls.lang.Class.create( /** @lends jls.io.cs.CharDecoder.prototype */
  6 {
  7     /**
  8      * Creates a character decoder.
  9      * 
 10      * @constructs
 11      * @class This class represents a character decoder.
 12      */
 13     initialize : function(charset) {
 14         this._charset = charset;
 15         this._averBytes = 1.0;
 16         this._replacement = '?'.charCodeAt(0);
 17     },
 18     /**
 19      * Decodes byte buffer and returns the character buffer.
 20      *
 21      * @param {jls.lang.Buffer} input The buffer to decode.
 22      * @returns {jls.lang.CharBuffer} The decoded character buffer.
 23      */
 24     decode : function(input, buffer) {
 25     	var length = Math.round(input.remaining() / this._averBytes);
 26     	var output = buffer || jls.lang.CharBuffer.allocate(length + 1);
 27     	while (input.remaining() > 0) {
 28     		var b = input.getByte();
 29     		if (b > 127) {
 30     			b = this._replacement;
 31     		}
 32     		output.putChar(b);
 33     	}
 34         return output;
 35     }
 36 });
 37 
 38