gets an (uncompressed) stream representing the chunk data returns null if the chunk is not found or an error occurs
(int x, int z)
| 184 | * chunk is not found or an error occurs |
| 185 | */ |
| 186 | public synchronized DataInputStream getChunkDataInputStream(int x, int z) { |
| 187 | if (this.outOfBounds(x, z)) { |
| 188 | this.debug("read", x, z, "out of bounds"); |
| 189 | return null; |
| 190 | } |
| 191 | |
| 192 | try { |
| 193 | int offset = this.getOffset(x, z); |
| 194 | if (offset == 0) { |
| 195 | // debugln("READ", x, z, "miss"); |
| 196 | return null; |
| 197 | } |
| 198 | |
| 199 | int sectorNumber = offset >> 8; |
| 200 | int numSectors = offset & 0xFF; |
| 201 | |
| 202 | if (sectorNumber + numSectors > this.sectorFree.size()) { |
| 203 | this.debug("read", x, z, "invalid sector"); |
| 204 | return null; |
| 205 | } |
| 206 | |
| 207 | this.file.seek(sectorNumber * RegionFile.SECTOR_BYTES); |
| 208 | int length = this.file.readInt(); |
| 209 | |
| 210 | if (length > RegionFile.SECTOR_BYTES * numSectors) { |
| 211 | this.debug("read", x, z, "invalid length: " + length + " > 4096 * " + numSectors); |
| 212 | return null; |
| 213 | } |
| 214 | |
| 215 | byte version = this.file.readByte(); |
| 216 | if (version == RegionFile.VERSION_GZIP) { |
| 217 | byte[] data = new byte[length - 1]; |
| 218 | this.file.read(data); |
| 219 | DataInputStream ret = new DataInputStream(new GZIPInputStream(new ByteArrayInputStream(data))); |
| 220 | // debug("READ", x, z, " = found"); |
| 221 | return ret; |
| 222 | } else if (version == RegionFile.VERSION_DEFLATE) { |
| 223 | byte[] data = new byte[length - 1]; |
| 224 | this.file.read(data); |
| 225 | DataInputStream ret = new DataInputStream(new InflaterInputStream(new ByteArrayInputStream(data))); |
| 226 | // debug("READ", x, z, " = found"); |
| 227 | return ret; |
| 228 | } |
| 229 | |
| 230 | this.debug("read", x, z, "unknown version " + version); |
| 231 | return null; |
| 232 | } catch (IOException e) { |
| 233 | this.debug("read", x, z, "exception"); |
| 234 | return null; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | public DataOutputStream getChunkDataOutputStream(int x, int z) { |
| 239 | if (this.outOfBounds(x, z)) { |