This sample does not actually do anything, it just illustrates the structure of the filter approach. This example shows an appropriate way to process the output stream as it is being written by the FCS server to the original stream. public class TestFilter implements FCSStreamFilter { private Element _params; class MyFilteredOutputStream extends FilterOutputStream { private int _bytesWritten; public MyFilteredOutputStream(OutputStream out) { super(out); } public void write(byte[] b, int off, int len) throws IOException { super.write(b, off, len); _bytesWritten+= len; } } public OutputStream getCheckinStream(Item item, LocationInfo info, FcsContext context, OutputStream underlyingStream) throws FcsException { return new MyFilteredOutputStream(underlyingStream); } public InputStream getCheckoutStream(Item item, LocationInfo info, FcsContext context, InputStream underlyingStream) throws Exception { return underlyingStream; } public void init(Element params) { _params = params; } } This filter performs compression: package main; import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; import com.matrixone.fcs.common.FcsException; import com.matrixone.fcs.fcs.FCSStreamFilter; import com.matrixone.fcs.fcs.FcsContext; import com.matrixone.fcs.fcs.Location; import com.matrixone.jdom.Element; public class ZipFilter implements FCSStreamFilter { @Override public OutputStream getCheckinStream(FcsContext arg0, Location arg1, OutputStream arg2) throws FcsException { ZipOutputStream z = new ZipOutputStream(arg2); ZipEntry e = new ZipEntry("a"); try { z.putNextEntry(e); } catch (IOException e1) { throw new FcsException(e1); } return z; } @Override public InputStream getCheckoutStream(FcsContext arg0, Location arg1, InputStream arg2) throws Exception { ZipInputStream z = new ZipInputStream(new MyZipInputStream(arg2)); z.getNextEntry(); return z; } class MyZipInputStream extends FilterInputStream { protected MyZipInputStream(InputStream arg0) { super(arg0); } @Override public void close() throws IOException { byte[] b = new byte [8192]; while (read(b) > 0){ } super.close(); } } @Override public void init(Location arg0, Element arg1) { } } Deprecation notice Deprecation of the
The deprecation of
If you want to use file stream filters, you must no longer implement
the
For the zip sample, just replace
|