import java.util.*; import java.net.*; import java.io.*; import java.util.zip.ZipInputStream; import java.util.zip.ZipEntry; import static java.lang.System.out; public class getZipFile { static boolean dftickerNames = true; static boolean dftickerData = false; static String urlBase = "http://www.math.gatech.edu/~shenk/Books/FinMath/"; static String tickersFileName = "FIMCOM-tickers"; static String[] helptext = {"\n", "Utility to retrieve the FIMCOM symbols (tickers) or FIMCOM data files", "from the 'Finance with Monte Carlo' web site (www.math.gatech.edu/~shenk.", "This program defaults to retrieving the symbols and storing them in", "\"FIMCOM-tickers\". To retrieve the price data files instead, or to get", "both, change the booleans (true/false) as desired at the top of this", "program.", ""}; //ggg=== boolean tickerNames = true; boolean tickerData = false; int verbose = 1; InputStream is; ZipInputStream zis; ZipEntry entry; ArrayList tickersList = new ArrayList(); //ccc=== public getZipFile() throws IOException { this(dftickerNames,dftickerData); } //ccc=== public getZipFile(boolean tNames, boolean tData) throws IOException { tickerNames = tNames; tickerData = tData; String urlAddr = urlBase+"FIMCOM/fimcom.zip"; FileOutputStream TKRos=null; PrintWriter writer=null; try { URL url = new URL(urlAddr); URLConnection conn = url.openConnection(); is = url.openStream(); BufferedInputStream bis = new BufferedInputStream(is); zis = new ZipInputStream(bis); if( tickerNames ) { TKRos = new FileOutputStream(tickersFileName); writer = new PrintWriter(TKRos); } String ticker; while( (entry = zis.getNextEntry()) != null) { ticker = entry.getName().substring(0,(entry.getName()).length()-4); tickersList.add(ticker); if( verbose==1 ) out.print("."); else if( verbose==2 ) out.println(ticker); if( tickerNames ) { writer.println(ticker); } if( tickerData ) { //out.println("Unzipping: "+ entry.getName()); int size; byte[] buffer = new byte[2048]; FileOutputStream CSVos = new FileOutputStream(entry.getName()); BufferedOutputStream bos = new BufferedOutputStream(CSVos, buffer.length); while ((size = zis.read(buffer, 0, buffer.length)) != -1) { bos.write(buffer, 0, size); } bos.flush(); bos.close(); } } if( tickerNames ) { writer.close(); TKRos.close();} zis.close(); is.close(); } catch( MalformedURLException me) { throw new IOException(me); } catch( FileNotFoundException ffe) { throw new IOException(ffe); } catch( ArrayIndexOutOfBoundsException aioob ) { throw new IOException(aioob); } catch( IOException ioe) { throw new IOException(ioe); } } //mmm=== public static void main (String args[]) throws IOException { if( args.length > 0 && args[0].equals("-h") ) { for( int i=0; i