Thread: [Japi-cvs] SF.net SVN: japi: [386] tools/jwget/trunk
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2007-06-09 18:35:48
|
Revision: 386 http://svn.sourceforge.net/japi/?rev=386&view=rev Author: christianhujer Date: 2007-06-09 11:35:47 -0700 (Sat, 09 Jun 2007) Log Message: ----------- Added jwget implementation. Modified Paths: -------------- tools/jwget/trunk/jwget.iml Added Paths: ----------- tools/jwget/trunk/src/ tools/jwget/trunk/src/net/ tools/jwget/trunk/src/net/sf/ tools/jwget/trunk/src/net/sf/japi/ tools/jwget/trunk/src/net/sf/japi/jwget/ tools/jwget/trunk/src/net/sf/japi/jwget/JWGet.java Modified: tools/jwget/trunk/jwget.iml =================================================================== --- tools/jwget/trunk/jwget.iml 2007-06-09 18:30:55 UTC (rev 385) +++ tools/jwget/trunk/jwget.iml 2007-06-09 18:35:47 UTC (rev 386) @@ -30,7 +30,7 @@ </component> <component name="copyright"> <Base> - <setting name="state" value="1" /> + <setting name="state" value="0" /> </Base> <LanguageOptions name="$TEMPLATE$"> <option name="templateOptions"> @@ -45,7 +45,7 @@ <option name="filler" value=" " /> </value> </option> - <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> + <option name="notice" value="JWGet is a simple Java implementation of the unix command wget. Copyright (C) &#36;today.year Christian Hujer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA." /> <option name="keyword" value="Copyright" /> <option name="fileTypeOverride" value="4" /> <option name="relativeBefore" value="true" /> Added: tools/jwget/trunk/src/net/sf/japi/jwget/JWGet.java =================================================================== --- tools/jwget/trunk/src/net/sf/japi/jwget/JWGet.java (rev 0) +++ tools/jwget/trunk/src/net/sf/japi/jwget/JWGet.java 2007-06-09 18:35:47 UTC (rev 386) @@ -0,0 +1,75 @@ +/* + * JWGet is a simple Java implementation of the unix command wget. + * Copyright (C) 2007 Christian Hujer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.japi.jwget; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; + +/** WGet implementation in Java. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @todo use argparser + */ +public class JWGet { + + /** Main program. + * @param args command line arguments + */ + public static void main(final String... args) { + int returnCode = 0; + if (args.length == 0) { + System.err.println("Usage: JWGet url..."); + returnCode++; + } + final byte[] buf = new byte[8192]; + for (final String arg : args) { + try { + final URL url = new URL(arg); + OutputStream out = null; + InputStream in = null; + try { + final URLConnection con = url.openConnection(); + in = con.getInputStream(); + final String location = con.getHeaderField("Content-Location"); + final String outputFilename = new File((location != null ? new URL(url, location) : url).getFile()).getName(); + System.err.println(outputFilename); + out = new FileOutputStream(outputFilename); + for (int bytesRead; (bytesRead = in.read(buf)) != -1; out.write(buf, 0, bytesRead)); + } catch (final IOException e) { + System.err.println(e); + returnCode++; + } finally { + try { in.close(); } catch (final Exception ignore) { /* ignore */ } + try { out.close(); } catch (final Exception ignore) { /* ignore */ } + } + } catch (final MalformedURLException e) { + System.err.println(e); + returnCode++; + } + } + System.exit(returnCode); + } + +} // class JWGet Property changes on: tools/jwget/trunk/src/net/sf/japi/jwget/JWGet.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |