Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void read() throws IOException, IllegalStateException {
- // Determines the location of the file and generates one based off of the path
- File file = FILE_LOCATION.toFile();
- // Determines if the file exists, and discontinues if it does not
- if (!file.exists()) {
- //throw some no file found exception if necessary
- return;
- }
- // Creates a new byte array with the information from the file
- byte[] buffer = StreamLoader.getBytesFromFile(file);
- // Creates a new stream using the byte buffer as the backing array
- Stream stream = new Stream(buffer);
- // Continues to read from the buffer until it can no longer
- while (stream.currentOffset < buffer.length) {
- // Reads the first byte that determines what data we're reading
- int opcode = stream.readSignedByte();
- // Here we read information from the cache depending on the opcode
- switch (opcode) {
- case 0:
- String username = stream.readString();
- break;
- case 1:
- String password = stream.readString();
- break;
- default:
- throw new IllegalStateException("Opcode #"+opcode+" does not exist.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement