1 /* Fetch an URL's contents.
2 * Copyright (C) 2001, 2008, 2015 Free Software Foundation, Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * Fetch an URL's contents and emit it to standard output.
25 * Exit code: 0 = success
28 * @author Bruno Haible
31 // Use a separate thread to signal a timeout error if the URL cannot
32 // be accessed and completely read within a given amount of time.
33 private static long timeout = 30*1000; // 30 seconds
35 private Thread timeoutThread;
36 public void fetch (String s) {
40 } catch (MalformedURLException e) {
53 } catch (InterruptedException e) {
57 timeoutThread.start();
59 InputStream istream = new BufferedInputStream(url.openStream());
60 OutputStream ostream = new BufferedOutputStream(System.out);
62 int b = istream.read();
69 } catch (IOException e) {
70 //e.printStackTrace();
75 public static void main (String[] args) {
78 (new GetURL()).fetch(args[0]);