package wenjian;
import java.io.IOException;
import java.io.OutputStream;
public class DecoratorOutputStream extends OutputStream{
protected OutputStream os;
public DecoratorOutputStream(OutputStream os) {
this.os = os;
}
@Override
public void write(int a) throws IOException {
if(os!=null)
os.write(a);
}
}
package wenjian;
import java.io.IOException;
import java.io.OutputStream;
public class NewOutputStream1 extends DecoratorOutputStream {
public NewOutputStream1(OutputStream os) {
super(os);
}
public void write(int a) throws IOException
{a=a+5;
if(a>=97+26)
a=a-26;
this.os.write(a);
}
}
package wenjian;
import java.io.IOException;
import java.io.OutputStream;
public class NewOutputStream2 extends DecoratorOutputStream {
public NewOutputStream2(OutputStream os) {
super(os);
}
public void write(int a) throws IOException
{if(a<=97+26&&a>=97)
a=a-32;
this.os.write(a);
}
}
package wenjian;
import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import zhaungshimoshi.EnOutputStream;
public class Test {
public static void main(String args[]) throws IOException
{DataOutputStream dout = new DataOutputStream(new BufferedOutputStream(
new NewOutputStream1(new NewOutputStream2(new FileOutputStream("f:\\gwh.txt")))));
dout.write("abcdxyz".getBytes());
dout.close();
}
}
装饰模式实例自定义文件输出流
最新推荐文章于 2021-04-16 00:03:41 发布