/* * [RSSFeedLog.java] * * Summary: Logs the XML for all feeds. * * Copyright: (c) 2008-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 2008-07-31 */ package com.mindprod.htmlmacros.support; import com.mindprod.common18.EIO; import java.io.DataOutputStream; import java.io.File; import java.io.IOException; import static com.mindprod.htmlmacros.macro.Global.configuration; import static java.lang.System.*; /** * Logs the XML for all feeds. *

* it will be expanded in line if there were any feeds. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2008-07-31 * @since 2008-07-31 */ public final class RSSFeedLog { /** * count of RSS items */ static int count; static File rssBinaryLogFile; /** * where we log all feeds in binary format for later sorting and collecting into separate feeds. * Opened on first encounter with RSS macro . * Stays open until shutdown. */ private static DataOutputStream rssBinaryLogStream; /** * close binary log of feeds we will later format */ private static void endAllFeeds() throws IOException { if ( rssBinaryLogStream != null ) { rssBinaryLogStream.close(); rssBinaryLogStream = null; } } /** * start recording binary stream of rss items that will will later format */ private static void startAllFeeds() { try { // first time we have encountered an RSS macro expansion in this batch, open file and leave open till shutdown. rssBinaryLogFile = new File( configuration.getLocalWebrootWithSlashes() + "/rss/temprssfeedlog.bin" ); rssBinaryLogStream = EIO.getDataOutputStream( rssBinaryLogFile, 32 * 1024 ); } catch ( IOException e ) { err.println( "Unable to open " + rssBinaryLogFile.getAbsolutePath() ); System.exit( 2 ); } } /** * done at start */ public static void fireup() { startAllFeeds(); } /** * emit the XML for one RSS-2 feed item to a binary log file. * * @param feedItem item to log */ public static void logFeedItem( RSSSortableItem feedItem ) { try { // we have to automatically handle start/end. Caller won't invoke them. // log item in computer-friendly BigEndian binary format for processing later. feedItem.write( rssBinaryLogStream ); count++; } catch ( IOException e ) { throw new IllegalArgumentException( "problem writing an RSS feed item file" ); } } /** * generate various export files to download with formatted xml */ public static void shutdown() { try { // sends all results to files, nothing to expandNoRef inline. endAllFeeds(); RSSFeedExport.exportAllFeeds(); } catch ( IOException e ) { throw new IllegalArgumentException( "problem closing/exporting a RSS feed item file" ); } } }