Skip to content

Instantly share code, notes, and snippets.

@standy66
Created October 9, 2014 14:06
Show Gist options
  • Save standy66/89726e008e26954ad46d to your computer and use it in GitHub Desktop.
Save standy66/89726e008e26954ad46d to your computer and use it in GitHub Desktop.
channel = new FileInputStream(dbFilePath).getChannel();
ByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
try {
while (buffer.remaining() > 0) {
int keySize = buffer.getInt();
byte[] key = new byte[keySize];
buffer.get(key);
int valueSize = buffer.getInt();
byte[] value = new byte[valueSize];
buffer.get(value);
cache.put(new String(key, "UTF-8"), new String(value, "UTF-8"));
}
} catch (BufferUnderflowException e) {
System.err.println("Corrupted file");
System.exit(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment