1 50 51 package org.openlaszlo.iv.flash.util; 52 53 import java.io.*; 54 55 65 public class DataSource { 66 67 private LineReader reader; 68 69 public DataSource() {} 70 71 public DataSource( LineReader reader ) { 72 setReader( reader ); 73 } 74 75 protected void setReader( LineReader reader ) { 76 this.reader = reader; 77 } 78 79 public String [][] getData() throws IOException { 80 IVVector lines = new IVVector(); 81 IVVector curLine = new IVVector(); 82 83 String line = reader.readLine(); 84 while( line != null ) { 85 curLine.reset(); 86 87 String token; 88 Tokenizer t = new Tokenizer(line); 89 while( (token=t.getToken()) != null ) { 90 curLine.addElement( Util.processEscapes(token) ); 91 } 92 93 if( curLine.size() > 0 ) { 94 int size = curLine.size(); 95 if( lines.size() > 0 ) { 96 int s = ((String [])lines.elementAt(0)).length; 97 if( s > size ) size = s; 98 } 99 String [] sa = new String [size]; 100 curLine.copyInto(sa); 101 for( int k=curLine.size(); k<size; k++ ) { sa[k] = ""; } 102 lines.addElement(sa); 103 } 104 105 line = reader.readLine(); 106 } 107 108 String [][] data = new String [lines.size()][]; 109 lines.copyInto(data); 110 return data; 111 } 112 113 131 } 132 | Popular Tags |