Example #1
0
//============================================================================
//		NFileUtilities::GetFileText : Get a file as text.
//----------------------------------------------------------------------------
NString NFileUtilities::GetFileText(const NFile &theFile, NStringEncoding theEncoding)
{	NStringEncoder		theEncoder;
	NData				theData;
	NString				theText;



	// Get the state we need
	theData = GetFileData(theFile);
	if (theData.IsEmpty())
		return(theText);
	
	
	
	// Get the text
	if (theEncoding == kNStringEncodingInvalid)
		{
		theEncoding = theEncoder.GetEncoding(theData);
		NN_ASSERT(theEncoding != kNStringEncodingInvalid);
		}

	if (theEncoding != kNStringEncodingInvalid)
		theText = NString(theData, theEncoding);
		
	return(theText);
}
Example #2
0
//============================================================================
//		NDataEncoder::B64_Encode : Encode to Base64.
//----------------------------------------------------------------------------
NString NDataEncoder::B64_Encode(const NData &theValue)
{	NData					theBuffer;
	NString					theString;
	base64_encodestate		theState;
	char					*dataPtr;
	NIndex					dataSize;



	// Get the state we need
	base64_init_encodestate(&theState);

	if (theValue.IsEmpty() || !theBuffer.SetSize(theValue.GetSize() * 2))
		return(theString);



	// Encode the value
	dataPtr   = (char *) theBuffer.GetData();
	dataSize  = base64_encode_block((const char *) theValue.GetData(), theValue.GetSize(), dataPtr, &theState);
	theString = NString(dataPtr, dataSize);

	dataSize = base64_encode_blockend(dataPtr, &theState);
	if (dataSize != 0)
		theString += NString(dataPtr, dataSize);



	// Remove the trailing newline
	NN_ASSERT(theString.GetRight(1) == "\n");
	theString.TrimRight(1);

	return(theString);
}
Example #3
0
//============================================================================
//		NSocketRequest::NSocketRequest : Constructor.
//----------------------------------------------------------------------------
NSocketRequest::NSocketRequest(const NData &theData)
{


	// Validate our parameters
	NN_ASSERT(!theData.IsEmpty());



	// Initialise ourselves
	mData      = theData;
	mProcessed = 0;

	mStatus    = kNoErr;
	mSemaphore = NULL;
}