Advertisement
Guest User

read

a guest
Jul 30th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. public void read() throws IOException, IllegalStateException {
  2. // Determines the location of the file and generates one based off of the path
  3. File file = FILE_LOCATION.toFile();
  4.  
  5. // Determines if the file exists, and discontinues if it does not
  6. if (!file.exists()) {
  7. //throw some no file found exception if necessary
  8. return;
  9. }
  10.  
  11. // Creates a new byte array with the information from the file
  12. byte[] buffer = StreamLoader.getBytesFromFile(file);
  13.  
  14. // Creates a new stream using the byte buffer as the backing array
  15. Stream stream = new Stream(buffer);
  16.  
  17. // Continues to read from the buffer until it can no longer
  18. while (stream.currentOffset < buffer.length) {
  19.  
  20. // Reads the first byte that determines what data we're reading
  21. int opcode = stream.readSignedByte();
  22.  
  23.  
  24.  
  25. // Here we read information from the cache depending on the opcode
  26. switch (opcode) {
  27.  
  28. case 0:
  29. String username = stream.readString();
  30. break;
  31.  
  32. case 1:
  33. String password = stream.readString();
  34. break;
  35.  
  36. default:
  37. throw new IllegalStateException("Opcode #"+opcode+" does not exist.");
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement