/* * [ImportQuotations.java] * * Summary: Import CSV File of Quotations. * * Copyright: (c) 2012-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: * 1.0 2012-07-12 initial version */ package com.mindprod.repair; import com.mindprod.common18.EIO; import com.mindprod.csv.CSVReader; import com.mindprod.fastcat.FastCat; import java.io.EOFException; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import static java.lang.System.*; /** * Import CSV File of Quotations. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2012-07-12 initial version * @since 2012-07-12 */ public class ImportQuotations { /** * import csv file C:/temp/import.csv and output at C:/temp/import.html * * @param args not used * * @throws IOException */ public static void main( final String[] args ) throws IOException { final File csv = new File( "C:/temp/import.csv" ); // reader, separatorChar, quoteChar, commentChars, hideComments, trimQuoted, trimUnquoted, // allowMultipleLineFields final CSVReader r = new CSVReader( EIO.getBufferedReader( csv, 1024 * 256 * 3, EIO.UTF8 ), ',' /* tab delimited */, '\"' /* effectively no quote char */, "#", /* comment chars */ true /* hide comments */, true /* trimQuoted */, true /* trimUnquoted */, false /* disallow multiline */ ); final PrintWriter w = EIO.getPrintWriter( new File( "C:/temp/import.html" ), 16 * 1024, EIO.UTF8 ); try { while ( true ) { final String[] fields = r.getAllFieldsInLine(); if ( fields.length != 4 ) { throw new IllegalArgumentException( "Each line must have four fields " + r.lineCount() ); } final String born = fields[ 0 ]; final String author = fields[ 1 ]; final String quotation = fields[ 2 ]; final String notes = fields[ 3 ]; final FastCat sb = new FastCat( 11 ); sb.append( "
" ); sb.append( quotation ); sb.append( "\n" ); sb.append( "
\n" ); sb.append( "~ " ); sb.append( author ); sb.append( " " ); sb.append( notes ); sb.append( "
\n" ); final String html = sb.toString(); w.println( html ); } } catch ( EOFException e ) { out.println( r.lineCount() + " lines converted." ); r.close(); w.close(); } } }