/* * [Prepare.java] * * Summary: prepare predigested *.ser resource of information about default apps to track. * * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 3.7 2009-03-20 define defaults and obsoletes in files rather than hard wired into the program. * 3.8 2009-03-31 change order of fields in defaults.csv * 3.9 2010-03-24 check that dates are not in future * 4.0 2014-06-06 allow appnames and descriptions to be entified, passed an UTF-8 to Vercheck resources. */ package com.mindprod.vercheck; import com.mindprod.common18.BigDate; import com.mindprod.common18.EIO; import com.mindprod.csv.CSVReader; import com.mindprod.entities.DeEntifyStrings; import java.io.EOFException; import java.io.File; import java.io.IOException; import java.io.ObjectOutputStream; import java.util.ArrayList; import static java.lang.System.*; /** * prepare predigested *.ser resource of information about default apps to track. * * @author Roedy Green, Canadian Mind Products * @version 4.0 2014-06-06 allow appnames and descriptions to be entified, passed an UTF-8 to Vercheck resources. * @since 2009-03-20 */ public class Prepare { // methods /** * Read list of default apps from csv file. Vercheck does not update defaults.csv file with * changes made online. * * @return List of app objects * @throws IOException if problems reading csv file */ private static AppToWatch[] readDefaults() throws IOException { final CSVReader defaultsCSV = new CSVReader( EIO.getBufferedReader( new File( "defaults.csv" ), 4 * 1048, EIO.UTF8 ) ); final ArrayList defaults = new ArrayList<>( 200 ); try { while ( true ) { final String appName = DeEntifyStrings.deEntifyHTML( defaultsCSV.get(), ' ' ); if ( appName == null ) { continue; } final String version = defaultsCSV.get(); final String marker = defaultsCSV.get(); final String yyyymmdd = defaultsCSV.get(); BigDate when = new BigDate( yyyymmdd ); final BigDate today = BigDate.localToday(); if ( when.compareTo( today ) > 0 ) { when = today; err.println( "Error: future date: " + yyyymmdd + " on " + appName ); } final boolean sni = defaultsCSV.getBoolean(); final String versionURL = defaultsCSV.get(); final String description = DeEntifyStrings.deEntifyHTML( defaultsCSV.get(), ' ' ); final String downloadURL = defaultsCSV.get(); defaultsCSV.skipToNextLine(); defaults.add( new AppToWatch( appName, version, description, downloadURL, sni, versionURL, marker, when ) ); } } catch ( EOFException e ) { defaultsCSV.close(); } out.println( defaults.size() + " default apps read" ); return defaults.toArray( new AppToWatch[ defaults.size() ] ); } // /method /** * read list of obsolete apps from csv file * * @return names of obsolete apps * @throws IOException if problems reading csv file */ private static String[] readObsoletes() throws IOException { final CSVReader obsoletesCSV = new CSVReader( EIO.getBufferedReader( new File( "obsoletes.csv" ), 4 * 1048, EIO.UTF8 ) ); final ArrayList obsoletes = new ArrayList<>( 100 ); try { while ( true ) { final String appName = DeEntifyStrings.deEntifyHTML( obsoletesCSV.get(), ' ' ); if ( appName == null ) { continue; } obsoletesCSV.skipToNextLine(); obsoletes.add( appName ); } } catch ( EOFException e ) { obsoletesCSV.close(); } out.println( obsoletes.size() + " obsoletes read" ); return obsoletes.toArray( new String[ obsoletes.size() ] ); } // /method /** * write serialized list of default apps * * @param defaults default apps * * @throws IOException if problems writing serialised file */ private static void writeDefaults( final AppToWatch[] defaults ) throws IOException { // O P E N final ObjectOutputStream oos = EIO.getObjectOutputStream( new File( "defaults.ser" ), 4 * 1024, true /* zipped */ ); // W R I T E oos.writeObject( defaults ); // C L O S E oos.close(); } // /method /** * write out serialised list of obsoletes * * @param obsoletes list of obsolete app names * * @throws IOException if problems writing serialised file */ private static void writeObsoletes( final String[] obsoletes ) throws IOException { // O P E N final ObjectOutputStream oos = EIO.getObjectOutputStream( new File( "obsoletes.ser" ), 4 * 1024, true /* zipped */ ); // W R I T E oos.writeObject( obsoletes ); // C L O S E oos.close(); } // /method /** * prepare defaults.csv and obsoletes.csv as *.ser resource files. * r.btm sorts and aligns the csv files. * * @param args not used * * @throws IOException if file problems */ public static void main( String[] args ) throws IOException { // We do not sort. VerCheckTableModel does. // write out in compressed serialised format: writeDefaults( readDefaults() ); // write out in compressed serialised format: writeObsoletes( readObsoletes() ); } // /method // /methods }