01: /**
02: * @see com.coldcore.coloradoftp.filter.DataFilter
03: *
04: * This filter does nothing but forwards data is it is.
05: * It can be used as a filter for TYPE I, STRU F and MODE S.
06: */package com.coldcore.coloradoftp.filter.impl;
07:
08: import com.coldcore.coloradoftp.filter.DataFilter;
09:
10: import java.io.IOException;
11: import java.nio.ByteBuffer;
12: import java.nio.channels.ReadableByteChannel;
13: import java.nio.channels.WritableByteChannel;
14:
15: public class GenericDataFilter implements DataFilter {
16:
17: protected WritableByteChannel wbc;
18: protected ReadableByteChannel rbc;
19: protected String name;
20: protected boolean upload;
21:
22: public void setChannel(WritableByteChannel wbc) {
23: this .wbc = wbc;
24: upload = true;
25: }
26:
27: public void setChannel(ReadableByteChannel rbc) {
28: this .rbc = rbc;
29: upload = false;
30: }
31:
32: public boolean mayModifyDataLength() {
33: return false;
34: }
35:
36: public boolean isOpen() {
37: return upload ? wbc.isOpen() : rbc.isOpen();
38: }
39:
40: public void close() throws IOException {
41: if (upload)
42: wbc.close();
43: else
44: rbc.close();
45: }
46:
47: public int write(ByteBuffer src) throws IOException {
48: //Do nothing, pass as it is
49: return wbc.write(src);
50: }
51:
52: public int read(ByteBuffer dst) throws IOException {
53: //Do nothing, pass as it is
54: return rbc.read(dst);
55: }
56:
57: public String getName() {
58: return name;
59: }
60:
61: public void setName(String name) {
62: this.name = name;
63: }
64: }
|