()
| 174 | } |
| 175 | |
| 176 | public void save() |
| 177 | throws DBException, IOException |
| 178 | { |
| 179 | File outputFile = new File(this.file.getPath() + ".tmp"); |
| 180 | if (outputFile.exists()) { |
| 181 | outputFile.delete(); |
| 182 | } |
| 183 | RandomAccessFile out = new RandomAccessFile(outputFile, "rw"); |
| 184 | RandomAccessFile in = null; |
| 185 | try |
| 186 | { |
| 187 | byte[] header = new byte[' ']; |
| 188 | out.write(header); |
| 189 | |
| 190 | byte[] buffer = new byte['']; |
| 191 | int stringOffset = (int)out.getFilePointer(); |
| 192 | int stringSize = 0; |
| 193 | int stringCount = this.description.getSubstringCount(); |
| 194 | for (int i = 0; i < stringCount; i++) { |
| 195 | LocalizedSubstring substring = this.description.getSubstring(i); |
| 196 | String string = substring.getString(); |
| 197 | byte[] stringBytes = string.getBytes(); |
| 198 | int length = stringBytes.length; |
| 199 | if (length + 8 > buffer.length) { |
| 200 | buffer = new byte[length + 8]; |
| 201 | } |
| 202 | setInteger(substring.getLanguage() * 2 + substring.getGender(), buffer, 0); |
| 203 | setInteger(length, buffer, 4); |
| 204 | for (int j = 0; j < length; j++) { |
| 205 | buffer[(j + 8)] = stringBytes[j]; |
| 206 | } |
| 207 | out.write(buffer, 0, length + 8); |
| 208 | stringSize += length + 8; |
| 209 | } |
| 210 | |
| 211 | int entryCount = this.entries.size(); |
| 212 | int keyOffset = (int)out.getFilePointer(); |
| 213 | int resourceID = 0; |
| 214 | int entryLength; |
| 215 | int nameLength; |
| 216 | if (this.databaseVersion.equals("V1.1")) { |
| 217 | nameLength = 32; |
| 218 | entryLength = 40; |
| 219 | } else { |
| 220 | nameLength = 16; |
| 221 | entryLength = 24; |
| 222 | } |
| 223 | |
| 224 | byte[] keyBuffer = new byte[entryLength]; |
| 225 | for (ResourceEntry entry : this.entries) { |
| 226 | byte[] nameBytes = entry.getResourceName().getBytes(); |
| 227 | if (nameBytes.length > nameLength) { |
| 228 | throw new DBException("Resource name '" + entry.getResourceName() + "' is too long"); |
| 229 | } |
| 230 | int index; |
| 231 | for (index = 0; index < nameBytes.length; index++) { |
| 232 | keyBuffer[index] = nameBytes[index]; |
| 233 | } |
nothing calls this directly
no test coverage detected