1 16 package org.apache.commons.net.io; 17 18 import java.io.FilterOutputStream ; 19 import java.io.IOException ; 20 import java.io.OutputStream ; 21 22 33 34 public final class ToNetASCIIOutputStream extends FilterOutputStream 35 { 36 private boolean __lastWasCR; 37 38 44 public ToNetASCIIOutputStream(OutputStream output) 45 { 46 super(output); 47 __lastWasCR = false; 48 } 49 50 51 62 public synchronized void write(int ch) 63 throws IOException 64 { 65 switch (ch) 66 { 67 case '\r': 68 __lastWasCR = true; 69 out.write('\r'); 70 return ; 71 case '\n': 72 if (!__lastWasCR) 73 out.write('\r'); 74 default: 76 __lastWasCR = false; 77 out.write(ch); 78 return ; 79 } 80 } 81 82 83 90 public synchronized void write(byte buffer[]) 91 throws IOException 92 { 93 write(buffer, 0, buffer.length); 94 } 95 96 97 107 public synchronized void write(byte buffer[], int offset, int length) 108 throws IOException 109 { 110 while (length-- > 0) 111 write(buffer[offset++]); 112 } 113 114 } 115 | Popular Tags |