Advertisement
Vita_Harvey

UnBackMasker_C

Feb 17th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.05 KB | None | 0 0
  1. package csc143.backmask;
  2.  
  3.  
  4. import java.io.*;
  5. import java.util.*;
  6. import csc143.data_structures.*;
  7.  
  8. /**
  9.  * @author Vita Wiebe
  10.  * @version PA6
  11.  * A class which reads the textual input from a DAT file,
  12.  * reverses it, and thereby produces a "backmasked" or "unbackmasked" audio file.
  13.  */
  14. public class UnBackMasker {
  15.  
  16.    // Fields:
  17.    // Create new input file, read from input file using Scanner.io or something
  18.    // Declare only, take out initialization
  19.    private File inFile;
  20.    //PrintWriter or PrintStream for output file (written to)
  21.    private File outFile;
  22.    
  23.    /**
  24.     * Class constructor.
  25.     * Will do the "work" of reversing the appropriate info from the source
  26.     * file and writing it to the output file.
  27.     * Returns a "backwards" version of the .dat file we originally input.
  28.     * @param File inFile, the file to be opened and read from.
  29.     * @param File outFile, the file to be created and written to from input.
  30.     * @return A .dat file with the displacement info written in opposite order
  31.     */
  32.    public UnBackMasker(File inFile, File outFile)
  33.       throws IOException {
  34.    
  35.       // Get input file (to be read from)
  36.       inFile = new File("" + inFile + "");
  37.       FileReader fr=new FileReader(inFile);
  38.       BufferedReader br = new BufferedReader(fr);
  39.       Scanner scan = new Scanner(inFile);
  40.       // Open input file
  41.       // Create output file (to be written to)
  42.       outFile = new File("" + outFile + "");
  43.      
  44.       // Write headers from inFile to outFile directly
  45.       FileWriter fw = new FileWriter(outFile);
  46.       BufferedWriter bw = new BufferedWriter(fw);
  47.      
  48.       // Reads first header line.
  49.       String header1 = new String(br.readLine());
  50.       // Reads second header line.
  51.       String header2 = new String(br.readLine());
  52.       // We write each header line on its own line in outFile.
  53.       bw.write(header1);
  54.       bw.newLine();
  55.       bw.write(header2);
  56.       bw.newLine();
  57.      
  58.       // Create n UnboundedArrayQueue to keep the content of time column.
  59.       UnboundedArrayQueue timeQ = new UnboundedArrayQueue(100);
  60.       // Create an UnboundedArrayStack to keep the content of displacement column.
  61.       UnboundedArrayStack dispStack = new UnboundedArrayStack(100);
  62.      
  63.       // Count is the number of elements stored in each data structure.
  64.       int lines = 0;
  65.      
  66.       while(scan.hasNextLine()) {
  67.          String time = scan.next();
  68.          String disp = scan.next();
  69.          timeQ.add(time);
  70.          dispStack.push(disp);
  71.          lines++;
  72.          scan.nextLine();                          
  73.       }
  74.      
  75.      
  76.      
  77.      
  78.      
  79.            
  80.    
  81.    
  82.    // Create a BoundedArrayStack to keep the contents of displacement col.
  83.    // Write time column from inFile to queue
  84.    // Read from queue into outFile to recreate time column in same order
  85.    // Write displacement column from inFile to stack
  86.    // Read displacements from stack and write into outFile
  87.    //    (this will cause them to be in reverse order)  
  88.    // Close input file (don't forget)
  89.    
  90.    }
  91.    
  92.    /**
  93.     * Will accept user input into args array,
  94.     * use these Strings to specify an input file to read from
  95.     * and an output file to write to, then uses these
  96.     * files as arguments "in" and "out" to the class
  97.     * constructor's respective "inFile" and "outFile" params.
  98.     */
  99.    public static void main(String[] args)
  100.       throws IllegalArgumentException {
  101.    
  102.       File in;
  103.       File out;
  104.      
  105.       // Main report # of args errors,
  106.       // UnBackMasker report "file not found" errors, System.err useage
  107.       //Scanner scan = new Scanner(System.in);
  108.       if (args.length != 2) {
  109.          throw new IllegalArgumentException("Only accepts two arguments.");
  110.       }else{
  111.             in = new File(args[0]);
  112.             out = new File(in, args[1]);
  113.             try {
  114.                new UnBackMasker(in, out);
  115.             }catch(IOException e){
  116.                System.err.println("Useage: UnBackMasker" + in + out);
  117.                return;
  118.             }
  119.       }    
  120.    }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement