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 37 38 public final class FromNetASCIIOutputStream extends FilterOutputStream 39 { 40 private boolean __lastWasCR; 41 42 48 public FromNetASCIIOutputStream(OutputStream output) 49 { 50 super(output); 51 __lastWasCR = false; 52 } 53 54 55 private void __write(int ch) throws IOException 56 { 57 switch (ch) 58 { 59 case '\r': 60 __lastWasCR = true; 61 break; 63 case '\n': 64 if (__lastWasCR) 65 { 66 out.write(FromNetASCIIInputStream._lineSeparatorBytes); 67 __lastWasCR = false; 68 break; 69 } 70 __lastWasCR = false; 71 out.write('\n'); 72 break; 73 default: 74 if (__lastWasCR) 75 { 76 out.write('\r'); 77 __lastWasCR = false; 78 } 79 out.write(ch); 80 break; 81 } 82 } 83 84 85 97 public synchronized void write(int ch) 98 throws IOException 99 { 100 if (FromNetASCIIInputStream._noConversionRequired) 101 { 102 out.write(ch); 103 return ; 104 } 105 106 __write(ch); 107 } 108 109 110 117 public synchronized void write(byte buffer[]) 118 throws IOException 119 { 120 write(buffer, 0, buffer.length); 121 } 122 123 124 134 public synchronized void write(byte buffer[], int offset, int length) 135 throws IOException 136 { 137 if (FromNetASCIIInputStream._noConversionRequired) 138 { 139 out.write(buffer, offset, length); 142 return ; 143 } 144 145 while (length-- > 0) 146 __write(buffer[offset++]); 147 } 148 149 150 155 public synchronized void close() 156 throws IOException 157 { 158 if (FromNetASCIIInputStream._noConversionRequired) 159 { 160 super.close(); 161 return ; 162 } 163 164 if (__lastWasCR) 165 out.write('\r'); 166 super.close(); 167 } 168 } 169 | Popular Tags |