108 default: 109 case -1: /* this is an error */ 110 throw new TelnetProtocolException("misplaced CR in input"); 111 112 case 0: /* NUL - treat CR as CR */ 113 return '\r'; 114 115 case '\n': /* CRLF - treat as NL */ 116 if (stickyCRLF) { 117 seenCR = true; 118 return '\r'; 119 } else { 120 return '\n'; 121 } 122 } 123 } 124 return c; 125 } 126 127 /** read into a byte array */ 128 public int read(byte bytes[]) throws IOException { 129 return read(bytes, 0, bytes.length); 130 } 131 132 /** 133 * Read into a byte array at offset <i>off</i> for length <i>length</i> 134 * bytes. 135 */ 136 public int read(byte bytes[], int off, int length) throws IOException { 137 if (binaryMode) 138 return super.read(bytes, off, length); 139 140 int c; 141 int offStart = off; 142 143 while (--length >= 0) { 144 c = read(); 145 if (c == -1) 146 break; 147 bytes[off++] = (byte)c; 148 } 149 return (off > offStart) ? off - offStart : -1; 150 } 151 } | 108 default: 109 case -1: /* this is an error */ 110 throw new TelnetProtocolException("misplaced CR in input"); 111 112 case 0: /* NUL - treat CR as CR */ 113 return '\r'; 114 115 case '\n': /* CRLF - treat as NL */ 116 if (stickyCRLF) { 117 seenCR = true; 118 return '\r'; 119 } else { 120 return '\n'; 121 } 122 } 123 } 124 return c; 125 } 126 127 /** read into a byte array */ 128 public int read(byte[] bytes) throws IOException { 129 return read(bytes, 0, bytes.length); 130 } 131 132 /** 133 * Read into a byte array at offset <i>off</i> for length <i>length</i> 134 * bytes. 135 */ 136 public int read(byte[] bytes, int off, int length) throws IOException { 137 if (binaryMode) 138 return super.read(bytes, off, length); 139 140 int c; 141 int offStart = off; 142 143 while (--length >= 0) { 144 c = read(); 145 if (c == -1) 146 break; 147 bytes[off++] = (byte)c; 148 } 149 return (off > offStart) ? off - offStart : -1; 150 } 151 } |