Advertisement
Vita_Harvey

UnBackMasker_B

Feb 17th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.72 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.       // Create a BoundedArrayQueue to keep the content of time column.
  58.       BoundedArrayQueue timeQ = new BoundedArrayQueue(100);
  59.       BoundedArrayStack dispStack = new BoundedArrayStack(100);
  60.       int count = 0;
  61.       while(br.readLine() != null) {
  62.          timeQ.add(br.readLine());
  63.          count++;
  64.       }
  65.             while(br.hasNextLine() != null) {
  66.          String currentString = .inFile;
  67.          dispStack.push(  
  68.    
  69.    
  70.    // Create a BoundedArrayStack to keep the contents of displacement col.
  71.    // Write time column from inFile to queue
  72.    // Read from queue into outFile to recreate time column in same order
  73.    // Write displacement column from inFile to stack
  74.    // Read displacements from stack and write into outFile
  75.    //    (this will cause them to be in reverse order)  
  76.    // Close input file (don't forget)
  77.    
  78.    }
  79.    
  80.    /**
  81.     * Will accept user input into args array,
  82.     * use these Strings to specify an input file to read from
  83.     * and an output file to write to, then uses these
  84.     * files as arguments "in" and "out" to the class
  85.     * constructor's respective "inFile" and "outFile" params.
  86.     */
  87.    public static void main(String[] args) {
  88.    
  89.       File in;
  90.       File out;
  91.      
  92.       // Main report # of args errors,
  93.       // UnBackMasker report "file not found" errors, System.err useage
  94.       //Scanner scan = new Scanner(System.in);
  95.       if (args.length != 2) {
  96.          throw new IllegalArgumentException("Only accepts two arguments.");
  97.       }else{
  98.             in = new File(args[0]);
  99.             out = new File(in, args[1]);
  100.             try {
  101.                new UnBackMasker(in, out);
  102.             }catch(IOException e){
  103.                System.out.println("Something went wrong.");
  104.             }
  105.       }    
  106.    }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement