1/* 2 * ProGuard -- shrinking, optimization, obfuscation, and preverification 3 * of Java bytecode. 4 * 5 * Copyright (c) 2002-2013 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 */ 21package proguard; 22 23import 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 */ 32public class ArgumentWordReader extends WordReader 33{ 34 private final String[] arguments; 35 36 private int index = 0; 37 38 39// /** 40// * Creates a new ArgumentWordReader for the given arguments. 41// */ 42// public ArgumentWordReader(String[] arguments) 43// { 44// this(arguments, null); 45// } 46// 47// 48 /** 49 * Creates a new ArgumentWordReader for the given arguments, with the 50 * given base directory. 51 */ 52 public ArgumentWordReader(String[] arguments, File baseDir) 53 { 54 super(baseDir); 55 56 this.arguments = arguments; 57 } 58 59 60 // Implementations for WordReader. 61 62 protected String nextLine() throws IOException 63 { 64 return index < arguments.length ? 65 arguments[index++] : 66 null; 67 } 68 69 70 protected String lineLocationDescription() 71 { 72 return "argument number " + index; 73 } 74 75 76 /** 77 * Test application that prints out the individual words of 78 * the argument list. 79 */ 80 public static void main(String[] args) { 81 82 try 83 { 84 WordReader reader = new ArgumentWordReader(args, null); 85 86 try 87 { 88 while (true) 89 { 90 String word = reader.nextWord(false); 91 if (word == null) 92 System.exit(-1); 93 94 System.err.println("["+word+"]"); 95 } 96 } 97 catch (Exception ex) 98 { 99 ex.printStackTrace(); 100 } 101 finally 102 { 103 reader.close(); 104 } 105 } 106 catch (IOException ex) 107 { 108 ex.printStackTrace(); 109 } 110 } 111} 112