Question

In: Computer Science

In this programming assignment, you will implement a SimpleWebGet program for non- interactive download of files...

In this programming assignment, you will implement a SimpleWebGet program for non- interactive download of files from the Internet. This program is very similar to wget utility in Unix/Linux environment.The synopsis of SimpleWebGet is: java SimpleWebGet URL. The URL could be either a valid link on the Internet, e.g., www.asu.edu/index.html, or gaia.cs.umass.edu/wireshark-labs/alice.txt or an invalid link, e.g., www.asu.edu/inde.html. ww.asu.edu/inde.html. The output of SimpleWebGet for valid links should be the same as wget utility in Linux, except the progress line highlighted within the red rectangle: 100% [============================>] 152,138 248.78K/s.The outputs of SimpleWebGet for not-found hosts or non-found files should be the same as wget utility in Linux. Dynamics progress bar and percentages are shown.The program could successfully download a HTML file or other Web objects.The program could report the Resolving line.The program could report the Connecting line.The program could report the HTTP request and response line.The program could report the Length line.The program could report the accurate data transfer rate.The program could handle the host/servname not known error. The program could handle the file not found error.

Solutions

Expert Solution

CODE:

/The code with comments

package Nov20;
import java.io.*;
import java.net.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Scanner;

public class JavaWGetCommand
{
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the URL to be downloaded like WGET of Unix: ");
String inputUrl = sc.next();
InputStream inputStream = null;
try {
//input stream of the URL link
inputStream = new URL(inputUrl).openStream();
//copy the content of URL file to your local pc file.
Files.copy(inputStream, Paths.get("C:\\Users\\{your username here please}\\myFile.txt"), StandardCopyOption.REPLACE_EXISTING);
}catch (MalformedURLException mfe){ //exception handling similar to Wget command.
System.out.println("The URL is not valid");
mfe.printStackTrace();
}catch (IOException ioe){
ioe.printStackTrace();
}catch (Exception e){
e.printStackTrace();
}finally {
if(inputStream!=null)
inputStream.close();
}
}

}


Related Solutions

This assignment uses a combination of classes and arrays. Instructions: 1) download the 3 program files...
This assignment uses a combination of classes and arrays. Instructions: 1) download the 3 program files into a new C++ project.    NOTE: if your IDE does not allow you to create projects - or you are not sure how to do it - then you may combine the two cpp files into a single file. 2) Complete the program by adding code the the class methods. You may want to study the existing code first to get a feel...
Download and review the PrintNumbers.java program provided in the homework files. This program contains a method...
Download and review the PrintNumbers.java program provided in the homework files. This program contains a method which is designed to read in a number from the user and print it to the screen. The parameter to the method specifies whether the number might contain decimals. There are two helper methods- one that reads in an integer and one that reads in a double. Run the program. As written, it works as long as the user enters what they are supposed...
This is C# programming. In Chapter 2, you created an interactive application named GreenvilleRevenue. The program...
This is C# programming. In Chapter 2, you created an interactive application named GreenvilleRevenue. The program prompts a user for the number of contestants entered in this year’s and last year’s Greenville Idol competition, and then it displays the revenue expected for this year’s competition if each contestant pays a $25 entrance fee. The programs also display a statement that compares the number of contestants each year. Now, replace that statement with one of the following messages: If the competition...
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
Assignment 1 – Writing a Linux Utility Program Instructions For this programming assignment you are going...
Assignment 1 – Writing a Linux Utility Program Instructions For this programming assignment you are going to implement a simple C version of the UNIX cat program called lolcat. The cat program allows you to display the contents of one or more text files. The lolcat program will only display one file. The correct usage of your program should be to execute it on the command line with a single command line argument consisting of the name you want to...
This program focuses on programming with Java Collections classes. You will implement a module that finds...
This program focuses on programming with Java Collections classes. You will implement a module that finds a simplified Levenshtein distance between two words represented by strings. Your program will need support files LevenDistanceFinder.Java, dictionary.txt, while you will be implementing your code in the LevenDistanceFinder.java file. INSTRUCTIONS The Levenshtein distance, named for it's creator Vladimir Levenshtein, is a measure of the distance between two words. The edit distance between two strings is the minimum number of operations that are needed to...
Please do this in java program. In this assignment you are required to implement the Producer...
Please do this in java program. In this assignment you are required to implement the Producer Consumer Problem . Assume that there is only one Producer and there is only one Consumer. 1. The problem you will be solving is the bounded-buffer producer-consumer problem. You are required to implement this assignment in Java This buffer can hold a fixed number of items. This buffer needs to be a first-in first-out (FIFO) buffer. You should implement this as a Circular Buffer...
Description: In this assignment, you will implement a deterministic finite automata (DFA) using C++ programming language...
Description: In this assignment, you will implement a deterministic finite automata (DFA) using C++ programming language to extract all matching patterns (substrings) from a given input DNA sequence string. The alphabet for generating DNA sequences is {A, T, G, C}. Write a regular expression that represents all DNA strings that begin with ‘A’ and end with ‘T’. Note: assume empty string is not a valid string. Design a deterministic finite automaton to recognize the regular expression. Write a program which...
Design and implement an interactive program named trip.c that collects information about the user's car and...
Design and implement an interactive program named trip.c that collects information about the user's car and planned travel, and reports back useful information. The dialog below shows exactly what data should be collected as input and reported as output. Some Hints to get started /* Not tested not complete code Just to get you started */ #include /* FUNCTION PROTOTYPES */ void WelcomeMessage(); void AskUserForInput(); /* ask and check whether user wants to continue if wants to continue gather information...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT