• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: StringBuffer to NSData
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: StringBuffer to NSData


  • Subject: Re: StringBuffer to NSData
  • From: Colin Clark <email@hidden>
  • Date: Fri, 10 Sep 2004 11:04:59 -0400

Hi Nathan,

Just to be clear, I'm assuming that this is the section from the WOCode example you're talking about:

	public NSData dataOfAFile = null;
	...
	aResponse.setContent( dataOfAFile );

If you take a look at the Javadocs for WOResponse, you'll notice that the setContent() method is overloaded in three ways:

public void setContent(char[] someContent)
public void setContent(NSData someContent)
public void setContent(String someContent)

So, if you just want to set the response's content using a StringBuffer, there is a version of setContent that takes a String as an argument that will do the trick. I can't guarantee it will actually have the affect you want, but all it took was a quick look at the Javadocs to see what your options were.

If you do need to turn your StringBuffer into a NSData object, that should be quite straightforward as well. NSData has constructor that takes an array of bytes. You can convert a String into a byte array by calling getBytes. So, assuming you're okay with the default character encoding, the code do this would be:

NSData myData = new NSData(myStringBuffer.toString().getBytes());

I hope that helps,

Colin

On Friday, September 10, 2004, at 09:04  AM, Nathan Dumar wrote:

I realize this is a very basic question, but ...

How do I convert a StringBuffer into an NSData?

I'm following some instructions to make a text file download (from wocode.com), and the variable used is an NSData. I'm assuming this needs to be what it is in order for the download to work, so I need to get my text from the StringBuffer into the NSData variable. How?

Thank you,
Nathan

PS - the instructions I'm following are ...
http://wocode.com/cgi-bin/WebObjects/WOCode.woa/1/wa/ ShareCodeItem?itemId=271&wosid=wNSsIbD8sUa57geK6nhZeM
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >StringBuffer to NSData (From: Nathan Dumar <email@hidden>)

  • Prev by Date: Re: Table Column Limit for WOReps?
  • Next by Date: RE: StringBuffer to NSData
  • Previous by thread: StringBuffer to NSData
  • Next by thread: RE: StringBuffer to NSData
  • Index(es):
    • Date
    • Thread