/* * [ReadManifests.java] * * Summary: Download manifest of about each of the distribution zips and files. * * 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: * 1.0 2007-07-18 Created with IntelliJ IDEA. */ package com.mindprod.replicator; import com.mindprod.common18.EIO; import com.mindprod.replicatorcommon.Config; import com.mindprod.replicatorcommon.MiniFD; import com.mindprod.replicatorcommon.MiniZD; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.zip.GZIPInputStream; /** * Download manifest of about each of the distribution zips and files. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2007-07-18 Created with IntelliJ IDEA. * @since 2009 */ final class ReadManifests { /** * download the filemanifest of active files, used to verify download.. * * @throws java.net.MalformedURLException if URL name bad. */ static void downloadFileManifestSer() throws MalformedURLException { // could check if have it and length matches. Then could avoid download. final String fileManifestFilename = ConfigForReceiver .RECEIVER_ZIP_STAGING_DIR + File .separatorChar + Config .ZIPDETAILEDMANIFEST_SER; final String fileManifestURL = ConfigForReceiver .RECEIVER_ZIP_URL + "/" + Config .ZIPDETAILEDMANIFEST_SER; Replicator.doing( "downloading list of files that should be in the distribution: " + Config .ZIPDETAILEDMANIFEST_SER ); if ( !FetchZips.ft .download( new URL( fileManifestURL ), new File( fileManifestFilename ), false ) ) { Replicator.fatal( "Unable to download file manifest: " + fileManifestURL + " to " + fileManifestFilename ); } } /** * download the zipmanifest of active zip files. * * @throws java.net.MalformedURLException if URL name bad. */ static void downloadZipManifestSer() throws MalformedURLException { // could check if have it and length matches. Then could avoid download. final String zipManifestFilename = ConfigForReceiver .RECEIVER_ZIP_STAGING_DIR + File .separatorChar + Config .ZIPMANIFEST_SER; final String zipManifestURL = ConfigForReceiver .RECEIVER_ZIP_URL + "/" + Config .ZIPMANIFEST_SER; Replicator.doing( "downloading list of zips: " + zipManifestURL ); if ( !FetchZips.ft .download( new URL( zipManifestURL ), new File( zipManifestFilename ), false ) ) { Replicator.fatal( "Unable to download zip manifest: " + zipManifestURL + " to " + zipManifestFilename ); } } /** * Unpack the file manifest, an array of serialised file MiniFD descriptors. */ static void unpackFileManifestSer() { final String fileManifestFilename = ConfigForReceiver .RECEIVER_ZIP_STAGING_DIR + File .separatorChar + Config.ZIPDETAILEDMANIFEST_SER; try { final ObjectInputStream ois = EIO.getObjectInputStream( new File( fileManifestFilename ), 4 * 1024, true ); long fileSerialVersionUID = ( Long ) ois.readObject(); if ( fileSerialVersionUID != MiniFD.serialVersionUID ) { Replicator.fatal( "Incompatible version of " + Config .ZIPDETAILEDMANIFEST_SER + " got: " + fileSerialVersionUID + " expected: " + MiniFD .serialVersionUID ); } FetchZips.allFilesAndDeletions = ( MiniFD[] ) ois.readObject(); Log.divider(); Log.println( "File Manifest:" ); for ( MiniFD fileInDistribution : FetchZips.allFilesAndDeletions ) { Log.println( fileInDistribution.dump() ); } Log.println(); ois.close(); Log.divider(); } catch ( ClassNotFoundException e ) { Replicator.fatal( "Corrupt file manifest: " + fileManifestFilename + "\n" + e .getMessage() ); } catch ( IOException e ) { Replicator.fatal( "Unable to read file manifest: " + fileManifestFilename + "\n" + e.getMessage() ); } } // end unpackFileManifestSer /** * Unpack the zip manifest, an array of serialised zip descriptors. */ static void unpackZipManifestSer() { final String zipManifestFilename = ConfigForReceiver .RECEIVER_ZIP_STAGING_DIR + File .separatorChar + Config.ZIPMANIFEST_SER; try { final FileInputStream fis = new FileInputStream( zipManifestFilename ); // stream is compressed final GZIPInputStream gzis = new GZIPInputStream( fis, 4 * 1024/* buffsize */ ); final ObjectInputStream ois = new ObjectInputStream( gzis ); long fileSerialVersionUID = ( Long ) ois.readObject(); if ( fileSerialVersionUID != MiniZD.serialVersionUID ) { Replicator.fatal( "Incompatible version of " + Config .ZIPMANIFEST_SER + " got: " + fileSerialVersionUID + " expected: " + MiniZD .serialVersionUID ); } FetchZips.allDownloadableZips = ( MiniZD[] ) ois.readObject(); Log.divider(); Log.println( "Zip Manifest:" ); for ( MiniZD downloadablezip : FetchZips.allDownloadableZips ) { Log.println( downloadablezip.dump() ); } Log.divider(); ois.close(); } catch ( ClassNotFoundException e ) { Replicator.fatal( "Corrupt zip manifest: " + zipManifestFilename + "\n" + e .getMessage() ); } catch ( IOException e ) { Replicator.fatal( "Unable to read zip manifest: " + zipManifestFilename + "\n" + e.getMessage() ); } } // end unpackZipManifestSer }