1 jls.loader.provide('jls.net.http.HttpMultiPartBody');
  2 
  3 jls.loader.require('jls.net.SelectionHandlerSequence');
  4 jls.loader.require('jls.net.BufferSelectionHandler');
  5 jls.loader.require('jls.lang.ByteBuffer');
  6 
  7 jls.net.http.HttpMultiPartBody = jls.lang.Class.create(jls.net.SelectionHandlerSequence, /** @lends jls.net.http.HttpMultiPartBody.prototype */
  8 {
  9     /**
 10      * Creates a multipart HTTP content.
 11      *
 12      * @param {String} boundary The boundary.
 13      * @constructs
 14 	 * @augments jls.net.SelectionHandlerSequence
 15 	 * @class This class is a selection handler for multipart HTTP content.
 16      */
 17     initialize : function($super, boundary) {
 18         if (typeof boundary != 'string') {
 19             throw new jls.lang.Exception('Invalid boundary');
 20         }
 21         $super();
 22         this._boundary = boundary;
 23         this._boundaryContent = null;
 24     },
 25     /**
 26      * Adds a content.
 27      * 
 28      * @param {jls.net.SelectionHandler} content The content to add.
 29      */
 30     addContent : function(content) {
 31         if (this._contents.length > 0) {
 32             // prepare boundary
 33             if (this._boundaryContent == null) {
 34                 var buffer = jls.lang.ByteBuffer.allocate(this._boundary.length);
 35                 buffer.putString(this._boundary);
 36                 buffer.flip();
 37                 this._boundaryContent = new jls.net.BufferSelectionHandler(buffer);
 38             }
 39             this.addSelectionHandler(this._boundaryContent);
 40         }
 41         this.addSelectionHandler(content);
 42         return this;
 43     },
 44     /**
 45      * Gets a content.
 46      * 
 47      * @param {Number} content The content index.
 48      * @returns {jls.net.SelectionHandler} The content.
 49      */
 50     getContent : function($super, index) {
 51         return this.getSelectionHandler(index * 2);
 52     },
 53     onRead : function(output) {
 54         throw new jls.lang.Exception('Not available');
 55     }
 56 });
 57