public DataInputStream getChunkDataInputStream(int i, int j) { if (outOfBounds(i, j)) { debugln("READ", i, j, "out of bounds"); return(null); } try { int k = getOffset(i, j); if (k == 0) { return(null); } int l = k >> 8; int i1 = k & 0xff; if (l + i1 > sectorFree.size()) { debugln("READ", i, j, "invalid sector"); return(null); } dataFile.seek(l * 4096); int j1 = dataFile.readInt(); if (j1 > 4096 * i1) { debugln("READ", i, j, (new StringBuilder()).append("invalid length: ").append(j1).append(" > 4096 * ").append(i1). toString()); return(null); } byte byte0 = dataFile.readByte(); if (byte0 == 1) { var abyte0 = new byte[j1 - 1]; dataFile.read(abyte0); var datainputstream = new DataInputStream(new GZIPInputStream(new ByteArrayInputStream(abyte0))); return(datainputstream); } if (byte0 == 2) { var abyte1 = new byte[j1 - 1]; dataFile.read(abyte1); var datainputstream1 = new DataInputStream(new InflaterInputStream(new ByteArrayInputStream(abyte1))); return(datainputstream1); } else { debugln("READ", i, j, (new StringBuilder()).append("unknown version ").append(byte0).toString()); return(null); } } catch (IOException) { debugln("READ", i, j, "exception"); } return(null); }
public virtual DataInputStream GetChunkDataInputStream(int x, int z) { if (OutOfBounds(x, z)) { return(null); } try { int offset = GetOffset(x, z); if (offset == 0) { return(null); } int sectorNumber = offset >> 8; int numSectors = offset & 0xFF; if (sectorNumber + numSectors > _sectorFree.Count) { return(null); } _file.seek(sectorNumber * SectorBytes); int length = _file.readInt(); if (length > SectorBytes * numSectors) { return(null); } byte version = _file.readByte(); if (version == VersionGzip) { byte[] data = new byte[length - 1]; _file.read(data); return(new DataInputStream(new ByteArrayInputStream(data))); } if (version != VersionDeflate) { return(null); } { byte[] data = new byte[length - 1]; _file.read(data); return(new DataInputStream(new InflaterInputStream(new ByteArrayInputStream(data)))); } } catch (Exception) { return(null); } }