-
Notifications
You must be signed in to change notification settings - Fork 0
Chunk IO
By default, all chunks are saved in a folder, called chunks
. To change that path, you have to understand, that chunk systems use several classes to do IO stuff: ChunkSaver
and ChunkLoader
. You can modify these classes very easily:
// Fetch the IO classes from our recently created chunk system
ChunkSaver saver = chunSystem.getSaver();
ChunkLoader loader = chunkSystem.getLoader();
// Lets change the path
final String PATH = "data/";
saver.setPath(PATH);
loader.setPath(PATH);
Additionally you can modify the way, how chunks should be saved. The first way is to modify the data stream between file and system, by defining providers. chunx contains two stream providers: InputStreamProvider
and OutputStreamProvider
. For instance, the default output stream provider looks like this:
public class SimpleInputStreamProvider implements InputStreamProvider {
@Override
public InputStream getInputStream(String file) throws IOException {
return new FileInputStream(file);
}
}
As you can see, it's a very simple implementation. You could integrate encryption or other stream work like zipping into a .zip/.rar file. Everything is on your own!
Additionally you can modify the name of the chunks as well. chunx providers a so called FileNameConverter
class which does the work for you. Here is a basic implementation:
public class SimpleFileNameConverter implements FileNameConverter {
public static final String FILE_PREFIX = "chunk";
@Override
public String convert(int indexX, int indexY) {
return FILE_PREFIX + '_' + indexX + '_' + indexY;
}
}
A sample file name for a chunk on index -1,18 would be: chunk_-1_18
. Furthermore there is a more detailed implementation, called EncryptedFileNameConverter
. It converts chunk indexes to MD5 checksums and vise versa, to avoid manual modifications of chunk files.