/* * [RSSBatchLog.java] * * Summary: Logs the HTML for a batch of RSS feed times. * * 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 java.io.BufferedOutputStream; import java.io.DataOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import static com.mindprod.htmlmacros.macro.Global.configuration; /** * Logs the HTML for a batch of RSS feed times. *

* When an RSSEnd macro is encountered, it will be expanded in line. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2008-07-31 * @since 2008-07-31 */ public final class RSSBatchLog { /** * false, RSS macros expanded inline. * true, RSS macros saved to disk to be sorted, and expanded later when hit RSSend */ public static boolean inBatch = false; /** * count of items in the current RSSBegin ... RSSEnd batch */ 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 RSSBegin macro. * Stays open until RSSEnd. */ private static DataOutputStream rssBinaryLog; /** * close the batch log. * * @see # */ public static void endBatch() { if ( !inBatch ) { throw new IllegalArgumentException( "RSSEnd macro without previous RSSBegin macro." ); } inBatch = false; try { if ( rssBinaryLog != null ) { rssBinaryLog.close(); rssBinaryLog = null; } } catch ( IOException e ) { throw new IllegalArgumentException( "Trouble closing RSS batch log" ); } } /** * log one RSS item for temp binary file */ public static void logBatchItem( RSSSortableItem item ) { if ( !inBatch ) { return; } try { item.write( rssBinaryLog ); count++; } catch ( IOException e ) { throw new IllegalArgumentException( "Trouble writing RSS batch log" ); } } /** * start parsing a batch of RSS items */ public static void startBatch() { if ( inBatch ) { throw new IllegalArgumentException( "RSSBegin macro without previous RSSEnd macro." ); } inBatch = true; count = 0; // first time we have encountered an RSS macro expansion in this batch, open file and leave open till hit // RSSEnd. rssBinaryLogFile = new File( configuration.getScratchAreaWithBackslashes(), "temprssbatchlog.bin" ); try { rssBinaryLog = new DataOutputStream( new BufferedOutputStream( new FileOutputStream( rssBinaryLogFile, false ), 4 * 1024/* buffsize in bytes */ ) ); } catch ( IOException e ) { throw new IllegalArgumentException( "Trouble opening RSS batch log" ); } } }