Use the Java 7 file API in the IndexedFileSystem.

This commit is contained in:
Major-
2014-08-10 04:28:53 +01:00
parent 6cb3996fbf
commit 2f0a062929
5 changed files with 19 additions and 20 deletions
+2 -2
View File
@@ -7,9 +7,9 @@ import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import java.io.File;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.file.Paths;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -169,7 +169,7 @@ public final class Server {
serviceManager.startAll();
int releaseNo = context.getRelease().getReleaseNumber();
IndexedFileSystem fs = new IndexedFileSystem(new File("data/fs/" + releaseNo), true);
IndexedFileSystem fs = new IndexedFileSystem(Paths.get("data/fs/", Integer.toString(releaseNo)), true);
World.getWorld().init(releaseNo, fs, manager);
}
+10 -12
View File
@@ -1,11 +1,12 @@
package org.apollo.fs;
import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.zip.CRC32;
/**
@@ -43,7 +44,7 @@ public final class IndexedFileSystem implements Closeable {
* @param readOnly Indicates whether the file system will be read only or not.
* @throws FileNotFoundException If the data files could not be found.
*/
public IndexedFileSystem(File base, boolean readOnly) throws FileNotFoundException {
public IndexedFileSystem(Path base, boolean readOnly) throws FileNotFoundException {
this.readOnly = readOnly;
detectLayout(base);
}
@@ -71,25 +72,22 @@ public final class IndexedFileSystem implements Closeable {
* @param base The base directory.
* @throws FileNotFoundException If the data files could not be found.
*/
private void detectLayout(File base) throws FileNotFoundException {
private void detectLayout(Path base) throws FileNotFoundException {
int indexCount = 0;
for (int index = 0; index < indices.length; index++) {
File f = new File(base.getAbsolutePath() + "/main_file_cache.idx" + index);
if (f.exists() && !f.isDirectory()) {
Path idx = base.resolve("main_file_cache.idx" + index);
if (Files.exists(idx) && !Files.isDirectory(idx)) {
indexCount++;
indices[index] = new RandomAccessFile(f, readOnly ? "r" : "rw");
indices[index] = new RandomAccessFile(idx.toFile(), readOnly ? "r" : "rw");
}
}
if (indexCount <= 0) {
throw new FileNotFoundException("No index file(s) present.");
}
File oldEngineData = new File(base.getAbsolutePath() + "/main_file_cache.dat");
File newEngineData = new File(base.getAbsolutePath() + "/main_file_cache.dat2");
if (oldEngineData.exists() && !oldEngineData.isDirectory()) {
data = new RandomAccessFile(oldEngineData, readOnly ? "r" : "rw");
} else if (newEngineData.exists() && !oldEngineData.isDirectory()) {
data = new RandomAccessFile(newEngineData, readOnly ? "r" : "rw");
Path resources = base.resolve("main_file_cache.dat");
if (Files.exists(resources) && !Files.isDirectory(resources)) {
data = new RandomAccessFile(resources.toFile(), readOnly ? "r" : "rw");
} else {
throw new FileNotFoundException("No data file present.");
}
+2 -2
View File
@@ -2,8 +2,8 @@ package org.apollo.tools;
import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.nio.file.Paths;
import org.apollo.fs.IndexedFileSystem;
import org.apollo.fs.decoder.ItemDefinitionDecoder;
@@ -1172,7 +1172,7 @@ public final class EquipmentUpdater {
try (DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("data/equipment-"
+ release + ".dat")));
IndexedFileSystem fs = new IndexedFileSystem(new File("data/fs/" + release), true)) {
IndexedFileSystem fs = new IndexedFileSystem(Paths.get("data/fs/", release), true)) {
ItemDefinitionDecoder decoder = new ItemDefinitionDecoder(fs);
ItemDefinition[] definitions = decoder.decode();
ItemDefinition.init(definitions);
+2 -2
View File
@@ -2,8 +2,8 @@ package org.apollo.tools;
import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
@@ -32,7 +32,7 @@ public final class NoteUpdater {
try (DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("data/note-"
+ release + ".dat")));
IndexedFileSystem fs = new IndexedFileSystem(new File("data/fs/" + release), true)) {
IndexedFileSystem fs = new IndexedFileSystem(Paths.get("data/fs/", release), true)) {
ItemDefinitionDecoder decoder = new ItemDefinitionDecoder(fs);
ItemDefinition[] defs = decoder.decode();
ItemDefinition.init(defs);
+3 -2
View File
@@ -1,6 +1,7 @@
package org.apollo.update;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
@@ -65,7 +66,7 @@ public final class UpdateService extends Service {
public void start() {
int release = getContext().getRelease().getReleaseNumber();
try {
File base = new File("./data/fs/" + release + "/");
Path base = Paths.get("data/fs/", Integer.toString(release));
for (int i = 0; i < THREADS_PER_REQUEST_TYPE; i++) {
workers.add(new JagGrabRequestWorker(dispatcher, new IndexedFileSystem(base, true)));
workers.add(new OnDemandRequestWorker(dispatcher, new IndexedFileSystem(base, true)));