[Japi-cvs] SF.net SVN: japi: [209] libs/argparser/trunk/src/net/sf/japi/io/args
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2006-11-25 14:20:53
|
Revision: 209 http://svn.sourceforge.net/japi/?rev=209&view=rev Author: christianhujer Date: 2006-11-25 06:20:52 -0800 (Sat, 25 Nov 2006) Log Message: ----------- Added Converter package. Added Paths: ----------- libs/argparser/trunk/src/net/sf/japi/io/args/converter/ libs/argparser/trunk/src/net/sf/japi/io/args/converter/BooleanConverter.java libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter.java libs/argparser/trunk/src/net/sf/japi/io/args/converter/InputStreamConverter.java libs/argparser/trunk/src/net/sf/japi/io/args/converter/package.html Added: libs/argparser/trunk/src/net/sf/japi/io/args/converter/BooleanConverter.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/BooleanConverter.java (rev 0) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/BooleanConverter.java 2006-11-25 14:20:52 UTC (rev 209) @@ -0,0 +1,14 @@ +package net.sf.japi.io.args.converter; + +/** + * Converter which converts a String into a Boolean. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class BooleanConverter implements Converter<Boolean> { + + /** {@inheritDoc} */ + public Boolean convert(final String arg) throws Exception { + return Boolean.valueOf(arg); + } + +} // class BooleanConverter Property changes on: libs/argparser/trunk/src/net/sf/japi/io/args/converter/BooleanConverter.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter.java (rev 0) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter.java 2006-11-25 14:20:52 UTC (rev 209) @@ -0,0 +1,17 @@ +package net.sf.japi.io.args.converter; + +/** + * The Converter interface is used for converters that convert Strings into other types. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public interface Converter<T> { + + /** + * Convert the given argument to the desired return type. + * @param arg Argument to convert + * @return Argument converted to T. + * @throws Exception In case of conversion failure. + */ + T convert(final String arg) throws Exception; + +} // interface Convert Property changes on: libs/argparser/trunk/src/net/sf/japi/io/args/converter/Converter.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: libs/argparser/trunk/src/net/sf/japi/io/args/converter/InputStreamConverter.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/InputStreamConverter.java (rev 0) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/InputStreamConverter.java 2006-11-25 14:20:52 UTC (rev 209) @@ -0,0 +1,24 @@ +package net.sf.japi.io.args.converter; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +/** + * Converter that converts a String into an InputStream. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class InputStreamConverter implements Converter<InputStream> { + + /** {@inheritDoc} */ + public InputStream convert(final String arg) throws FileNotFoundException { + try { + return new URL(arg).openStream(); + } catch (final IOException ignore) { + return new FileInputStream(arg); + } + } + +} // class InputStreamConverter Property changes on: libs/argparser/trunk/src/net/sf/japi/io/args/converter/InputStreamConverter.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: libs/argparser/trunk/src/net/sf/japi/io/args/converter/package.html =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/converter/package.html (rev 0) +++ libs/argparser/trunk/src/net/sf/japi/io/args/converter/package.html 2006-11-25 14:20:52 UTC (rev 209) @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- JAPI - (Yet another (hopefully) useful) Java API + - + - Copyright (C) 2004-2006 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., 59 Temple Place - Suite 330, Boston, MA + - 02111-1307, USA. + --> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de"> + <head> + <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /> + <meta name="Date" content="$Date: 2006-04-03 23:00:14 +0200 (Mon, 03 Apr 2006) $" /> + <title>net.sf.japi.io.args.converter</title> + </head> + <body> + <p> + The Converter package contains classes for automatic argument conversion. + For instance, a Command might simply want to read bytes from an InputStream. + The Converter package makes will convert the String into an InputStream then. + </p> + </body> +</html> Property changes on: libs/argparser/trunk/src/net/sf/japi/io/args/converter/package.html ___________________________________________________________________ Name: svn:mime-type + text/html Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |