Beispiel #1
0
static ZTupleValue sReadStringish(const ZStreamU& s)
	{
	const int32 stringLength = sReadInteger(s);
	const uint8 terminator = s.ReadUInt8();
	if (terminator != ':')
		throw runtime_error("Expected ':' terminator for string/binary length");

	// Suck all the data into a memory block.
	ZMemoryBlock theMB;
	ZStreamRWPos_MemoryBlock(theMB).CopyFrom(s, stringLength);

	// Transcribe the data as UTF8 into theString.
	string theString;
	ZStrimW_String(theString).CopyAllFrom(ZStrimR_StreamUTF8(ZStreamRPos_MemoryBlock(theMB)));

	if (theString.size() == stringLength)
		{
		// The number of bytes in theString matches the number of bytes
		// in theMB, so every byte was valid UTF-8 and we can return it as a string.
		return theString;
		}
	else
		{
		// Some code units were skipped, so return the raw data.
		return theMB;
		}
	}
Beispiel #2
0
/*
 * Class:     org_zoolib_tuplebase_ZTB_1RAM
 * Method:    sConstruct_Stream
 * Signature: (Ljava/io/InputStream;)I
 */
JNIEXPORT jint JNICALL Java_org_zoolib_tuplebase_ZTB_1RAM_sConstruct_1Stream
	(JNIEnv* iEnv, jclass, jobject iStream)
	{
	vector<ZRef<ZTupleIndexFactory> > theFactories;
	try
		{
		ZTS_RAM* theTS = new ZTS_RAM(theFactories, ZStrimU_Unreader(ZStrimR_StreamUTF8(ZStreamR_Buffered(4096, ZStreamR_JNI(iEnv, iStream)))));
		ZTB* theTB = new ZTB(new ZTBRep_TS(theFactories, theTS));
		return reinterpret_cast<jint>(theTB);
		}
	catch (...)
		{
		return 0;
		}
	}