// Set the STORYLINE attribute for the Lost in Translation movie
String storylinePart1 = "This could be part of the storyline, read from ";
String storylinePart2 = "a text file to a simple char[].";
TextStream tstrm = new TextStream(false);
g.setAttributeText(mLostInTranslation, movieStorylineType, tstrm);
char[] textBuffer = storylinePart1.toCharArray();
tstrm.write(textBuffer, textBuffer.length);
textBuffer = storylinePart2.toCharArray();
tstrm.write(textBuffer, textBuffer.length);
tstrm.close();
new TextStream(false);
// Get the STORYLINE attribute for the Lost in Translation movie
char[] textBuffer = new char[1024];
TextStream tstrm = g.getAttributeText(mLostInTranslation, movieStorylineType);
int readed;
String storyline = new String();
do {
readed = tstrm.read(textBuffer, textBuffer.length);
storyline += new String(textBuffer, 0, readed);
} while (readed > 0);
tstrm.close();
System.out.println("The TEXT attribute value: \""+ storyline+"\"");
Use of TextStream for reading: (i) Get the text attribute of a node or edge instance and (ii) get the TextStream instance from the retrieved Value instance. Once you have the TextStream instance, you can execute Read operations to read from the stream. (iii) The end of the stream is reached when Read returns 0. Finally, (iv) execute Close to close stream resources."