(InputStream inStream)
| 91 | * Return byte[] on success, null on failure |
| 92 | */ |
| 93 | public static byte[] ReadToken(InputStream inStream) |
| 94 | { |
| 95 | if (DEBUG) |
| 96 | System.out.println("Entered ReadToken..."); |
| 97 | |
| 98 | byte[] inputTokenBuffer = null; |
| 99 | |
| 100 | try { |
| 101 | |
| 102 | int data; |
| 103 | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| 104 | |
| 105 | /* First read the incomming array size (first 4 bytes) */ |
| 106 | int array_size = 0; |
| 107 | byte[] temp = null; |
| 108 | for (int i = 0; i < 4; i++) { |
| 109 | data = inStream.read(); |
| 110 | if (DEBUG) |
| 111 | System.out.println("ReadToken... read() returned: " + data); |
| 112 | out.write(data); |
| 113 | } |
| 114 | temp = out.toByteArray(); |
| 115 | array_size = Util.byteArrayToInt(temp); |
| 116 | out.reset(); |
| 117 | |
| 118 | if (DEBUG) |
| 119 | System.out.println("... got byte array size = " + array_size); |
| 120 | |
| 121 | if (array_size < 0) |
| 122 | return null; |
| 123 | |
| 124 | /* Now read our full array */ |
| 125 | for (int j = 0; j < array_size; j++) { |
| 126 | data = inStream.read(); |
| 127 | out.write(data); |
| 128 | } |
| 129 | |
| 130 | if (DEBUG) { |
| 131 | System.out.println("... got data: "); |
| 132 | Util.printByteArray(out.toByteArray()); |
| 133 | System.out.println("... returning from ReadToken, success"); |
| 134 | } |
| 135 | |
| 136 | return out.toByteArray(); |
| 137 | |
| 138 | } catch (IOException e) { |
| 139 | e.printStackTrace(); |
| 140 | return null; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | * Print a byte[], for debug purposes. |
no test coverage detected