MCPcopy Create free account
hub / github.com/Garten/sourcecraft / RegionFile

Method RegionFile

src/minecraft/reader/RegionFile.java:96–160  ·  view source on GitHub ↗
(File path)

Source from the content-addressed store, hash-verified

94 private long lastModified = 0;
95
96 public RegionFile(File path) {
97 this.offsets = new int[RegionFile.SECTOR_INTS];
98 this.chunkTimestamps = new int[RegionFile.SECTOR_INTS];
99
100 this.fileName = path;
101
102 this.sizeDelta = 0;
103
104 try {
105 if (path.exists()) {
106 this.lastModified = path.lastModified();
107 }
108
109 this.file = new RandomAccessFile(path, "rw");
110
111 if (this.file.length() < RegionFile.SECTOR_BYTES) {
112 /* we need to write the chunk offset table */
113 for (int i = 0; i < RegionFile.SECTOR_INTS; ++i) {
114 this.file.writeInt(0);
115 }
116 // write another sector for the timestamp info
117 for (int i = 0; i < RegionFile.SECTOR_INTS; ++i) {
118 this.file.writeInt(0);
119 }
120
121 this.sizeDelta += RegionFile.SECTOR_BYTES * 2;
122 }
123
124 if ((this.file.length() & 0xfff) != 0) {
125 /* the file size is not a multiple of 4KB, grow it */
126 for (int i = 0; i < (this.file.length() & 0xfff); ++i) {
127 this.file.write((byte) 0);
128 }
129 }
130
131 /* set up the available sector map */
132 int nSectors = (int) this.file.length() / RegionFile.SECTOR_BYTES;
133 this.sectorFree = new ArrayList<>(nSectors);
134
135 for (int i = 0; i < nSectors; ++i) {
136 this.sectorFree.add(true);
137 }
138
139 this.sectorFree.set(0, false); // chunk offset table
140 this.sectorFree.set(1, false); // for the last modified info
141
142 this.file.seek(0);
143 for (int i = 0; i < RegionFile.SECTOR_INTS; ++i) {
144 int offset = this.file.readInt();
145// System.out.println(this.fileName.toString() + " offset " + i + " | " + offset);
146 this.offsets[i] = offset;
147 if (offset != 0 && (offset >> 8) + (offset & 0xFF) <= this.sectorFree.size()) {
148 for (int sectorNum = 0; sectorNum < (offset & 0xFF); ++sectorNum) {
149 this.sectorFree.set((offset >> 8) + sectorNum, false);
150 }
151 }
152 }
153 for (int i = 0; i < RegionFile.SECTOR_INTS; ++i) {

Callers

nothing calls this directly

Calls 5

lastModifiedMethod · 0.80
setMethod · 0.80
readIntMethod · 0.80
writeMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected