()
| 86 | } |
| 87 | |
| 88 | public void prepare() throws IOException { |
| 89 | for (StringItem s : this) { |
| 90 | if (s.data.length() > 0x7FFF) { |
| 91 | useUTF8 = false; |
| 92 | } |
| 93 | } |
| 94 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 95 | int i = 0; |
| 96 | int offset = 0; |
| 97 | baos.reset(); |
| 98 | Map<String, Integer> map = new HashMap<String, Integer>(); |
| 99 | for (StringItem item : this) { |
| 100 | item.index = i++; |
| 101 | String stringData = item.data; |
| 102 | Integer of = map.get(stringData); |
| 103 | if (of != null) { |
| 104 | item.dataOffset = of; |
| 105 | } else { |
| 106 | item.dataOffset = offset; |
| 107 | map.put(stringData, offset); |
| 108 | if (useUTF8) { |
| 109 | int length = stringData.length(); |
| 110 | byte[] data = stringData.getBytes("UTF-8"); |
| 111 | int u8lenght = data.length; |
| 112 | |
| 113 | if (length > 0x7F) { |
| 114 | offset++; |
| 115 | baos.write((length >> 8) | 0x80); |
| 116 | } |
| 117 | baos.write(length); |
| 118 | |
| 119 | if (u8lenght > 0x7F) { |
| 120 | offset++; |
| 121 | baos.write((u8lenght >> 8) | 0x80); |
| 122 | } |
| 123 | baos.write(u8lenght); |
| 124 | baos.write(data); |
| 125 | baos.write(0); |
| 126 | offset += 3 + u8lenght; |
| 127 | } else { |
| 128 | int length = stringData.length(); |
| 129 | byte[] data = stringData.getBytes("UTF-16LE"); |
| 130 | if (length > 0x7FFF) { |
| 131 | int x = (length >> 16) | 0x8000; |
| 132 | baos.write(x); |
| 133 | baos.write(x >> 8); |
| 134 | offset += 2; |
| 135 | } |
| 136 | baos.write(length); |
| 137 | baos.write(length >> 8); |
| 138 | baos.write(data); |
| 139 | baos.write(0); |
| 140 | baos.write(0); |
| 141 | offset += 4 + data.length; |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | // TODO |
nothing calls this directly
no test coverage detected