List of usage examples for org.apache.commons.lang.time DurationFormatUtils formatDuration
public static String formatDuration(long durationMillis, String format)
Formats the time gap as a string, using the specified format, and padding with zeros and using the default timezone.
This method formats durations using the days and lower fields of the format pattern.
From source file:com.antsdb.saltedfish.server.mysql.PacketEncoder.java
/** * /* ww w . j ava 2 s. c o m*/ * From server to client. One packet for each row in the result set. * * <pre> * Bytes Name * ----- ---- * n (Length Coded String) (column value) * ... * * (column value): The data in the column, as a character string. * If a column is defined as non-character, the * server converts the value into a character * before sending it. Since the value is a Length * Coded String, a NULL can be represented with a * single byte containing 251(see the description * of Length Coded Strings in section "Elements" above). * * @see http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol#Row_Data_Packet * </pre> * * @param buffer * @param nColumns * @param rowRec */ public void writeRowTextBody(ByteBuf buffer, long pRecord, int nColumns) { for (int i = 0; i < nColumns; i++) { Object fv = Record.getValue(pRecord, i); if (fv instanceof Boolean) { // mysql has no boolean it is actually tinyint fv = ((Boolean) fv) ? 1 : 0; } if (fv == null) { // null mark is 251 buffer.writeByte((byte) 251); } else if (fv instanceof Duration) { Duration t = (Duration) fv; String text = DurationFormatUtils.formatDuration(t.toMillis(), "HH:mm:ss"); BufferUtils.writeLenString(buffer, text, this.cs); } else if (fv instanceof Timestamp) { // @see ResultSetRow#getDateFast, mysql jdbc driver only take precision 19,21,29 if callers wants // to get a Date from a datetime column Timestamp ts = (Timestamp) fv; if (ts.getTime() == Long.MIN_VALUE) { // mysql '0000-00-00 00:00:00' is treated as null in jdbc buffer.writeByte((byte) 251); } else { String text; if (ts.getNanos() == 0) { text = TIMESTAMP19_FORMAT.format(ts); } else { text = TIMESTAMP29_FORMAT.format(ts); } BufferUtils.writeLenString(buffer, text, this.cs); } } else if (fv instanceof byte[]) { BufferUtils.writeWithLength(buffer, (byte[]) fv); } else if ((fv instanceof Date) && (((Date) fv).getTime() == Long.MIN_VALUE)) { // mysql '0000-00-00' is treated as null in jdbc buffer.writeByte((byte) 251); } else { String val = fv.toString(); if (val.length() == 0) { // empty mark is 0 buffer.writeByte((byte) 0); } else { BufferUtils.writeLenString(buffer, val, this.cs); } } } }
From source file:com.emcopentechnologies.viprcloudstorage.WAStorageClient.java
public static String getTime(long timeInMills) { return DurationFormatUtils.formatDuration(timeInMills, "HH:mm:ss.S") + " (HH:mm:ss.S)"; }
From source file:com.frey.repo.DateUtil.java
/** * /*from w w w . j a va2 s . c o m*/ */ public static int compTowData(Date date1, Date date2) { String date_str1 = convertDate2String5(date1); String date_str2 = convertDate2String5(date2); Date d1 = stringToDate3(date_str1); Date d2 = stringToDate3(date_str2); Long l; if (d1.getTime() > d2.getTime()) { l = d1.getTime() - d2.getTime(); } else { l = d2.getTime() - d1.getTime(); } String daystr = DurationFormatUtils.formatDuration(l, "d"); return Integer.parseInt(daystr); }
From source file:nl.nn.adapterframework.extensions.tibco.TibcoUtils.java
protected static String getQueueFirstMessageAgeAsString(Session jSession, String queueName, long currentTime) { try {/*from w ww . j a va 2s. c o m*/ long age = getQueueFirstMessageAge(jSession, queueName, null, currentTime, false); if (age == -2) { return "??"; } else if (age == -1) { return null; } else { return DurationFormatUtils.formatDuration(age, "ddd-HH:mm:ss"); } } catch (JMSException e) { return "?"; } }
From source file:nl.nn.adapterframework.util.Misc.java
public static String getAge(long value) { long currentTime = (new Date()).getTime(); long age = currentTime - value; String ageString = DurationFormatUtils.formatDuration(age, "d") + "d"; if (ageString.equals("0d")) { ;//from ww w .jav a 2s. c o m ageString = DurationFormatUtils.formatDuration(age, "H") + "h"; if (ageString.equals("0h")) { ; ageString = DurationFormatUtils.formatDuration(age, "m") + "m"; if (ageString.equals("0m")) { ; ageString = DurationFormatUtils.formatDuration(age, "s") + "s"; } } } return ageString; }
From source file:org.artifactory.addon.wicket.WicketAddonsImpl.java
@Override public Label getUptimeLabel(String wicketId) { long uptime = ContextHelper.get().getUptime(); String uptimeStr = DurationFormatUtils.formatDuration(uptime, "d'd' H'h' m'm' s's'"); Label uptimeLabel = new Label(wicketId, uptimeStr); //Only show uptime for admins if (!ContextHelper.get().getAuthorizationService().isAdmin()) { uptimeLabel.setVisible(false);//from ww w . ja v a2s.c o m } return uptimeLabel; }
From source file:org.artifactory.cli.main.ArtAdmin.java
@SuppressWarnings({ "OverlyComplexMethod" }) public static void main(String[] args) { if (args.length > 0) { String commandName = args[0]; if (!StringUtils.isEmpty(commandName)) { commandName = commandName.trim(); }//from www . j a va2 s . com CommandDefinition commandDefinition; try { commandDefinition = CommandDefinition.get(commandName); } catch (Exception e) { System.err.println("Command " + commandName + " is unknown."); (new HelpCommand()).usage(); if (DO_SYSTEM_EXIT) { System.exit(ERROR_STATUS); } return; } try { Command command = commandDefinition.getCommand(); boolean analysisValid = command.analyzeParameters(args); if (!analysisValid) { if (DO_SYSTEM_EXIT) { System.exit(ERROR_STATUS); } return; } if (command instanceof UrlBasedCommand) { if (!CliOption.username.isSet()) { System.err .println("The '" + commandName + "' command makes use of Artfiactory's REST API.\n" + "Please specify a username."); if (DO_SYSTEM_EXIT) { System.exit(ERROR_STATUS); } } if (!CliOption.password.isSet()) { char[] passwordChars; try { passwordChars = SecurePrompt.readConsoleSecure("Please enter you password: "); } catch (Exception e) { throw new RemoteCommandException(e.getMessage()); } String password = String.valueOf(passwordChars); CliOption.password.setValue(password); } } long start = System.currentTimeMillis(); int returnCode = command.execute(); long executionTime = System.currentTimeMillis() - start; String executionTimeString = DurationFormatUtils.formatDuration(executionTime, "s.SS"); CliLog.info(commandName + " finished in " + executionTimeString + " seconds."); if (DO_SYSTEM_EXIT) { System.exit(returnCode); } } catch (RemoteCommandException rme) { CliLog.error(rme.getMessage()); } catch (Exception e) { e.printStackTrace(); if (DO_SYSTEM_EXIT) { System.exit(ERROR_STATUS); } } } else { System.err.println("No command has been specified. Please specify a command."); (new HelpCommand()).usage(); if (DO_SYSTEM_EXIT) { System.exit(ERROR_STATUS); } } }
From source file:org.artifactory.ui.rest.service.home.GetHomePageService.java
/** * return system up time//from www .j av a2 s. co m * * @return up time as string */ public String getUptime() { long uptime = ContextHelper.get().getUptime(); String uptimeStr = DurationFormatUtils.formatDuration(uptime, "d'd' H'h' m'm' s's'"); return uptimeStr; }
From source file:org.artifactory.webapp.wicket.page.browse.treebrowser.tabs.general.panels.GeneralInfoPanel.java
private void addItemInfoLabels(FieldSetBorder infoBorder, ItemInfo itemInfo) { LabeledValue sizeLabel = new LabeledValue("size", "Size: "); infoBorder.add(sizeLabel);/* w w w . j av a 2s . c o m*/ LabeledValue lastModified = new LabeledValue("lastModified", "Last Modified: "); infoBorder.add(lastModified); HelpBubble lastModifiedHelp = new HelpBubble("lastModified.help", "The time this artifact's file was modified. \nWill be identical to the artifact's 'Created' date when not available \n(for example, when deploying without the 'X-Artifactory-Last-Modified' request header)."); infoBorder.add(lastModifiedHelp); String created = centralConfigService.format(itemInfo.getCreated()) + " " + DurationFormatUtils .formatDuration(System.currentTimeMillis() - itemInfo.getCreated(), "(d'd' H'h' m'm' s's' ago)"); LabeledValue createdLabel = new LabeledValue("created", "Created: ", created); infoBorder.add(createdLabel); infoBorder.add( new HelpBubble("created.help", "The time this artifact was deployed to or cached in Artifactory.")); LabeledValue moduleId = new LabeledValue("moduleId", "Module ID: "); infoBorder.add(moduleId); // disable/enable and set info according to the node type if (itemInfo.isFolder()) { lastModified.setVisible(false); lastModifiedHelp.setVisible(false); sizeLabel.setVisible(false); moduleId.setVisible(false); } else { FileInfo file = (FileInfo) itemInfo; ModuleInfo moduleInfo = repositoryService.getItemModuleInfo(file.getRepoPath()); long size = file.getSize(); //If we are looking at a cached item, check the expiry from the remote repository String ageStr = centralConfigService.format(itemInfo.getLastModified()) + " " + DurationFormatUtils.formatDuration(file.getAge(), "(d'd' H'h' m'm' s's' ago)"); lastModified.setValue(ageStr); sizeLabel.setValue(StorageUnit.toReadableString(size)); if (moduleInfo.isValid()) { moduleId.setValue(moduleInfo.getPrettyModuleId()); } else { moduleId.setValue("N/A"); } } }
From source file:org.betaconceptframework.astroboa.engine.jcr.io.Deserializer.java
public <T> T deserializeContent(InputStream source, boolean jsonSource, Class<T> classWhoseContentIsImported, ImportConfiguration configuration) { if (configuration != null) { persistMode = configuration.getPersistMode(); version = configuration.isVersion(); updateLastModificationDate = configuration.isUpdateLastModificationTime(); }// w w w .j a v a2 s . c o m if (persistMode == null) { if (classWhoseContentIsImported == Repository.class || List.class.isAssignableFrom(classWhoseContentIsImported)) { persistMode = PersistMode.PERSIST_ENTITY_TREE; } else { persistMode = PersistMode.DO_NOT_PERSIST; } } context = new Context(cmsRepositoryEntityUtils, cmsQueryHandler, session, configuration); XMLStreamReader xmlStreamReader = null; SAXSource saxSource = null; try { Object entity = null; long start = System.currentTimeMillis(); if (jsonSource) { xmlStreamReader = CmsEntityDeserialization.Context.createJSONReader(source, true, classWhoseContentIsImported); JsonImportContentHandler<T> handler = new JsonImportContentHandler(classWhoseContentIsImported, this); XMLStreamReaderToContentHandler xmlStreamReaderToContentHandler = new XMLStreamReaderToContentHandler( xmlStreamReader, handler, false, false); xmlStreamReaderToContentHandler.bridge(); entity = handler.getResult(); logger.debug(" Unmarshal json to {} took {}", classWhoseContentIsImported.getSimpleName(), DurationFormatUtils.formatDuration(System.currentTimeMillis() - start, "HH:mm:ss.SSSSSS")); } else { saxSource = CmsEntityDeserialization.Context.createSAXSource(source, repositoryEntityResolver, false); //we explicitly disable validation because partial saves are allowed ImportContentHandler<T> handler = new ImportContentHandler(classWhoseContentIsImported, this); saxSource.getXMLReader().setContentHandler(handler); saxSource.getXMLReader().parse(saxSource.getInputSource()); entity = handler.getImportResult(); logger.debug("Unmarshal xml to {} took {}", classWhoseContentIsImported.getSimpleName(), DurationFormatUtils.formatDuration(System.currentTimeMillis() - start, "HH:mm:ss.SSSSSS")); } //If entity is not of type T then a class cast exception is thrown. if (entity instanceof CmsRepositoryEntity) { entity = save((CmsRepositoryEntity) entity); } return (T) entity; } catch (CmsException e) { logger.error("", e); throw e; } catch (Exception e) { logger.error("", e); throw new CmsException(e.getMessage()); } finally { if (xmlStreamReader != null) { try { xmlStreamReader.close(); } catch (Exception e) { //Ignore exception } } if (saxSource != null && saxSource.getInputSource() != null) { IOUtils.closeQuietly(saxSource.getInputSource().getByteStream()); IOUtils.closeQuietly(saxSource.getInputSource().getCharacterStream()); } if (context != null) { context.dispose(); context = null; } } }