public static final void say( String msg, Monitor monitor ) { if( monitor != null ) monitor.message( msg ); }
/** * convert timestamp to millis * * @param ts timestamp to convert. Presumed to be a long of form yyyyMMddHHmmss * @return millis, corresponding to the supplied TS * @throws ParseException is long does not follow the format */ public static long toMillis( long ts ) throws ParseException { return toMillis( "" + ts ); }
public static final String nvlS( String s, String dflt ) { return isEmpty(s) ? dflt : s; }
/** * @return current UTC timestamp by yyyyMMddHHmmss mask */ public static String getUTCTimestamp() { return getUTCTimestamp( new Date() ); }
/** * Read the content of a file and converts it with UTF-8 encoding to a String. */ public static String readRawDataAsString( File file ) throws IOException { return new String( readRawData( file ), DEFAULT_CHARSET ); } //---------------------------------------------------------------------------------------------------------------
public static void writeAndSign( String fName, byte [] bytes, Set<StreamVerifierFactory> vFacs ) throws IOException, StreamObserverException { ByteArrayInputStream bais = new ByteArrayInputStream( bytes ); writeAndSign( fName, bais, vFacs ); } //---------------------------------------------------------------------------------------------------------------
/** * Write UTF-8 representation of a String to a File. */ public static void writeRawData( File file, String sBytes ) throws IOException { writeRawData( file, sBytes.getBytes( DEFAULT_CHARSET ) ); } //---------------------------------------------------------------------------------------------------------------
public static void delete( File f ) { if( ! f.exists() ) return; if( f.isDirectory() ) { File [] kids = f.listFiles(); for( File kid : kids ) delete( kid ); } f.delete(); } //---------------------------------------------------------------------------------------------------------------
public void release() { if( lock == null ) { if( fileLock ) FileUtil.unlockDir( dir ); return; } try { lock.release(); channel.close(); } catch( IOException any ){} } }
public ArtifactFilterList( Map<String, Collection<String>> filter ) { if( Util.isEmpty( filter ) ) return; _filters.add( new MetadataTreeArtifactFilterMap(filter) ); }
/** * @return current UTC timestamp by yyyyMMddHHmmss mask as a long int */ public static long getUTCTimestampAsLong() { return Long.parseLong( getUTCTimestamp( new Date() ) ); }
public static File writeTempData( byte [] bytes ) throws IOException { File f = File.createTempFile( "temp-", "-mercury-util" ); writeRawData( f, bytes ); return f; } //---------------------------------------------------------------------------------------------------------------
public static void main( String[] args ) throws Exception { if( args == null || args.length < 0 ) return; if( "-t".equals( args[0] ) ) { System.out.println( args[1]+" => " + new Date( toMillis( args[1] ) ) ) ; return; } } }
public boolean veto( ArtifactMetadata md ) { String key = md.toManagementString(); Collection<String> ver = _vetos.get( key ); if( Util.isEmpty( ver ) ) return false; return ver.contains( md.getVersion() ); }
/** * @return current UTC timestamp by yyyyMMddHHmmss mask as a long int */ public static long getUTCTimestampAsMillis() { return Long.parseLong( getUTCTimestamp( new Date() ) ); }
private static void copyFile( File f, File toFile ) throws IOException { File fOut = null; if( toFile.isDirectory() ) fOut = new File(toFile, f.getName() ); else fOut = toFile; FileInputStream fis = new FileInputStream(f); writeRawData( fis, fOut ); } //---------------------------------------------------------------------------------------------------------------
private List<Comparator<MetadataTreeNode>> getComparators() { if ( Util.isEmpty( _comparators ) ) _comparators = new ArrayList<Comparator<MetadataTreeNode>>( 2 ); if ( _comparators.size() < 1 ) { _comparators.add( new ClassicDepthComparator() ); _comparators.add( new ClassicVersionComparator() ); } return _comparators; }
/** * update snapshot timestamp to now * * @param target */ public static void updateTimestamp( Snapshot target ) { target.setTimestamp( TimeUtil.getUTCTimestamp() ); }
/** * update versioning's lastUpdated timestamp to now * * @param target */ public static void updateTimestamp( Versioning target ) { target.setLastUpdated( TimeUtil.getUTCTimestamp() ); }
private boolean updateSnapshot( Snapshot snapshot, Versioning vs ) { vs.setSnapshot( snapshot ); vs.setLastUpdated( TimeUtil.getUTCTimestamp() ); return true; }