Requirements for custom stream processing in File data sets

Standard File data sets support reading or writing compressed .zip and .gzip files. To extend these capabilities to support encryption, decryption, and other compression methods for files in repositories, implement custom stream processing as Java classes on the Pega Platform server classpath.

To implement custom stream processing, ensure that:
  • The input stream processing class implements java.util.function.Function<InputStream, InputStream>.
  • The output stream processing class implements java.util.function.Function<OutputStream, OutputStream>.
  • The classes are present on the Pega Platform server classpath on every node that uses the data set, for example, by importing the .jar file to pega-enginecode codeset. The codeset version must be the same as the release version.
  • For custom stream processing with ZIP compression, the java.util.function.Function<OutputStream, OutputStream> function does not replace the original stream.
  • The classes are public.
  • The classes expose a public constructor with no arguments.
  • You restart the application server after importing the new classes.
See the following code for a sample custom stream processing implementation (output and input streams):
public class OutputStreamShiftingProcessing implements Function<OutputStream, OutputStream> {  
  
  
private static final int SHIFT = 2;  
  
  
 @Override  
 public OutputStream apply(OutputStream outputStream) {  
   return new ShiftingOutputStream(outputStream);  
 }  
  
  
 public static class ShiftingOutputStream extends OutputStream {  
  
  
 private final OutputStream outputStream;  
  
  
 public ShiftingOutputStream(OutputStream outputStream) {  
   this.outputStream = outputStream;  
 }  
  
  
 @Override  
 public void write(int b) throws IOException {  
   if (b != -1) {  
     outputStream.write(b + SHIFT);  
   } else {  
     outputStream.write(b);  
   }  
 }  
  
  
 @Override  
 public void close() throws IOException {  
   outputStream.close();  
 }  
 }  
}  
 public class InputStreamShiftingProcessing implements Function<InputStream, InputStream> {  
  
  
 private static final int SHIFT = 2;  
  
  
 @Override  
 public InputStream apply(InputStream inputStream) {  
   return new ShiftingInputStream(inputStream);  
 }  
  
 public static class ShiftingInputStream extends InputStream {  
  
 private final InputStream inputStream;  
  
 public ShiftingInputStream(InputStream inputStream) {  
   this.inputStream = inputStream;  
 }  
  
 @Override  
 public int read() throws IOException {  
   int read = inputStream.read();  
   if (read != -1) {  
     return read - SHIFT;  
   } else {  
     return read;  
   }  
 }  
  
  
 @Override  
 public void close() throws IOException {  
   inputStream.close();  
 }  
 }  
}