()
| 98 | } |
| 99 | |
| 100 | public void save() |
| 101 | throws IOException |
| 102 | { |
| 103 | File outputFile = new File(this.file.getPath() + ".tmp"); |
| 104 | if (outputFile.exists()) { |
| 105 | outputFile.delete(); |
| 106 | } |
| 107 | OutputStream out = new FileOutputStream(outputFile); |
| 108 | InputStream in = null; |
| 109 | byte[] buffer = new byte[4096]; |
| 110 | |
| 111 | int listOffset = this.dataOffset; |
| 112 | try |
| 113 | { |
| 114 | in = new FileInputStream(this.file); |
| 115 | int residualLength = this.dataOffset; |
| 116 | while (residualLength > 0) { |
| 117 | int length = Math.min(residualLength, buffer.length); |
| 118 | int count = in.read(buffer, 0, length); |
| 119 | if (count != length) { |
| 120 | throw new IOException("Save game header truncated"); |
| 121 | } |
| 122 | out.write(buffer, 0, count); |
| 123 | residualLength -= count; |
| 124 | } |
| 125 | |
| 126 | in.close(); |
| 127 | |
| 128 | for (SaveEntry entry : this.entries) { |
| 129 | if (entry.isOnDisk()) { |
| 130 | in = new FileInputStream(entry.getResourceFile()); |
| 131 | in.skip(entry.getResourceOffset()); |
| 132 | residualLength = entry.getResourceLength(); |
| 133 | listOffset += residualLength; |
| 134 | while (residualLength > 0) { |
| 135 | int length = Math.min(residualLength, buffer.length); |
| 136 | int count = in.read(buffer, 0, length); |
| 137 | if (count != length) { |
| 138 | throw new IOException("Resource data truncated for " + entry.getResourceName()); |
| 139 | } |
| 140 | out.write(buffer, 0, count); |
| 141 | residualLength -= count; |
| 142 | } |
| 143 | |
| 144 | in.close(); |
| 145 | } else { |
| 146 | List resourceDataList = entry.getResourceDataList(); |
| 147 | residualLength = entry.getResourceLength(); |
| 148 | listOffset += residualLength; |
| 149 | int index = 0; |
| 150 | while (residualLength > 0) { |
| 151 | byte[] dataBuffer = (byte[])resourceDataList.get(index); |
| 152 | int length = Math.min(residualLength, dataBuffer.length); |
| 153 | out.write(dataBuffer, 0, length); |
| 154 | residualLength -= length; |
| 155 | index++; |
| 156 | } |
| 157 |
nothing calls this directly
no test coverage detected