/* * [MiniZD.java] * * Summary: Stripped down Zip Descriptor. Describes one zip archive. Zip files are never modified once created. * * Copyright: (c) 2003-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: * 10.2 2009-04-03 tidy up code to check presence of necessary files to make it more WORA. * Stripped down Zip Descriptor. Describes one zip archive. Zip files are never modified once created. * They may be obsoleted and their files moved to another archive however. * What we export to the client to describe a zip archive. */ package com.mindprod.replicatorcommon; import com.mindprod.replicator.ConfigForReceiver; import java.io.File; import java.io.Serializable; /** * Stripped down Zip Descriptor. Describes one zip archive. Zip files are never modified once created. * * @author Roedy Green, Canadian Mind Products * @version 10.2 2009-04-03 tidy up code to check presence of necessary files to make it more WORA. * Stripped down Zip Descriptor. Describes one zip archive. Zip files are never modified once created. * They may be obsoleted and their files moved to another archive however. * What we export to the client to describe a zip archive. * @since 2003-08-28 */ public class MiniZD implements Serializable { /** * Layout version number. */ public static final long serialVersionUID = 25L; /** * serial number of this zip archive. Numbers are not recycled. They are assigned in simple ascending order. */ protected final int zipNumber; /** * Usually the same as the timestamp, but for files that appear out of the blue with dates in the past, is the * cutoff timestamp for the last round of distributions, at so that it will clump with the newly created files. * Otherwise we would imagine this file was already done in some past zip. */ protected long highestClumpingInZip = Config.NULL_TIMESTAMP; /** * Copy constructor to allow a MaxiZD to be demoted to a MiniZD * * @param m usually a MaxiZD to be demoted */ public MiniZD( MiniZD m ) { zipNumber = m.zipNumber; highestClumpingInZip = m.highestClumpingInZip; } /** * constructor, used by MaxiZD * * @param zipNumber number of this zip file. */ protected MiniZD( int zipNumber ) { this.zipNumber = zipNumber; highestClumpingInZip = 0; } /** * Set highest clumping in zip of candidate is bigger than anything previous. * * @param highestClumpingInZip timestamp. */ protected void setPossiblyHigherClumpingInZip( long highestClumpingInZip ) { if ( highestClumpingInZip > this.highestClumpingInZip ) { this.highestClumpingInZip = highestClumpingInZip; } } /** * Convert to String for debug * * @return Zip descriptor as string. */ public String dump() { final StringBuilder sb = new StringBuilder( 100 ); sb.append( "MiniZD " ); sb.append( "z" ); sb.append( Integer.toString( zipNumber ) ); // no need to dump clumping separately, part of lastElement. if ( highestClumpingInZip != 0 ) { sb.append( " highestclumping: " ); sb.append( Config.TIMESTAMP_MILLISECOND_FORMAT.format( highestClumpingInZip ) ); } return sb.toString(); } /** * Get highest clumping timestamp of any file in the zip. * * @return timestamp as a long. */ public long getHighestClumpingInZip() { return highestClumpingInZip; } /** * set value for hihighestClumpingInZip * * @param highestClumpingInZip timestamp */ public void setHighestClumpingInZip( long highestClumpingInZip ) { this.highestClumpingInZip = highestClumpingInZip; } /** * Get name of the archive relative to the replicator archive, e.g. z42.zip * * @return zip file name e.g. z123.zip */ public String getRelativeZipFilename() { return "z" + Integer.toString( zipNumber ) + ".zip"; } /** * get the fully qualified filename of this zip: e.g. E:\mindprod\replicator\z42.zip * * @param where which name, ON_SOURCE, ON_TARGET or ON_WEBSITE, ON_RECEIVER_ZIP_URL, RELATIVE * * @return fully qualified name of the zip file. */ public String getZipFilename( ZipnameContext where ) { switch ( where ) { // case ON_SOURCE implemented in MaxiZD. case ON_TARGET: return ConfigForReceiver .RECEIVER_ZIP_STAGING_DIR + File .separatorChar + getRelativeZipFilename(); case ON_WEBSITE: return ConfigForReceiver .WEBSITE_ZIP_URL + "/" + getRelativeZipFilename(); case ON_RECEIVER_ZIP_URL: return ConfigForReceiver .RECEIVER_ZIP_URL + "/" + getRelativeZipFilename(); case RELATIVE: return getRelativeZipFilename(); default: assert false : "bad where code"; return null; } } /** * get the number 1..n of this zip file * * @return number of zip, used in same z9999.zip */ public int getZipNumber() { return zipNumber; } /** * Represent MiniZD as a String * * @return String z999 filename clumping */ public String toString() { final StringBuilder sb = new StringBuilder( 100 ); sb.append( "z" ); sb.append( Integer.toString( zipNumber ) ); if ( highestClumpingInZip != 0 ) { sb.append( " highestclump: " ); sb.append( Config.TIMESTAMP_MILLISECOND_FORMAT.format( highestClumpingInZip ) ); } return sb.toString(); } }