DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (fbecf6c8a86f)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is [Open Source Virtual Machine.].
 *
 * The Initial Developer of the Original Code is
 * Adobe System Incorporated.
 * Portions created by the Initial Developer are Copyright (C) 2004-2006
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   Adobe AS3 Team
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

package flash.utils
{

//
// ByteArray
//


/**
 * The ByteArray class makes it possible to work with
 * binary data in ActionScript in an efficient manner.
 *
 * <p><b><i>Note:</i></b> The ByteArray class are for advanced ActionScript developers who need to access 
 * data on the byte level.</p>
 *
 * <p>Its in-memory representation is a packed array of bytes, but an instance of the ByteArray
 * class can be manipulated with the standard the ActionScript array access operators: 
 * <code>[</code> and <code>]</code>.</p>
 *
 * <p>It also can be read/written to as an in-memory file, using
 * methods similar to <code>URLStream</code> and <code>Socket</code>.</p>
 * 
 * <p>In addition, zlib compression/decompression is supported, as
 * well as AMF object serialization.</p>
 *
 * <p>Possible uses of the <code>ByteArray</code> class include the following:
 *
 * <ul>
 *
 *	 <li>Creating a custom protocol to connect to a server.</li>
 *
 *	 <li>Writing your own URLEncoder/URLDecoder.</li>
 *
 *	 <li>Writing your own AMF/Remoting packet.</li>
 *
 *	 <li>Optimizing the size of your data by using data types.</li>
 *
 * </ul>
 * </p>
 *
 * @playerversion Flash 8.0
 * @langversion 3.0
 * @helpid
 * @refpath 
 * @keyword ByteArray
 */
[native(cls="::avmshell::ByteArrayClass", instance="::avmshell::ByteArrayObject", methods="auto")]
public class ByteArray
{
	public native static function readFile(filename:String):ByteArray;
	public native function writeFile(filename:String):void;

	/**
	 * Reads <code>length</code> bytes of data from the byte stream.
	 * The bytes are read into the <code>ByteArray</code> object specified
	 * by <code>bytes</code>, starting <code>offset</code> bytes into
	 * the <code>ByteAray</code>.
	 *
	 * @param bytes The <code>ByteArray</code> object to read
	 *              data into.
	 * @param offset The offset into <code>bytes</code> at which data
	 *               read should begin.  Defaults to 0.
	 * @param length The number of bytes to read.  The default value
	 *               of 0 will cause all available data to be read.
	 * @throws EOFError There is not sufficient data available
	 * to read.
	 * @throws IOError An I/O error occurred on the byte stream,
	 * or the byte stream is not open.
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.readBytes, readBytes
	 */	
	public native function readBytes(bytes:ByteArray,
									 offset:uint=0,
									 length:uint=0):void;


	/**
	 * Writes a sequence of <code>length</code> bytes from the
	 * specified byte array, <code>bytes</code>,
	 * starting <code>offset</code>(zero-based index) bytes
	 * into the array.
	 *
	 * <p><code>offset</code> and <code>length</code> are optional
	 * parameters. If <code>length</code> is omitted, the default
	 * length of 0 means to write the entire buffer starting at
	 * <code>offset</code>.
	 *
	 * If <code>offset</code> is also omitted, the entire buffer is
	 * written. </p> <p>If <code>offset</code> or <code>length</code>
	 * is out of range, they will be clamped to the beginning and end
	 * of the <code>bytes</code> array.</p>
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.writeBytes, writeBytes
	 */	
	public native function writeBytes(bytes:ByteArray,
									  offset:uint=0,
									  length:uint=0):void;

	/**
	 * Writes a boolean to the byte stream. A single byte is written,
	 * either 1 for <code>true</code> or 0 for <code>false</code>.
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.writeBoolean, writeBoolean
	 */	
	public native function writeBoolean(value:Boolean):void;
	
	/**
	 * Writes a byte to the byte stream. 
	 * <p>The low 8 bits of the
	 * parameter are used. The high 24 bits are ignored. </p>
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.writeByte, writeByte
	 */	
	public native function writeByte(value:int):void;

	/**
	 * Writes a 16-bit integer to the byte stream. The bytes written
	 * are:
	 *
	 * <pre><code>(v &gt;&gt; 8) &amp; 0xff v &amp; 0xff</code></pre>
	 *
	 * <p>The low 16 bits of the parameter are used. The high 16 bits
	 * are ignored.</p>
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.writeShort, writeShort
	 */	
	public native function writeShort(value:int):void;

	/**
	 * Writes a 32-bit signed integer to the byte stream.
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.writeInt, writeInt
	 */	
	public native function writeInt(value:int):void;
	
	/**
	 * Writes a 32-bit unsigned integer to the byte stream.
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.writeUnsignedInt, writeUnsignedInt
	 */	
	public native function writeUnsignedInt(value:uint):void;

	/**
	 * Writes an IEEE 754 single-precision floating point number to the byte stream. 
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.writeFloat, writeFloat
	 */	
	public native function writeFloat(value:Number):void;

	/**
	 * Writes an IEEE 754 double-precision floating point number to the byte stream. 
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.writeDouble, writeDouble
	 */	
	public native function writeDouble(value:Number):void;

	/**
	 * Writes a 16-bit unsigned integer to the byte stream, specifying
	 * the length of the UTF-8 string that follows in bytes. Then,
	 * writes the UTF-8 string to the byte stream.
	 *
	 * <p>First, the total number of bytes needed to represent all the
	 * characters of <code>s</code> is calculated.</p>
	 *
	 * @throws RangeError If the length is larger than
	 * <code>65535</code>.
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.writeUTF, writeUTF
	 */	
	public native function writeUTF(value:String):void;

	/**
	 * Writes a UTF-8 string to the byte stream. Similar to writeUTF,
	 * but does not prefix the string with a 16-bit length word.
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.writeUTFBytes, writeUTFBytes
	 */	
	public native function writeUTFBytes(value:String):void;
	
	/**
	 * Reads a boolean from the byte stream. A single byte is read,
	 * and <code>true</code> is returned if the byte is non-zero,
	 * <code>false</code> otherwise.
	 * 
	 * @throws EOFError There is not sufficient data available
	 * to read.
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.readBoolean, readBoolean
	 */	
	public native function readBoolean():Boolean;

	/**
	 * Reads a signed byte from the byte stream.
	 * <p>The returned value is in the range -128...127.</p>
	 * @throws EOFError There is not sufficient data available
	 * to read.
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.readByte, readByte
	 */	
	public native function readByte():int;

	/**
	 * Reads an unsigned byte from the byte stream.
	 * 
	 * <p>The returned value is in the range 0...255. </p>	
	 *
	 * @throws EOFError There is not sufficient data available
	 * to read.
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.readUnsignedByte, readUnsignedByte
	 */	
	public native function readUnsignedByte():uint;

	/**
	 * Reads a signed 16-bit integer from the byte stream.
	 *
	 * <p>The returned value is in the range -32768...32767.</p>
	 *
	 * @throws EOFError There is not sufficient data available
	 * to read.
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.readShort, readShort
	 */	
	public native function readShort():int;


	/**
	 * Reads an unsigned 16-bit integer from the byte stream.
	 *
	 * <p>The returned value is in the range 0...65535. </p>
	 * @throws EOFError There is not sufficient data available
	 * to read.
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.readUnsignedShort, readUnsignedShort
	 */	
	public native function readUnsignedShort():uint;
	
	/**
	 * Reads a signed 32-bit integer from the byte stream.
	 *
     * <p>The returned value is in the range -2147483648...2147483647.</p>
	 *
	 * @throws EOFError There is not sufficient data available
	 * to read.
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.readInt, readInt
	 */	
	public native function readInt():int;

	/**
	 * Reads an unsigned 32-bit integer from the byte stream.
	 *
	 * <p>The returned value is in the range 0...4294967295. </p>
	 *
	 * @throws EOFError There is not sufficient data available
	 * to read.
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.readUnsignedInt, readUnsignedInt
	 */	
	public native function readUnsignedInt():uint;

	/**
	 * Reads an IEEE 754 single-precision floating point number from the byte stream.
	 *
	 * @throws EOFError There is not sufficient data available
	 * to read.
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.readFloat, readFloat
	 */	
	public native function readFloat():Number;

	/**
	 * Reads an IEEE 754 double-precision floating point number from the byte stream.
	 *
	 * @throws EOFError There is not sufficient data available
	 * to read.
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.readDouble, readDouble
	 */	
	public native function readDouble():Number;

	/**
	 * Reads a UTF-8 string from the byte stream.  The string
	 * is assumed to be prefixed with an unsigned short indicating
	 * the length in bytes.
	 *
	 * <p>This method is similar to the <code>readUTF</code>
	 * method in the Java <code>DataInput</code> interface.</p>
	 *
	 * @throws EOFError There is not sufficient data available
	 * to read.
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.readUTF, readUTF
	 */	
	public native function readUTF():String;

	/**
	 * Reads a sequence of <code>length</code> UTF-8
	 * bytes from the byte stream, and returns a string.
	 *
	 * @throws EOFError There is not sufficient data available
	 * to read.
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.readUTFBytes, readUTFBytes
	 */	
	public native function readUTFBytes(length:uint):String;

	/**
	 * The length of the <code>ByteArray</code>, in bytes.
	 *
	 * <p>If the length is set to a larger value than the
	 * current length, the empty space is filled with zeros.</p>
	 *
	 * <p>If the length is set to a smaller value than the
	 * current length, the array is truncated.</p>
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.length, length
	 */	
	public native function get length():uint;
	public native function set length(value:uint):void;

	/**
	* Compresses the byte array using zlib compression.
	* The entire byte array is compressed.
	*
	* @see #uncompress
	*
	* @playerversion Flash 8.0
	* @langversion 3.0
	* @helpid
	* @refpath
	* @keyword ByteArray, ByteArray.compress, compress
	*/
	private native function zlib_compress():void;
	public function compress():void { zlib_compress(); }

	/**
	* Uncompresses the byte array.  The byte array
	* must have been previously compressed with the
	* <code>compress</code> method.
	*
	* @see #compress
	*
	* @playerversion Flash 8.0
	* @langversion 3.0
	* @helpid
	* @refpath
	* @keyword ByteArray, ByteArray.uncompress, uncompress
	*/
	private native function zlib_uncompress():void;
	public function uncompress():void { zlib_uncompress(); }


	/**
	 * Converts the ByteArray to a String.
	 *
	 * @return The String representation of the ByteArray.
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.toString, toString
	 */	
	private native function _toString():String;
	public function toString():String { return _toString(); }
	
	/**
	 * The number of bytes of data available for reading
	 * from the current position in the byte array to the
	 * end of the array.
	 *
	 * <p>User code must access the <code>bytesAvailable</code> property to ensure
	 * that sufficient data is available before trying to read
	 * it with one of the <code>read</code> methods.</p>
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword available, bytes, position 
	 */	
	public native function get bytesAvailable():uint;

	/**
	 * Returns the current position, in bytes, of the file
	 * pointer into the <code>ByteArray</code>.  This is the
	 * point at which the next call to a <code>read</code>
	 * method will start reading, or a <code>write</code>
	 * method will start writing.
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.getFilePointer, 
	 */	
	public native function get position():uint;

	/**
	 * Moves the file pointer to <code>offset</code> bytes
	 * into the byte array.  The next call to a <code>read</code>
	 * or <code>write</code> method will start operating
	 * at this point.
	 *
	 * @playerversion Flash 8.0
	 * @langversion 3.0
	 * @helpid
	 * @refpath 
	 * @keyword ByteArray, ByteArray.seek, 
	 */	
	public native function set position(offset:uint):void;

	public native function get endian():String;
	public native function set endian(type:String):void;
};



/*
 * [ggrossman 04/07/05] API SCRUB
 *
 * - _ByteArray_ now implements the _DataInput_ and _DataOutput_
 *   interfaces, as described in the Low Level Data specification.
 *
 * - Method _available()_ changed to accessor _bytesAvailable_
 * - Method _getFilePointer()_ changed to accessor _position_
 * - Method _seek()_ changed to accessor _position_
 * - Method _readUnsignedByte()_ now returns type _uint_
 * - Method _readUnsignedShort()_ now returns type _uint_
 *
 * - Renamed _flash_transient_ namespace to _transient_ and
 *   put in _flash.net_ package
 *
 * - Moved _registerClass_ to the _flash.net_ package.
 *
 * - Moved the _ObjectEncoding_ class from _flash.util_ to the
 *   _flash.net_ package.
 *
 * - [srahim 04/05/05] Doc scrub
 */

}