1 /* 2 * ProGuard -- shrinking, optimization, obfuscation, and preverification 3 * of Java bytecode. 4 * 5 * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License as published by the Free 9 * Software Foundation; either version 2 of the License, or (at your option) 10 * any later version. 11 * 12 * This program is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15 * more details. 16 * 17 * You should have received a copy of the GNU General Public License along 18 * with this program; if not, write to the Free Software Foundation, Inc., 19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 */ 21 package proguard; 22 23 import java.io.*; 24 25 26 /** 27 * A <code>WordReader</code> that returns words from an argument list. 28 * Single arguments are split into individual words if necessary. 29 * 30 * @author Eric Lafortune 31 */ 32 public class ArgumentWordReader extends WordReader 33 { 34 private final String[] arguments; 35 private int index = 0; 36 37 38 // /** 39 // * Creates a new ArgumentWordReader for the given arguments. 40 // */ 41 // public ArgumentWordReader(String[] arguments) 42 // { 43 // this(arguments, null); 44 // } 45 // 46 // 47 /** 48 * Creates a new ArgumentWordReader for the given arguments, with the 49 * given base directory. 50 */ ArgumentWordReader(String[] arguments, File baseDir)51 public ArgumentWordReader(String[] arguments, File baseDir) 52 { 53 super(baseDir); 54 55 this.arguments = arguments; 56 } 57 58 59 // Implementations for WordReader. 60 nextLine()61 protected String nextLine() throws IOException 62 { 63 return index < arguments.length ? 64 arguments[index++] : 65 null; 66 } 67 68 lineLocationDescription()69 protected String lineLocationDescription() 70 { 71 return "argument number " + index; 72 } 73 74 75 /** 76 * Test application that prints out the individual words of 77 * the argument list. 78 */ main(String[] args)79 public static void main(String[] args) { 80 81 try 82 { 83 WordReader reader = new ArgumentWordReader(args, null); 84 85 try 86 { 87 while (true) 88 { 89 String word = reader.nextWord(); 90 if (word == null) 91 System.exit(-1); 92 93 System.err.println("["+word+"]"); 94 } 95 } 96 catch (Exception ex) 97 { 98 ex.printStackTrace(); 99 } 100 finally 101 { 102 reader.close(); 103 } 104 } 105 catch (IOException ex) 106 { 107 ex.printStackTrace(); 108 } 109 } 110 } 111