2017-07-28_15:54 by Christopher Woodruff
There are few things to point out here. First, YouTube uses '+' for separating search words. So, a search may look like http://www.youtube.com/results?search_query=Red+vs+Blue
We have to make sure the user is able to naturally enter a search term with more than one word and have that entered into the end of the given URL correctly. Second, I believe that the wait() timer gets placed into the code to allow the HTML to be written for the file. In other words: Create the new html, YouTube loads the page; take the html code from THAT page; save it into a file; give the computer/internet enough time to copy-paste the code; program should terminate after.
I'm not going to show the full code used, but here's a snippet to help:
/**
* The fileWriter() method creates a file of any writable type (text, html, etc) and
* places it into the desired directory with the given file name. It takes a String
* argument as the data to be input into the file. This method is intended to be
* flexible for future use.
*
* @param path The file's destination path (Ex: C:/myfolder/) The last forward slash
* (/) is necessary. It will be combined with the file name to get the final location-
* name combination.
* @param fileName The name of the file including the extension. (Ex: myWebPage.html)
* @param data Any data to be passed into the file. This is meant to be text based
* data only.
* @throws IOException
* @throws InterruptedException
*/
public synchronized void fileWriter(String path, String fileName, String data) throws IOException{
BufferedWriter bw = new BufferedWriter(new FileWriter(path + fileName));
try {
...write the data into the file
notify();
}
catch (IOException e) {
e.printStackTrace();
}
}
/**
* Get input from the user using Scanner and pass it through the other methods to
* eventually output a HTML file.
*/
public synchronized void run(){
...use WbPageReader class
readKeyword();
try {
...send the information to the fileWriter() method.
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Check your file."); //Just a friendly message to let them know when it's done.
}
Notice both of those methods were not 'static' but 'synchronized'. This is necessary to use the notify() and wait() methods.
/**
* The fileWriter() method creates a file of any writable type (text, html, etc) and
* places it into the desired directory with the given file name. It takes a String
* argument as the data to be input into the file. This method is intended to be
* flexible for future use.
*
* @param path The file's destination path (Ex: C:/myfolder/) The last forward slash
* (/) is necessary. It will be combined with the file name to get the final location-
* name combination.
* @param fileName The name of the file including the extension. (Ex: myWebPage.html)
* @param data Any data to be passed into the file. This is meant to be text based
* data only.
* @throws IOException
* @throws InterruptedException
*/
public synchronized void fileWriter(String path, String fileName, String data) throws IOException{
BufferedWriter bw = new BufferedWriter(new FileWriter(path + fileName));
try {
...write the data into the file
notify();
}
catch (IOException e) {
e.printStackTrace();
}
}
/**
* Get input from the user using Scanner and pass it through the other methods to
* eventually output a HTML file.
*/
public synchronized void run(){
...use WbPageReader class
readKeyword();
try {
...send the information to the fileWriter() method.
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Check your file."); //Just a friendly message to let them know when it's done.
}
Notice both of those methods were not 'static' but 'synchronized'. This is necessary to use the notify() and wait() methods.