|
WebObjects 5.4.2 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.webobjects.foundation.NSData
public class NSData
NSData and its subclass NSMutableData provide data objects, object-oriented wrappers for byte buffers. Data objects let byte arrays take on the behavior of Foundation objects. NSData creates static data objects, and NSMutableData creates dynamic data objects.
Data objects can wrap data of any size. The object contains no information about the data itself (such as its type); the responsibility for deciding how to use the data lies with the client. In particular, it will not handle byte-order swapping when distributed between big-endian and little-endian machines.
The following table describes the NSData methods that provide the basis for all NSData's other methods; that is, all other methods are implemented in terms of these four. If you create a subclass of NSData, you need to ensure that only these base methods work properly. Having done so, you can be sure that all the subclass's inherited methods operate properly.
| Method | Description |
bytesNoCopy |
Returns the internal byte array that contains the receiver's data. Used by mutable subclasses of NSData. |
immutableBytes |
Returns an immutable byte array that contains the receiver's data. |
immutableRange |
Returns an immutable NSRange object that specifies the receiver's length. |
rangeNoCopy |
Returns the internal NSRange object that specifies the receiver's length. Used by mutable subclasses of NSData. |
To extract a data object that contains a subset of the bytes in another data object, use subdataWithRange. To determine if two data objects are equal, use isEqualToData, which does a byte-for-byte comparison.
writeToStream lets you write the contents of a data object to a stream (a java.io.OutputStream object).
NSData.bytesNoCopy(),
NSData.immutableBytes(),
NSData.immutableRange(),
NSData.rangeNoCopy(),
NSData.isEqualToData(NSData otherData),
NSData.subdataWithRange(NSRange range),
NSData.writeToStream(java.io.OutputStream outputStream),
Serialized Form| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface com.webobjects.foundation.NSCoding |
|---|
NSCoding.Support |
| Field Summary | |
|---|---|
static NSData |
EmptyData
An empty data object, which can be shared to save memory. |
| Constructor Summary | |
|---|---|
NSData()
Creates an empty data object. |
|
NSData(byte[] bytes)
Creates a data object with all the data in the byte array bytes. |
|
NSData(byte[] bytes,
int offset,
int count)
Creates a data object with the bytes from the byte array bytes that fall in the range specified by offset and count. |
|
NSData(byte[] bytes,
NSRange range)
Creates a data object with the bytes from the byte array bytes that fall in the range specified by range. |
|
NSData(byte[] bytes,
NSRange range,
boolean noCopy)
Creates a data object with the bytes from the byte array bytes that fall in the range specified by range. |
|
NSData(File file)
Deprecated. |
|
NSData(InputStream inputStream,
int chunkSize)
Creates a data object with the data from the stream specified by inputStream. |
|
NSData(NSData otherData)
Creates a data object containing the contents of another data object, otherData. |
|
NSData(String value)
Deprecated. |
|
NSData(String value,
String encoding)
This constructor creates a new NSData object from a String |
|
NSData(URL url)
Creates a new NSData from the contents of url. |
|
| Method Summary | |
|---|---|
byte[] |
bytes()
Returns a byte array containing all of the receiver's contents |
byte[] |
bytes(int offset,
int length)
Returns a byte array containing all of the receiver's contents |
byte[] |
bytes(NSRange range)
Returns a byte array containing all of the receiver's contents |
protected byte[] |
bytesNoCopy()
Due to the internal implementation of NSData, the array returned by this primitive method may contain bytes that are not actually a part of the receiver's data. |
byte[] |
bytesNoCopy(NSMutableRange range)
The receiver's actual data is composed of the returned array's bytes that lie within range. |
Class |
classForCoder()
Conformance to NSCoding. |
Object |
clone()
Since NSData objects are immutable, there's no need to make an actual clone. |
static NSData |
dataWithContentsOfFile(File file)
Deprecated. |
static NSData |
dataWithContentsOfFile(String path)
Deprecated. |
static NSData |
dataWithContentsOfMappedFile(File file)
Deprecated. |
static Object |
decodeObject(NSCoder coder)
Creates an NSData from the data in coder. |
void |
encodeWithCoder(NSCoder coder)
Encodes the receiver using coder. |
boolean |
equals(Object object)
Compares the receiving data object to object. |
int |
hashCode()
Provide an appropriate hash code useful for storing the receiver in a hash-based data structure. |
protected byte[] |
immutableBytes()
Privitive method that returns the receiver's data. |
protected NSRange |
immutableRange()
Privitive method that returns the receiver's range. |
boolean |
isEqualToData(NSData otherData)
Compares the receiving data object to otherData. |
int |
length()
Returns the number of bytes contained by the receiver. |
protected NSRange |
rangeNoCopy()
Primitive method used by mutable subclasses of NSData. |
ByteArrayInputStream |
stream()
Returns a stream containing the receiver's data |
NSData |
subdataWithRange(NSRange range)
Creates a data object containing a copy of the receiver's bytes that fall within the range specified by range. |
String |
toString()
Returns a string representation of the receiver. |
boolean |
writeToFile(String path)
Deprecated. |
void |
writeToStream(OutputStream stream)
Writes the bytes in the receiver contents to the stream. |
boolean |
writeToURL(URL url,
boolean atomically)
Deprecated. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final NSData EmptyData
| Constructor Detail |
|---|
public NSData()
public NSData(byte[] bytes)
bytes.
bytes - input byte array
public NSData(byte[] bytes,
NSRange range)
bytes that fall in the range specified by range.
bytes - input byte arrayrange - subrange of data within array
public NSData(byte[] bytes,
int offset,
int count)
bytes that fall in the range specified by offset and count.
bytes - input byte arrayoffset - offset of start of data within byte arraycount - length of data starting at offset
public NSData(byte[] bytes,
NSRange range,
boolean noCopy)
bytes that fall in the range specified by range. The noCopy parameter specifies whether or not a copy of bytes is made.
bytes - input byte arrayrange - range of data in byte arraynoCopy - specifies whether or not a copy of bytes is madepublic NSData(NSData otherData)
otherData.
otherData - data object to be copied
public NSData(InputStream inputStream,
int chunkSize)
throws IOException
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 reads the stream until it detects an end of file or encounters an exception, but it does not close the stream.
inputStream - data object with the data from the stream specified by inputStreamchunkSize - specifies the size, in bytes, of the block that the input stream returns
IOException
@Deprecated
public NSData(File file)
throws IOException
IOException
IllegalArgumentExceptionNSData.NSData(InputStream inputStream, int chunkSize)
public NSData(URL url)
throws IOException
url - input url
IOException@Deprecated public NSData(String value)
value - input value as StringNSData.NSData(InputStream inputStream, int chunkSize)
public NSData(String value,
String encoding)
value - The textual data to useencoding - The encoding type used to create the bytes.| Method Detail |
|---|
protected byte[] bytesNoCopy()
NSData.rangeNoCopy()protected NSRange rangeNoCopy()
bytesNoCopy)NSData.bytesNoCopy(),
NSData.bytesNoCopy(NSMutableRange dataRange)protected byte[] immutableBytes()
protected NSRange immutableRange()
public byte[] bytesNoCopy(NSMutableRange range)
range.
range - input mutable range specified by range
range's offset and length to those of the receiver's internal NSRange objectpublic NSData subdataWithRange(NSRange range)
range.
range - input range
range
RangeException - if range isn't within the receiver's range of bytes
@Deprecated
public static NSData dataWithContentsOfMappedFile(File file)
throws IOException
<blockquote> myData = new NSData(new FileInputStream(file), chunkSize); </blockquote>
file - input java.io.File object
file
IOException
@Deprecated
public static NSData dataWithContentsOfFile(File file)
throws IOException
myData = new NSData(new FileInputStream(file), chunkSize);
file - input java.io.File object
file
IOException
@Deprecated
public static NSData dataWithContentsOfFile(String path)
throws IOException
<blockquote> myData = new NSData(new FileInputStream(path), chunkSize); </blockquote>
path - input path of the file
path
IOExceptionpublic int length()
public byte[] bytes()
public byte[] bytes(int offset,
int length)
offset - input range specified by offsetlength - number of bytes following offset to return
offset and lengthpublic byte[] bytes(NSRange range)
range - input range specified by range
range
@Deprecated
public boolean writeToURL(URL url,
boolean atomically)
<blockquote>
try {
FileOutputStream fileOutputStream = new FileOutputStream(url.getFile());
myData.writeToStream(fileOutputStream);
fileOutputStream.close();
}
catch (java.io.IOException exception) {
// Do something with the exception
}
</blockquote>
url - input urlatomically - this parameter is ignored
NSData.writeToStream(java.io.OutputStream outputStream)@Deprecated public boolean writeToFile(String path)
<blockquote>
try {
FileOutputStream fileOutputStream = new FileOutputStream(path);
myData.writeToStream(fileOutputStream);
fileOutputStream.close();
} catch (java.io.IOException exception) {
// Do something with the exception
}
</blockquote>
path - input path of the file
public boolean isEqualToData(NSData otherData)
otherData. Two data objects are equal if they hold the same number of bytes, and if the bytes at the same position in the objects are the same.
otherData - input data object of type NSData
true if the contents of otherData are equal to the contents of the receiver, false
public boolean equals(Object object)
object. If object is an NSData and the contents of object are equal to the contents of the receiver, this method returns true. If not, it returns false. Two data objects are
equal if they hold the same number of bytes, and if the bytes at the same position in the objects are the same.
equals in class Objectobject - input data object
public ByteArrayInputStream stream()
java.io.ByteArrayInputStream containing the receiver's data
public void writeToStream(OutputStream stream)
throws IOException
stream.
stream - the input bytes in the receiver
java.io.IOException - if the write fails for any reason.
IOExceptionthrows java.io.IOExceptionpublic Class classForCoder()
classForCoder in interface NSCodingNSCoding.classForCoder()public static Object decodeObject(NSCoder coder)
coder.
coder -
NSKeyValueCoding.Null stored in the NSKeyValueCoding constant NullValueNSCodingpublic void encodeWithCoder(NSCoder coder)
NSCodingcoder. Object type information along with an object's data is stored.
encodeWithCoder in interface NSCodingcoder - NSCoderpublic int hashCode()
hashCode in class Objectpublic Object clone()
clone in class Objectpublic String toString()
toString in class Object
|
Last updated June 2008 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||