Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. package rs.raf.os.test;
  2.  
  3. import rs.raf.os.fat.FAT16;
  4. import rs.raf.os.fat.FATException;
  5.  
  6. public class MockFAT implements FAT16 {
  7.  
  8.     private int clusterWidth;
  9.     private int clusterCount;
  10.     private int[] clusterData;
  11.    
  12.     public MockFAT(int clusterWidth) {
  13.         this.clusterWidth = clusterWidth;
  14.         this.clusterCount = 0xFFED;
  15.     }
  16.    
  17.     public MockFAT(int clusterWidth, int clusterCount) {
  18.         if (clusterCount > 0xFFED) {
  19.             System.err.println("Uneo si mnogo brt " + clusterCount);
  20.             this.clusterCount = 0xFFED;
  21.         }
  22.        
  23.         this.clusterWidth = clusterWidth;
  24.         this.clusterCount = clusterCount;
  25.         this.clusterData = new int[clusterCount + 2];
  26.     }
  27.    
  28.     @Override
  29.     public int getEndOfChain() {
  30.         return 0xFFF8;
  31.     }
  32.  
  33.     @Override
  34.     public int getClusterCount() {
  35.         return clusterCount;
  36.     }
  37.  
  38.     @Override
  39.     public int getClusterWidth() {
  40.         return clusterWidth;
  41.     }
  42.  
  43.     @Override
  44.     public int readCluster(int clusterID) throws FATException {
  45.         if (clusterID < 2 || clusterID >= clusterData.length) {
  46.             throw new FATException("Ne valja read");
  47.         }
  48.        
  49.         return clusterData[clusterID];
  50.     }
  51.  
  52.     @Override
  53.     public void writeCluster(int clusterID, int valueToWrite) throws FATException {
  54.         if (clusterID < 2 || clusterID >= clusterData.length) {
  55.             throw new FATException("Ne valja write");
  56.         }
  57.        
  58.         if (valueToWrite > 0xFFED && valueToWrite != 0xFFF8) {
  59.             throw new FATException("Ne valja write 2");
  60.         }
  61.        
  62.         clusterData[clusterID] = valueToWrite;
  63.     }
  64.  
  65.     @Override
  66.     public String getString() {
  67.         StringBuilder sb = new StringBuilder();
  68.         sb.append("[");
  69.        
  70.         for (int i = 2; i < clusterData.length - 1; i++)
  71.             sb.append(clusterData[i] + "|");
  72.  
  73.         sb.append(clusterData[clusterData.length - 1] + "]");
  74.         return sb.toString();
  75.     }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement