1 7 package com.coldcore.coloradoftp.filter.impl; 8 9 import com.coldcore.coloradoftp.filter.DataFilter; 10 11 import java.io.IOException ; 12 import java.nio.ByteBuffer ; 13 import java.nio.channels.ReadableByteChannel ; 14 import java.nio.channels.WritableByteChannel ; 15 16 public class GenericDataFilter implements DataFilter { 17 18 protected WritableByteChannel wbc; 19 protected ReadableByteChannel rbc; 20 protected String name; 21 protected boolean upload; 22 23 24 public void setChannel(WritableByteChannel wbc) { 25 this.wbc = wbc; 26 upload = true; 27 } 28 29 30 public void setChannel(ReadableByteChannel rbc) { 31 this.rbc = rbc; 32 upload = false; 33 } 34 35 36 public boolean mayModifyDataLength() { 37 return false; 38 } 39 40 41 public boolean isOpen() { 42 return upload ? wbc.isOpen() : rbc.isOpen(); 43 } 44 45 46 public void close() throws IOException { 47 if (upload) wbc.close(); 48 else rbc.close(); 49 } 50 51 52 public int write(ByteBuffer src) throws IOException { 53 return wbc.write(src); 55 } 56 57 58 public int read(ByteBuffer dst) throws IOException { 59 return rbc.read(dst); 61 } 62 63 64 public String getName() { 65 return name; 66 } 67 68 69 public void setName(String name) { 70 this.name = name; 71 } 72 } 73 | Popular Tags |