net.wotonomy.foundation
Class NSData

java.lang.Object
  extended by net.wotonomy.foundation.NSData
Direct Known Subclasses:
NSMutableData

public class NSData
extends java.lang.Object

A pure java implementation of NSData, which is basically a wrapper on a byte array.

Version:
$Revision: 893 $
Author:
michael@mpowers.net, $Author: cgruber $

Field Summary
protected  byte[] bytes
           
static NSData EmptyData
           
 
Constructor Summary
NSData()
          Default constructor creates a zero-data object.
NSData(byte[] data)
          Creates an object containing a copy of the specified bytes.
NSData(byte[] data, int start, int length)
          Creates an object containing a copy of the bytes from the specified array within the specified range.
NSData(java.io.File aFile)
          Creates an object containing the contents of the specified file.
NSData(java.io.InputStream stream, int chunkSize)
          Creates a new NSData object from the bytes in the input stream.
NSData(NSData aData)
          Creates an object containing a copy of the contents of the specified NSData object.
NSData(java.lang.String aString)
          Creates an object containing the bytes of the specified string.
NSData(java.net.URL aURL)
          Creates an object containing the contents of the specified URL.
 
Method Summary
 byte[] bytes()
          Returns a copy of the bytes backing this data object.
 byte[] bytes(int location, int length)
          Returns a copy of the bytes starting at the specified location and ranging for the specified length.
static NSData dataWithContentsOfMappedFile(java.io.File aFile)
          Convenience to return the contents of the specified file.
 boolean isEqual(java.lang.Object obj)
           
 boolean isEqualToData(NSData aData)
          Returns whether the specified data is equivalent to these data.
 int length()
          Returns the length of the contained data.
 NSData subdataWithRange(NSRange aRange)
          Return the bytes within the data that fall within the specified range.
 java.lang.String toString()
           
 boolean writeToURL(java.net.URL aURL, boolean atomically)
          Writes the contents of this data to the specified URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EmptyData

public static final NSData EmptyData

bytes

protected byte[] bytes
Constructor Detail

NSData

public NSData()
Default constructor creates a zero-data object.


NSData

public NSData(byte[] data)
Creates an object containing a copy of the specified bytes.


NSData

public NSData(byte[] data,
              int start,
              int length)
Creates an object containing a copy of the bytes from the specified array within the specified range.


NSData

public NSData(java.lang.String aString)
Creates an object containing the bytes of the specified string.


NSData

public NSData(java.io.File aFile)
Creates an object containing the contents of the specified file. Errors reading the file will produce an empty or partially blank array.


NSData

public NSData(java.net.URL aURL)
Creates an object containing the contents of the specified URL.


NSData

public NSData(NSData aData)
Creates an object containing a copy of the contents of the specified NSData object.


NSData

public NSData(java.io.InputStream stream,
              int chunkSize)
       throws java.io.IOException
Creates a new NSData object from the bytes in the input stream. The input stream is read fully and is not closed.

Parameters:
stream - The stream to read from.
chunkSize - The buffer size used to read from the stream.
Throws:
java.io.IOException - if the stream cannot be read from.
Method Detail

length

public int length()
Returns the length of the contained data.


isEqualToData

public boolean isEqualToData(NSData aData)
Returns whether the specified data is equivalent to these data.


subdataWithRange

public NSData subdataWithRange(NSRange aRange)
Return the bytes within the data that fall within the specified range.


writeToURL

public boolean writeToURL(java.net.URL aURL,
                          boolean atomically)
Writes the contents of this data to the specified URL. If atomically is true, then the data is written to a temporary file and then renamed to the name specified by the URL when the data transfer is complete.


dataWithContentsOfMappedFile

public static NSData dataWithContentsOfMappedFile(java.io.File aFile)
Convenience to return the contents of the specified file.


bytes

public byte[] bytes(int location,
                    int length)
Returns a copy of the bytes starting at the specified location and ranging for the specified length.


bytes

public byte[] bytes()
Returns a copy of the bytes backing this data object. NOTE: This method is not in the NSData spec and is included for convenience only.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

isEqual

public boolean isEqual(java.lang.Object obj)


Copyright © 2006 null. All Rights Reserved.