public DataInputStream getChunkInputStream(int x, int z) {
        try {
            byte[] data;
            int read;
            int offset;
            int length;

            synchronized (file) {
                file.seek((7 * (x + (z * 32))) + 5);
                offset = file.readInt();
                length = ((file.readByte() << 16) & 0x00FF0000) | ((file.readByte() << 8) & 0x0000FF00) | (file.readByte() & 0x000000FF);
                if (offset < 7173 || length <= 0) {
                    // Either way, it's invalid
                    return null;
                }

                file.seek(offset);
                data = new byte[length];
                read = file.read(data);
            }

            if (read < length) {
                throw new DonkeyRegionException("(" + hardFile.getName() + ":" + x + ", " + z + ") Did not read all bytes for chunk! Expected " + length + " bytes, read " + read + " bytes");
            }

            if (hasChunkCompression) {
                return new DataInputStream(new BufferedInputStream(new GZIPInputStream(new ByteArrayInputStream(data))));
            } else {
                return new DataInputStream(new BufferedInputStream(new ByteArrayInputStream(data)));
            }
        } catch (IOException ex) {
            ex.printStackTrace();
            return null;
        }
    }