PATH Documentation > WebObjects

Table of Contents

NSMutableData


Inherits from:
NSData : Object
Implements:
Cloneable
java.io.Serializable
NSCoding
Package:
com.webobjects.foundation


Class Description


The NSMutableData class declares the programmatic interface to an object that contains modifiable data in the form of bytes. The data grows automatically if necessary.

Table 0-8 describes the NSMutableData methods that provide the basis for all NSMutableData's other methods; that is, all other methods are implemented in terms of these nine. If you create a subclass of NSMutableData, you need only ensure that these base methods work properly. Having done so, you can be sure that all your subclass's inherited methods operate properly.


Table 0-8 NSMutableData's Base API
Method Description
appendByte Appends a byte to the receiver.
appendBytes Appends the contents of a byte array to the receiver. The two-argument version is part of the base API.
bytesNoCopy Returns the internal byte array that contains the receiver's data. Inherited from NSData.
immutableBytes Returns an immutable byte array that contains a copy of the receiver's data.
immutableRange Returns an immutable copy of the NSRange object that specifies the receiver's length.
rangeNoCopy Returns the internal NSRange object that specifies the receiver's length. Inherited from NSData.
resetBytesInRange Resets to zero the receiver's bytes that fall within the specified range.
setData Replaces the receiver's contents with the specified NSData object.
setLength Extends or truncates a mutable data object to the specified length.

To modify the data, use the setData, appendByte, appendBytes, and appendData methods. If you want to set a range of bytes to zero, use the resetBytesInRange method. To change the length of the data, use the setLength and increaseLengthBy methods.




Interfaces Implemented


Cloneable
clone
java.io.Serializable
NSCoding
classForCoder
decodeObject
encodeWithCoder


Method Types


Constructors
NSMutableData
Modifying the data
appendByte
appendBytes
appendData
resetBytesInRange
setData
Modifying the range
increaseLengthBy
setLength
Accessing internal data directly
immutableBytes
immutableRange


Constructors



NSMutableData

public NSMutableData()

Creates an empty NSMutableData object.

public NSMutableData(NSData data)

Creates an NSMutableData object containing the contents of another data object data.

public NSMutableData(String string)

This constructor is deprecated. Use NSMutableData(string.getBytes()) instead.

public NSMutableData(byte[] bytes)

Creates a NSMutableData object with all the data in the byte array bytes.

public NSMutableData( byte[] bytes, NSRange range)

Creates an NSMutableData object with the bytes from the language array bytes that fall in the range specified by range.

public NSMutableData( byte[] bytes, NSRange range, boolean nocopy)

Creates an NSMutableData object with the bytes from the language array bytes that fall in the range specified by range. The noCopy parameter specifies whether or not a copy of bytes is made.

public NSMutableData(int capacity)

Creates an NSMutableData object prepared to store at least capacity bytes. If you know the upper bound on the size of your data, you can use this constructor to improve performance. As long as the data size does not exceed capacity bytes, the internal byte array will not be reallocated.

public NSMutableData(java.io.File file) throws java.io.IOException

This constructor is deprecated. Use NSMutableData(new FileInputStream(file),myChunkSize) instead.

public NSMutableData( java.io.InputStream inputStream, int chunkSize) throws java.io.IOException

Creates a data object with the data from the stream specified by inputStream. The chunkSize parameter specifies the size, in bytes, of the block that the input stream returns when it reads. For maximum performance, you should set the chunk size to the approximate size of the data. This constructor does not close the stream.

public NSMutableData(java.net.URL url) throws java.io.IOException

This constructor is deprecated. Use the following code instead:

    URLConnection connection = url.openConnection();
    connection.connect();
    NSMutableData myData = new NSMutableData(connection.getInputStream(),myChunkSize);




Instance Methods



appendByte

public void appendByte(byte byte)

Appends the specified byte to the receiver.

See Also: appendBytes, appendData



appendBytes

public void appendBytes(byte[] bytes[])

public void appendBytes( byte[] bytes, NSRange range)

Appends the contents of byte array bytes to the receiver. The two-argument method appends the bytes in bytes that fall within the range specified by range.

See Also: appendByte, appendData



appendData

public void appendData(NSData otherData)

Appends the contents of a data object otherData to the receiver.

See Also: appendByte, appendBytes



clone

public Object clone()

Returns a copy (an NSMutableData object) of the receiver.

immutableBytes

protected byte[] immutableBytes()

Returns an immutable copy of the byte array that contains the receiver's data.

immutableRange

protected NSRange immutableRange()

Returns an immutable copy of the NSRange object that contains the receiver's length.

increaseLengthBy

public void increaseLengthBy(int additionalLength)

Increases the length of the receiver by additionalLength. The additional bytes are all set to zero.

See Also: setLength



resetBytesInRange

public void resetBytesInRange(NSRange range)

Resets to zero the receiver's bytes that fall within the specified range. If the location of range isn't within the receiver's range of bytes, an IllegalArgumentException is thrown. The receiver is resized to accommodate the new bytes, if necessary.

setData

public void setData(NSData data)

Replaces the entire contents of the receiver with the contents of data.

See Also: setLength



setLength

public void setLength(int length)

Extends or truncates a mutable data object to the specified length. If the mutable data object is extended, the additional bytes are filled with zero.

See Also: increaseLengthBy, setData



© 2001 Apple Computer, Inc. (Last Published April 17, 2001)


Table of Contents