WebObjects 5.2

com.webobjects.foundation
Class NSMutableData

java.lang.Object
  |
  +--com.webobjects.foundation.NSData
        |
        +--com.webobjects.foundation.NSMutableData
All Implemented Interfaces:
Cloneable, NSCoding, Serializable

public class NSMutableData
extends NSData

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.

The following table 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.


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.

See Also:
NSData, appendByte(byte byte), appendBytes(byte[] bytes[]), appendBytes( byte[] bytes, NSRange range), NSData.bytesNoCopy(), immutableBytes(), immutableRange(), NSData.rangeNoCopy(), resetBytesInRange(NSRange range), setData(NSData data), setLength(int length), appendData(NSData otherData), increaseLengthBy(int additionalLength), Serialized Form

Inner classes inherited from class com.webobjects.foundation.NSCoding
NSCoding.Support
 
Fields inherited from class com.webobjects.foundation.NSData
EmptyData
 
Constructor Summary
NSMutableData()
          Creates an empty NSMutableData object.
NSMutableData(byte[] bytes)
          Creates an NSMutableData object with all the data in the byte array bytes.
NSMutableData(byte[] bytes, NSRange range)
          Creates an NSMutableData object with the bytes from the byte array bytes that fall in the range specified by range.
NSMutableData(byte[] bytes, NSRange range, boolean noCopy)
          Creates an NSMutableData object with the bytes from the byte array bytes that fall in the range specified by range.
NSMutableData(File file)
          Deprecated.  
NSMutableData(InputStream inputStream, int chunkSize)
          Creates a data object with the data from the stream specified by inputStream.
NSMutableData(int capacity)
          Creates an NSMutableData object prepared to store at least capacity bytes.
NSMutableData(NSData otherData)
          Creates an NSMutableData object containing the contents of another data object otherData.
NSMutableData(String value)
          Deprecated.  
NSMutableData(String value, String encoding)
          This constructor creates a new NSMutableData object from a String
NSMutableData(URL url)
          Deprecated.  
 
Method Summary
 void appendByte(byte singleByte)
          Appends the specified byte to the receiver.
 void appendBytes(byte[] bytes)
          Appends the specified byte array to the receiver.
 void appendBytes(byte[] bytes, NSRange range)
          Appends the contents of byte array bytes to the receiver.
 void appendData(NSData otherData)
          Appends the contents of a data object otherData to the receiver.
 Object clone()
          Returns an identical copy of the receiver.
protected  byte[] immutableBytes()
          Privitive method that returns the receiver's data.
protected  NSRange immutableRange()
          Privitive method that returns the receiver's range.
 void increaseLengthBy(int additionalLength)
          Increases the length of the receiver by additionalLength.
 void resetBytesInRange(NSRange range)
          Resets to zero the receiver's bytes that fall within the specified range.
 void setData(NSData otherData)
          Replaces the entire contents of the receiver with the contents of otherdata.
 void setLength(int length)
          Extends or truncates a mutable data object to the specified length.
 
Methods inherited from class com.webobjects.foundation.NSData
bytes, bytes, bytes, bytesNoCopy, bytesNoCopy, classForCoder, dataWithContentsOfFile, dataWithContentsOfFile, dataWithContentsOfMappedFile, decodeObject, encodeWithCoder, equals, hashCode, isEqualToData, length, rangeNoCopy, stream, subdataWithRange, toString, writeToFile, writeToStream, writeToURL
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NSMutableData

public NSMutableData()
Creates an empty NSMutableData object.

NSMutableData

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 his 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.

Parameters:
capacity - the upper bound on the size of the data

NSMutableData

public NSMutableData(byte[] bytes)
Creates an NSMutableData object with all the data in the byte array bytes.
Parameters:
bytes - input byte array

NSMutableData

public NSMutableData(byte[] bytes,
                     NSRange range)
Creates an NSMutableData object with the bytes from the byte array bytes that fall in the range specified by range.
Parameters:
bytes - input byte array
range - specifies the range that the bytes fall in

NSMutableData

