/** * Print a user friendly time for estimated time of completion of the task. * * @param currentCount current count of unit processed. * @return a nicely formatted remaining time. */ public String printETA( long currentCount ) { long eta = calculateETA( currentCount ); return new ElapsedTime( ( int ) eta ).toString(); } }
public void run(){buildMemoryReport(); } }
/** * Non-recursive listing of the files in a URL * @param folderUrl The folder to read * @return the lists of URLs * @throws java.io.IOException */ public static List<URL> listFilesFromFolderUrl(URL folderUrl) throws IOException { return listFilesFromFolderUrl(folderUrl, null, false); }
public String crc64(Interaction interaction) { UniquenessStringBuilder sb = createUniquenessString(interaction); final String uniquenessString = sb.toString().toLowerCase(); String crc64 = Crc64.getCrc64(uniquenessString); if (log.isDebugEnabled()) log.debug("Created CRC for interaction '" + interaction.getShortLabel() + "': " + crc64 + " (" + uniquenessString + ")"); return crc64; }
public static Collection<URL> searchResourcesInClasspath(String prefix, String suffix) throws IOException { return searchResourcesInClasspath(Thread.currentThread().getContextClassLoader(), prefix, suffix); }
public static void zip( File[] sourceFiles, File destFile, boolean deleteOriginalFiles ) throws IOException { zip( sourceFiles, destFile, deleteOriginalFiles, false ); }
/** * Send a mail to a set of recipients. * * @param recipients list of mail adresses * @param subject subject of the mail * @param message content of the mail * @param from who wrote that mail * * @throws javax.mail.MessagingException if the message can't be sent. */ public void postMail( String recipients[ ], String subject, String message, String from, File ... fileAttachments ) throws MessagingException { Session session = Session.getInstance(properties); postMail(session, recipients, subject, message, from, fileAttachments); }
/** * Uncompresses zipped files * @param zippedFile The file to uncompress * @return list of unzipped files * @throws java.io.IOException thrown if there is a problem finding or writing the files */ public static List<File> unzip(File zippedFile) throws IOException { return unzip(zippedFile, null); }
public MemoryMonitor() { hook(); }
/** * Zip the subdirectory and exclude already zipped files * @param path * @param srcFolder * @param zip * @param includeFullPath * @throws IOException */ static private void addFolderToZip(String path, String srcFolder, ZipOutputStream zip, boolean includeFullPath) throws IOException { File folder = new File(srcFolder); for (String fileName : folder.list()) { if (path.equals("") && !fileName.endsWith(".zip")) { if (includeFullPath){ addFileToZip(folder.toString(), srcFolder + "/" + fileName, zip); } else { addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip); } } else if (!fileName.endsWith(".zip")) { addFileToZip(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip); } } }
/** * @param resource Name of resource(s) to find in classpath * @param defaultObject The default object to use to determine the class loader (if none associated with current thread.) * * @return Iterator over URL Objects */ public static Iterator<URL> getResources(String resource, Object defaultObject) throws IOException { Enumeration<URL> resources = getCurrentLoader(defaultObject).getResources(resource); List<URL> lst = new ArrayList<URL>(); while (resources.hasMoreElements()) { lst.add(resources.nextElement()); } return lst.iterator(); }
protected static void searchDir(Set<URL> resultUrls, File dir, String suffix) throws IOException { if (dir.exists() && dir.isDirectory()) { File[] files = dir.listFiles(); String absolutePath; for (File file : files) { absolutePath = file.getAbsolutePath(); if (file.isDirectory()) { searchDir(resultUrls, file, suffix); } else if (absolutePath.endsWith(suffix)) { resultUrls.add(file.toURL()); } } } }
static private void addFileToZip(String path, String srcFile, ZipOutputStream zip) throws IOException { File folder = new File(srcFile); if (folder.isDirectory()) { addFolderToZip(path, srcFile, zip, false); } else { byte[] buf = new byte[1024]; int len; FileInputStream in = new FileInputStream(srcFile); try{ zip.putNextEntry(new ZipEntry(path + "/" + folder.getName())); while ((len = in.read(buf)) > 0) { zip.write(buf, 0, len); } } finally { in.close(); } } }
public String crc64(Interaction interaction) { UniquenessStringBuilder sb = createUniquenessString(interaction); final String uniquenessString = sb.toString().toLowerCase(); String crc64 = Crc64.getCrc64(uniquenessString); if (log.isDebugEnabled()) log.debug("Created CRC for interaction '" + interaction.getShortLabel() + "': " + crc64 + " (" + uniquenessString + ")"); return crc64; }
public static Collection<URL> searchResourcesInClasspath(String resourcePath) throws IOException { return searchResourcesInClasspath(Thread.currentThread().getContextClassLoader(), resourcePath, ""); }
/** * Send a mail to a set of recipients. * * @param recipients list of mail adresses * @param subject subject of the mail * @param message content of the mail * @param from who wrote that mail * * @throws javax.mail.MessagingException if the message can't be sent. */ public void postMail( String recipients[ ], String subject, String message, String from ) throws MessagingException { Session session = Session.getInstance(properties); postMail(session, recipients, subject, message, from, null); }
protected void loadDeclaredRulesFromClassPath() throws IOException { Collection<URL> resources = ClassUtils.searchResourcesInClasspath( RULES_XML_PATH ); if ( log.isDebugEnabled() ) log.debug( "Found " + resources.size() + " sanity-rules.xml files in the classpath" ); if ( log.isDebugEnabled() && resources.size() > 1 ) { int i = 1; for ( URL resource : resources ) { log.debug( i + ") " + resource.getFile() ); i++; } } for ( URL resource : resources ) { try { DeclaredRules dr = readDeclaredRules( resource.openStream() ); addAllDeclaredRules( dr.getDeclaredRules() ); if ( log.isDebugEnabled() ) log.debug( "Loaded " + dr.getDeclaredRules().size() + " declared rules from: " + resource ); } catch ( Throwable t ) { throw new SanityRuleException( "Problem reading declared rules from resource: " + resource, t ); } } }
/** * Send a mail to a set of recipients. * * @param recipients list of mail adresses * @param subject subject of the mail * @param message content of the mail * @param from who wrote that mail * * @throws javax.mail.MessagingException if the message can't be sent. */ public void postMailSSL( String recipients[ ], String subject, String message, String from, final PasswordAuthentication auth, File ... fileAttachment ) throws MessagingException { Session session = Session.getDefaultInstance(properties, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return auth; } }); postMail(session, recipients, subject, message, from, fileAttachment); }
/** * Send a mail to a set of recipients. * * @param recipients list of mail adresses * @param subject subject of the mail * @param message content of the mail * @param from who wrote that mail * * @throws javax.mail.MessagingException if the message can't be sent. */ public void postMailSSL( String recipients[ ], String subject, String message, String from, final PasswordAuthentication auth ) throws MessagingException { Session session = Session.getDefaultInstance(properties, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return auth; } }); postMail(session, recipients, subject, message, from, null); }