Decodes exactly one DataItem from the input stream. @return a DataItem or null if end of stream has reached. @throws CborException if decoding failed
()
| 119 | * if decoding failed |
| 120 | */ |
| 121 | public DataItem decodeNext() throws CborException { |
| 122 | int symbol; |
| 123 | try { |
| 124 | symbol = inputStream.read(); |
| 125 | } catch (IOException ioException) { |
| 126 | throw new CborException(ioException); |
| 127 | } |
| 128 | if (symbol == -1) { |
| 129 | return null; |
| 130 | } |
| 131 | switch (MajorType.ofByte(symbol)) { |
| 132 | case ARRAY: |
| 133 | return arrayDecoder.decode(symbol); |
| 134 | case BYTE_STRING: |
| 135 | return byteStringDecoder.decode(symbol); |
| 136 | case MAP: |
| 137 | return mapDecoder.decode(symbol); |
| 138 | case NEGATIVE_INTEGER: |
| 139 | return negativeIntegerDecoder.decode(symbol); |
| 140 | case UNICODE_STRING: |
| 141 | return unicodeStringDecoder.decode(symbol); |
| 142 | case UNSIGNED_INTEGER: |
| 143 | return unsignedIntegerDecoder.decode(symbol); |
| 144 | case SPECIAL: |
| 145 | return specialDecoder.decode(symbol); |
| 146 | case TAG: |
| 147 | Tag tag = tagDecoder.decode(symbol); |
| 148 | DataItem next = decodeNext(); |
| 149 | if (next == null) { |
| 150 | throw new CborException("Unexpected end of stream: tag without following data item."); |
| 151 | } else { |
| 152 | if (autoDecodeRationalNumbers && tag.getValue() == 30) { |
| 153 | return decodeRationalNumber(next); |
| 154 | } else if (autoDecodeLanguageTaggedStrings && tag.getValue() == 38) { |
| 155 | return decodeLanguageTaggedString(next); |
| 156 | } else { |
| 157 | DataItem itemToTag = next; |
| 158 | while (itemToTag.hasTag()) |
| 159 | itemToTag = itemToTag.getTag(); |
| 160 | itemToTag.setTag(tag); |
| 161 | return next; |
| 162 | } |
| 163 | } |
| 164 | case INVALID: |
| 165 | default: |
| 166 | throw new CborException("Not implemented major type " + symbol); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | private DataItem decodeLanguageTaggedString(DataItem dataItem) throws CborException { |
| 171 | if (!(dataItem instanceof Array)) { |