Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
InputStream stream = new ByteArrayInputStream(contentString.getBytes("UTF-8"));
CustomContentProperties properties = new CustomContentProperties();
properties.setProperty("customProperty", new StringValue("value"));
String contentName = "content name";
String contentType = "text/plain";
if(contentManager instanceof IChannelContentManager channelContentManager) {
  // Using the Java NIO-based API introduced in Blueriq 17.4
  GUID contentId = channelContentManager.create(Channels.newChannel(stream), contentName, contentType, properties, context.getSessionScope().getActiveUser());
} else {
  // Using the stream-based API that was deprecated in Blueriq 17.4 and might be released in a future release
  GUID contentId = contentManager.create(stream, contentName, contentType, properties, context.getSessionScope().getActiveUser()); 
}

The properties object may be used to store additional properties with the content. The contentId will be required to read, update or delete this content at a later time.

...

The following code snippet shows how to retrieve the string that was created in the previous example.

Code Block
languagejava
InputStreamif(contentManager instanceof IChannelContentManager channelContentManager) {
  // Using the Java NIO-based API introduced in Blueriq 17.4
  
} else {
   // Using the stream-based API that was deprecated in Blueriq 17.4 and might be released in a future release 
  InputStream stream = contentManager.readData(contentId, context.getSessionScope().getActiveUser());
  String contentString = new String(StreamUtil.getBytes(stream), "UTF-8");
}

To retrieve the custom property you may use the readMetadata method, for example:

...