Write a MessageBytes out at the current write position. A null MessageBytes is encoded as a string with length 0. @param mb The data to write
(MessageBytes mb)
| 143 | * @param mb The data to write |
| 144 | */ |
| 145 | public void appendBytes(MessageBytes mb) { |
| 146 | if (mb == null) { |
| 147 | log.error(sm.getString("ajpmessage.null"), new NullPointerException()); |
| 148 | appendInt(0); |
| 149 | appendByte(0); |
| 150 | return; |
| 151 | } |
| 152 | if (mb.getType() != MessageBytes.T_BYTES) { |
| 153 | mb.toBytes(); |
| 154 | ByteChunk bc = mb.getByteChunk(); |
| 155 | // Need to filter out CTLs excluding TAB. ISO-8859-1 and UTF-8 |
| 156 | // values will be OK. Strings using other encodings may be |
| 157 | // corrupted. |
| 158 | byte[] buffer = bc.getBuffer(); |
| 159 | for (int i = bc.getStart(); i < bc.getEnd(); i++) { |
| 160 | // byte values are signed i.e. -128 to 127 |
| 161 | // The values are used unsigned. 0 to 31 are CTLs so they are |
| 162 | // filtered (apart from TAB which is 9). 127 is a control (DEL). |
| 163 | // The values 128 to 255 are all OK. Converting those to signed |
| 164 | // gives -128 to -1. |
| 165 | if ((buffer[i] > -1 && buffer[i] <= 31 && buffer[i] != 9) || buffer[i] == 127) { |
| 166 | buffer[i] = ' '; |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | appendByteChunk(mb.getByteChunk()); |
| 171 | } |
| 172 | |
| 173 | |
| 174 | /** |