public NSMutableData(byte[] bytes,
                     NSRange range,
                     boolean noCopy)
Creates an NSMutableData object with the bytes from the byte array bytes that fall in the range specified by range. The noCopy parameter specifies whether or not a copy of bytes is made.
Parameters:
bytes - input byte array
range - specifies the range that the bytes fall in
noCopy - specifies whether or not a copy of bytes is made

NSMutableData

public NSMutableData(NSData otherData)
Creates an NSMutableData object containing the contents of another data object otherData.
Parameters:
otherData - contents of another data object

NSMutableData

public NSMutableData(InputStream inputStream,
                     int chunkSize)
              throws 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.

Parameters:
inputStream - data object is created with the data from this
chunkSize - specifies the size of the block that the input stream returns when it reads
Throws:
java.lang.IOException -  

NSMutableData

public NSMutableData(File file)
              throws IOException
Deprecated.  

Use NSMutableData(new FileInputStream(file),myChunkSize) instead.
See Also:
NSMutableData(InputStream, int)

NSMutableData

public NSMutableData(URL url)
              throws IOException
Deprecated.  

Use the following code instead:
URLConnection connection = url.openConnection(); connection.connect(); NSMutableData myData = new NSMutableData(connection.getInputStream(),myChunkSize);
See Also:
NSMutableData(InputStream, int)

NSMutableData

public NSMutableData(String value)
Deprecated.  

Use NSMutableData(string.getBytes()) instead.
See Also:
NSMutableData(byte[])

NSMutableData

public NSMutableData(String value,
                     String encoding)
This constructor creates a new NSMutableData object from a String
Parameters:
value - The textual data to use
encoding - The encoding type used to create the bytes.
Method Detail

appendByte

public void appendByte(byte singleByte)
Appends the specified byte to the receiver.
Parameters:
singleByte - the specified byte
See Also:
appendBytes(byte[] bytes), appendBytes(byte[] bytes, NSRange range), appendData(NSData otherData)

appendBytes

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.
Parameters:
bytes - the contents of byte array
range - the range specified for the bytes
See Also:
appendByte(byte singleByte), appendData(NSData otherData)

appendBytes

public void appendBytes(byte[] bytes)
Appends the specified byte array to the receiver.
Parameters:
bytes - the specified byte array that is appended to the receiver
See Also:
appendByte(byte singleByte), appendData(NSData otherData)

appendData

public void appendData(NSData otherData)
Appends the contents of a data object otherData to the receiver.
Parameters:
otherData - a data object whose contents are appended to the receiver
See Also:
appendByte(byte byte), appendBytes(byte[] bytes)

clone

public Object clone()
Returns an identical copy of the receiver.
Overrides:
clone in class NSData
Returns:
a copy (an NSMutableData object) of the receiver

immutableBytes

protected byte[] immutableBytes()
Privitive method that returns the receiver's data.
Overrides:
immutableBytes in class NSData
Returns:
an immutable copy of the byte array that contains the receiver's data

immutableRange

protected NSRange immutableRange()
Privitive method that returns the receiver's range.
Overrides:
immutableRange in class NSData
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.
Parameters:
additionalLength - the length of the receiver is increased by this much
See Also:
setLength(int length)

resetBytesInRange

public void resetBytesInRange(NSRange range)
Resets to zero the receiver's bytes that fall within the specified range.

The receiver is resized to accommodate the new bytes, if necessary.

Parameters:
range - specifies the range that the bytes should fall in
Throws:
IllegalArgumentException - if the location of range isn't within the receiver's range of bytes.

setData

public void setData(NSData otherData)
Replaces the entire contents of the receiver with the contents of otherdata.
Parameters:
otherData - the entire contents of the receiver is replaced by this
See Also:
setLength(int length)

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.
Parameters:
length - mutable data object is extended or truncated to this value
See Also:
increaseLengthBy(int additionalLength), setData(NSData otherData)

Last updated Fri Feb 21 13:15:00 PST 2003.

Copyright © 2003 Apple Computer, Inc.