01: package com.coldcore.coloradoftp.plugin.webcam;
02:
03: import com.coldcore.coloradoftp.filter.impl.GenericDataFilter;
04:
05: import java.io.IOException;
06: import java.io.InputStream;
07: import java.io.PipedInputStream;
08: import java.io.PipedOutputStream;
09: import java.nio.ByteBuffer;
10: import java.nio.channels.Channels;
11: import java.nio.channels.WritableByteChannel;
12:
13: /**
14: * This filter grabs uploaded file and provides an input stream.
15: */
16: public class FileGrabber extends GenericDataFilter {
17:
18: protected PipedInputStream pin;
19: protected WritableByteChannel twbc;
20:
21: public FileGrabber() throws IOException {
22: PipedOutputStream pout = new PipedOutputStream();
23: twbc = Channels.newChannel(pout);
24: pin = new PipedInputStream(pout);
25: }
26:
27: public int write(ByteBuffer src) throws IOException {
28: return twbc.write(src);
29: }
30:
31: /** Get input stream */
32: public InputStream getInputStream() {
33: return pin;
34: }
35:
36: public void close() throws IOException {
37: twbc.close();
38: }
39: }
|