Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package csc143.backmask;
- import java.io.*;
- import java.util.*;
- import csc143.data_structures.*;
- /**
- * @author Vita Wiebe
- * @version PA6
- * A class which reads the textual input from a DAT file,
- * reverses it, and thereby produces a "backmasked" or "unbackmasked" audio file.
- */
- public class UnBackMasker {
- // Fields:
- // Create new input file, read from input file using Scanner.io or something
- // Declare only, take out initialization
- private File inFile;
- //PrintWriter or PrintStream for output file (written to)
- private File outFile;
- /**
- * Class constructor.
- * Will do the "work" of reversing the appropriate info from the source
- * file and writing it to the output file.
- * Returns a "backwards" version of the .dat file we originally input.
- * @param File inFile, the file to be opened and read from.
- * @param File outFile, the file to be created and written to from input.
- * @return A .dat file with the displacement info written in opposite order
- */
- public UnBackMasker(File inFile, File outFile)
- throws IOException {
- // Get input file (to be read from)
- inFile = new File("" + inFile + "");
- FileReader fr=new FileReader(inFile);
- BufferedReader br = new BufferedReader(fr);
- Scanner scan = new Scanner(inFile);
- // Open input file
- // Create output file (to be written to)
- outFile = new File("" + outFile + "");
- // Write headers from inFile to outFile directly
- FileWriter fw = new FileWriter(outFile);
- BufferedWriter bw = new BufferedWriter(fw);
- // Reads first header line.
- String header1 = new String(br.readLine());
- // Reads second header line.
- String header2 = new String(br.readLine());
- // We write each header line on its own line in outFile.
- bw.write(header1);
- bw.newLine();
- bw.write(header2);
- bw.newLine();
- // Create n UnboundedArrayQueue to keep the content of time column.
- UnboundedArrayQueue timeQ = new UnboundedArrayQueue(100);
- // Create an UnboundedArrayStack to keep the content of displacement column.
- UnboundedArrayStack dispStack = new UnboundedArrayStack(100);
- // Count is the number of elements stored in each data structure.
- int lines = 0;
- while(scan.hasNextLine()) {
- String time = scan.next();
- String disp = scan.next();
- timeQ.add(time);
- dispStack.push(disp);
- lines++;
- scan.nextLine();
- }
- // Create a BoundedArrayStack to keep the contents of displacement col.
- // Write time column from inFile to queue
- // Read from queue into outFile to recreate time column in same order
- // Write displacement column from inFile to stack
- // Read displacements from stack and write into outFile
- // (this will cause them to be in reverse order)
- // Close input file (don't forget)
- }
- /**
- * Will accept user input into args array,
- * use these Strings to specify an input file to read from
- * and an output file to write to, then uses these
- * files as arguments "in" and "out" to the class
- * constructor's respective "inFile" and "outFile" params.
- */
- public static void main(String[] args)
- throws IllegalArgumentException {
- File in;
- File out;
- // Main report # of args errors,
- // UnBackMasker report "file not found" errors, System.err useage
- //Scanner scan = new Scanner(System.in);
- if (args.length != 2) {
- throw new IllegalArgumentException("Only accepts two arguments.");
- }else{
- in = new File(args[0]);
- out = new File(in, args[1]);
- try {
- new UnBackMasker(in, out);
- }catch(IOException e){
- System.err.println("Useage: UnBackMasker" + in + out);
- return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement