1 19 20 package gnu.mail.util; 21 22 import java.io.*; 23 24 31 public class MessageOutputStream 32 extends FilterOutputStream 33 { 34 35 38 public static final int END = 46; 39 40 43 public static final int LF = 10; 44 45 int[] last = { LF, LF }; 47 51 public MessageOutputStream(OutputStream out) 52 { 53 super(out); 54 } 55 56 60 public void write(int ch) 61 throws IOException 62 { 63 if (last[0]==LF && last[1]==END && ch==LF) 64 out.write(END); 65 out.write(ch); 66 last[0] = last[1]; 67 last[1] = ch; 68 } 69 70 74 public void write(byte b[], int off, int len) 75 throws IOException 76 { 77 for (int i = 0; i < len; i++) 78 { 79 int ch = (int)b[off+i]; 80 if (last[0]==LF && last[1]==END && ch==LF) 81 { 82 byte[] b2 = new byte[b.length+1]; 83 System.arraycopy(b, off, b2, off, i); 84 b2[off+i] = END; 85 System.arraycopy(b, off+i, b2, off+i+1, len-i); 86 b = b2; 87 i++; len++; 88 } 89 last[0] = last[1]; 90 last[1] = ch; 91 } 92 out.write(b, off, len); 93 } 94 95 } 96 97 | Popular Tags |