1 22 23 package org.jboss.tutorial.spring; 24 25 import java.io.BufferedReader ; 26 import java.io.InputStreamReader ; 27 import java.util.ArrayList ; 28 import java.util.List ; 29 30 import org.springframework.beans.factory.InitializingBean; 31 import org.springframework.core.io.Resource; 32 33 36 public class FileLineReader extends StaticWordsCreator implements InitializingBean 37 { 38 39 private Resource resource; 40 protected List <String > words; 41 42 public Resource getResource() 43 { 44 return resource; 45 } 46 47 public void setResource(Resource resource) 48 { 49 this.resource = resource; 50 } 51 52 public void afterPropertiesSet() throws Exception 53 { 54 if (getResource() == null) 55 { 56 throw new IllegalArgumentException ("Resource must be set!"); 57 } 58 BufferedReader reader = new BufferedReader (new InputStreamReader (getResource().getInputStream())); 59 try 60 { 61 words = new ArrayList <String >(); 62 String line; 63 while ((line = reader.readLine()) != null) 64 { 65 words.add(line); 66 } 67 } 68 finally 69 { 70 reader.close(); 71 } 72 } 73 74 protected String [] getArray() 75 { 76 return words.toArray(new String [words.size()]); 77 } 78 79 } 80 | Popular Tags |