Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package bpiwowar.argparser.handlers;
 
 import java.io.File;
 
This handler reads the file and add each line as a string to the collection

Author(s):
Benjamin Piwowarski
public class FileStringSetHandler extends GenericObjectsHandler {
	public FileStringSetHandler(Object objectField field)
		super(objectfield);
		if (!Collection.class.isAssignableFrom(field.getType()))
			throw new InvalidHolderException("Field %s is not a collection",
					field);
		// TODO: check it implements Collection<? extends String>
		// Type type = field.getGenericType();
	}
	protected Object process(ArgParser argParserStringScanner scanner)
		try {
			File file = new File(scanner.scanString());
			if (set == null) {
				.set(set);
			}
			for (String line : new ReadLineIterator(file))
				set.add(line);
			return set;
catch (RuntimeException e) {
			throw e;
catch (Exception e) {
			throw new StringScanException(e);
		}
	}
New to GrepCode? Check out our FAQ X