diff options
Diffstat (limited to 'projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSMutableData.java')
| -rw-r--r-- | projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSMutableData.java | 208 |
1 files changed, 93 insertions, 115 deletions
diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSMutableData.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSMutableData.java index c677ea7..c24e04d 100644 --- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSMutableData.java +++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSMutableData.java @@ -19,95 +19,82 @@ License along with this library; if not, see http://www.gnu.org package net.wotonomy.foundation; /** -* A pure java implementation of NSMutableData, which -* is basically an editable wrapper for a byte array. -* -* @author michael@mpowers.net -* @author $Author: cgruber $ -* @version $Revision: 892 $ -*/ -public class NSMutableData - extends NSData -{ - /** - * Default constructor creates a zero-data object. - */ - public NSMutableData () - { - super(); - } - - /** - * Creates an object containing the contents of the specified URL. - */ - public NSMutableData (java.net.URL aURL) - { - super( aURL ); - } - - /** - * Creates an object containing a copy of the contents of the - * specified NSData object. - */ - public NSMutableData (NSData aData) - { - super( aData ); - } - - /** - * Creates an object containing the specified number of bytes - * initialized to all zeroes. - */ - public NSMutableData (int size) - { - super( new byte[size] ); // inits to zeroes - } + * A pure java implementation of NSMutableData, which is basically an editable + * wrapper for a byte array. + * + * @author michael@mpowers.net + * @author $Author: cgruber $ + * @version $Revision: 892 $ + */ +public class NSMutableData extends NSData { + /** + * Default constructor creates a zero-data object. + */ + public NSMutableData() { + super(); + } + /** + * Creates an object containing the contents of the specified URL. + */ + public NSMutableData(java.net.URL aURL) { + super(aURL); + } /** - * Sets the length of the data to the specified length. - * If shorter, the data is truncated. If longer, the extra - * bytes are initialized to zeroes. - */ - public void setLength (int length) - { - byte[] data = new byte[ length ]; // inits to zeroes - int limit = length; - if (limit > bytes.length) - limit = bytes.length; - for ( int i = 0; i < limit; i++ ) - { - data[i] = this.bytes[ i ]; - } - this.bytes = data; - } + * Creates an object containing a copy of the contents of the specified NSData + * object. + */ + public NSMutableData(NSData aData) { + super(aData); + } /** - * Appends the specified data to the end of this data. - */ - public void appendData (NSData aData) - { - int len = aData.length(); - byte[] data = new byte[ bytes.length + len ]; - - int i; - for ( i = 0; i < bytes.length; i++ ) - { - data[i] = bytes[i]; - } - - byte[] src = aData.bytes( 0, len ); - for ( int j = 0; j < len; j++ ) - { - data[i+j] = src[j]; - } - - bytes = data; - } + * Creates an object containing the specified number of bytes initialized to all + * zeroes. + */ + public NSMutableData(int size) { + super(new byte[size]); // inits to zeroes + } + + /** + * Sets the length of the data to the specified length. If shorter, the data is + * truncated. If longer, the extra bytes are initialized to zeroes. + */ + public void setLength(int length) { + byte[] data = new byte[length]; // inits to zeroes + int limit = length; + if (limit > bytes.length) + limit = bytes.length; + for (int i = 0; i < limit; i++) { + data[i] = this.bytes[i]; + } + this.bytes = data; + } + + /** + * Appends the specified data to the end of this data. + */ + public void appendData(NSData aData) { + int len = aData.length(); + byte[] data = new byte[bytes.length + len]; + + int i; + for (i = 0; i < bytes.length; i++) { + data[i] = bytes[i]; + } + + byte[] src = aData.bytes(0, len); + for (int j = 0; j < len; j++) { + data[i + j] = src[j]; + } + + bytes = data; + } public void appendByte(byte b) { setLength(bytes.length + 1); - bytes[bytes.length-1] = b; + bytes[bytes.length - 1] = b; } public void appendBytes(byte[] b) { @@ -118,50 +105,41 @@ public class NSMutableData } /** - * Increases the size of the byte array by the specified amount. - */ - public void increaseLengthBy (int increment) - { - setLength( length() + increment ); - } + * Increases the size of the byte array by the specified amount. + */ + public void increaseLengthBy(int increment) { + setLength(length() + increment); + } /** - * Sets the bytes in the array within the specified range to zero. - */ - public void resetBytesInRange (NSRange aRange) - { - int loc = aRange.location(); - int max = aRange.maxRange(); - for ( int i = loc; i < max; i++ ) - { - bytes[i] = 0; - } - } + * Sets the bytes in the array within the specified range to zero. + */ + public void resetBytesInRange(NSRange aRange) { + int loc = aRange.location(); + int max = aRange.maxRange(); + for (int i = loc; i < max; i++) { + bytes[i] = 0; + } + } /** - * Copies the data in the specified object to this object, - * completely replacing the previous contents. - */ - public void setData (NSData aData) - { - bytes = aData.bytes( 0, aData.length() ); - } + * Copies the data in the specified object to this object, completely replacing + * the previous contents. + */ + public void setData(NSData aData) { + bytes = aData.bytes(0, aData.length()); + } } /* - * $Log$ - * Revision 1.1 2006/02/16 12:47:16 cgruber - * Check in all sources in eclipse-friendly maven-enabled packages. + * $Log$ Revision 1.1 2006/02/16 12:47:16 cgruber Check in all sources in + * eclipse-friendly maven-enabled packages. * - * Revision 1.2 2003/08/06 23:57:13 chochos - * appendByte(), appendBytes() + * Revision 1.2 2003/08/06 23:57:13 chochos appendByte(), appendBytes() * - * Revision 1.1.1.1 2000/12/21 15:47:34 mpowers - * Contributing wotonomy. + * Revision 1.1.1.1 2000/12/21 15:47:34 mpowers Contributing wotonomy. * - * Revision 1.3 2000/12/20 16:25:38 michael - * Added log to all files. + * Revision 1.3 2000/12/20 16:25:38 michael Added log to all files. * * */ - |
