(InputStream inStream)
| 143 | * Return byte[] on success, null on failure |
| 144 | */ |
| 145 | public static byte[] ReadToken(InputStream inStream) |
| 146 | { |
| 147 | if (DEBUG) |
| 148 | System.out.println("Entered ReadToken..."); |
| 149 | |
| 150 | byte[] inputTokenBuffer = null; |
| 151 | |
| 152 | try { |
| 153 | |
| 154 | int data; |
| 155 | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| 156 | |
| 157 | /* First read the incomming array size (first 4 bytes) */ |
| 158 | int array_size = 0; |
| 159 | byte[] temp = null; |
| 160 | for (int i = 0; i < 4; i++) { |
| 161 | data = inStream.read(); |
| 162 | if (DEBUG) |
| 163 | System.out.println("ReadToken... read() returned: " + data); |
| 164 | out.write(data); |
| 165 | } |
| 166 | temp = out.toByteArray(); |
| 167 | array_size = Util.byteArrayToInt(temp); |
| 168 | out.reset(); |
| 169 | |
| 170 | if (DEBUG) |
| 171 | System.out.println("... got byte array size = " + array_size); |
| 172 | |
| 173 | if (array_size < 0) |
| 174 | return null; |
| 175 | |
| 176 | /* Now read our full array */ |
| 177 | for (int j = 0; j < array_size; j++) { |
| 178 | data = inStream.read(); |
| 179 | out.write(data); |
| 180 | } |
| 181 | |
| 182 | if (DEBUG) { |
| 183 | System.out.println("... got data: "); |
| 184 | Util.printByteArray(out.toByteArray()); |
| 185 | System.out.println("... returning from ReadToken, success"); |
| 186 | } |
| 187 | |
| 188 | return out.toByteArray(); |
| 189 | |
| 190 | } catch (IOException e) { |
| 191 | e.printStackTrace(); |
| 192 | return null; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | /* |
| 197 | * Print a byte[], for debug purposes. |
no test coverage detected