List of usage examples for java.text DateFormat getDateTimeInstance
public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle)
From source file:org.jactr.entry.iterative.IterativeMain.java
/** * @param url/*ww w. ja v a 2s .com*/ * @param listener * @param iterations * @throws Exception */ public void run(URL url) { Collection<IIterativeRunListener> listeners = Collections.EMPTY_LIST; try { Document environment = loadEnvironment(url); int iterations = getIterations(environment); listeners = createListeners(environment); String id = System.getProperty("iterative-id"); if (id == null) id = ""; else id = "-" + id; File rootDir = new File(System.getProperty("user.dir")); PrintWriter log = new PrintWriter(new FileWriter("iterative-log" + id + ".xml")); log.println("<iterative-run total=\"" + iterations + "\">"); DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG); boolean shouldExit = false; for (IIterativeRunListener listener : listeners) try { listener.start(iterations); } catch (TerminateIterativeRunException tire) { shouldExit = true; } catch (Exception e) { if (LOGGER.isErrorEnabled()) LOGGER.error(listener + " threw an exception on start ", e); } long startTime = System.currentTimeMillis(); for (int i = 1; i <= iterations; i++) { if (shouldExit) break; /* * create a new working directory */ File workingDir = new File(rootDir, "run-" + i); workingDir.mkdirs(); ACTRRuntime.getRuntime().setWorkingDirectory(workingDir); log.println(" <run itr=\"" + i + "\" start=\"" + format.format(new Date()) + "\">"); try { /* * let's do it. */ if (_aggressiveGC) System.gc(); iteration(i, iterations, environment, url, listeners, log); if (_aggressiveGC) System.gc(); } catch (TerminateIterativeRunException tire) { shouldExit = true; } catch (Exception e1) { log.print(" <exception><![CDATA["); e1.printStackTrace(log); log.print("]]></exception>"); for (IIterativeRunListener listener : listeners) try { listener.exceptionThrown(i, null, e1); } catch (TerminateIterativeRunException tire) { shouldExit = true; } catch (Exception e2) { LOGGER.error(listener + " threw an exception on exception notification ", e2); } } log.println(" </run>"); log.flush(); if (workingDir.list().length == 0) workingDir.delete(); } String duration = duration(startTime, System.currentTimeMillis()); if (LOGGER.isDebugEnabled()) LOGGER.debug("Total running time : " + duration); log.println(" <duration value=\"" + duration + "\"/>"); log.println("</iterative-run>"); log.close(); } catch (Exception e) { LOGGER.error("Failed to run fully", e); for (IIterativeRunListener listener : listeners) try { // we ignore the return value here since we're exiting anyway listener.exceptionThrown(0, null, e); } catch (TerminateIterativeRunException tire) { // silently swallow since we're already exiting } catch (Exception e2) { LOGGER.error(listener + " threw an exception during exception notification ", e2); } } finally { for (IIterativeRunListener listener : listeners) try { listener.stop(); } catch (Exception e) { LOGGER.error(listener + " threw an exception on stop ", e); } } }
From source file:com.concursive.connect.web.modules.documents.dao.FileFolder.java
/** * Gets the enteredDateTimeString attribute of the FileFolder object * * @return The enteredDateTimeString value *///w w w .j a v a2s .c o m public String getEnteredDateTimeString() { try { return DateFormat.getDateTimeInstance(3, 3).format(entered); } catch (NullPointerException e) { } return ""; }
From source file:com.sludev.commons.vfs.simpleshell.SimpleShell.java
/** * Does an 'ls' command./*from ww w . java 2 s. c om*/ * * @param cmd * @throws org.apache.commons.vfs2.FileSystemException */ public void ls(final String[] cmd) throws FileSystemException { int pos = 1; final boolean recursive; if (cmd.length > pos && cmd[pos].equals("-R")) { recursive = true; pos++; } else { recursive = false; } final FileObject file; if (cmd.length > pos) { file = mgr.resolveFile(cwd, cmd[pos]); } else { file = cwd; } switch (file.getType()) { case FOLDER: // List the contents System.out.println("Contents of " + file.getName()); listChildren(file, recursive, ""); break; case FILE: // Stat the file System.out.println(file.getName()); final FileContent content = file.getContent(); System.out.println("Size: " + content.getSize() + " bytes."); final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); final String lastMod = dateFormat.format(new Date(content.getLastModifiedTime())); System.out.println("Last modified: " + lastMod); break; case IMAGINARY: System.out.println(String.format("File '%s' is IMAGINARY", file.getName())); break; default: log.error(String.format("Unkown type '%d' on '%s'", file.getType(), file.getName())); break; } }
From source file:mobisocial.bento.anyshare.util.DBHelper.java
public long storePicobjInDatabase(DbObj obj, Context context) { long localId = -1; // if replace entry, set ID long hash = obj.getHash(); byte[] raw = obj.getRaw(); String feedname = obj.getFeedName(); long parentid = 0; try {//w ww . j av a2 s .com if (obj.getJson().has("target_relation") && obj.getJson().getString("target_relation").equals("parent") && obj.getJson().has("target_hash")) { parentid = objIdForHash(obj.getJson().getLong("target_hash")); } } catch (JSONException e) { e.printStackTrace(); } DbUser usr = obj.getSender(); String sender = ""; if (usr != null) { sender = usr.getName(); } long timestamp = 0; String title = "Picture"; try { timestamp = Long.parseLong(obj.getJson().getString("timestamp")); } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } // add object long objId = (localId == -1) ? getNextId() : localId; String desc = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT) .format(new Date(timestamp)); if (!sender.isEmpty()) { desc += " by " + sender; } ContentValues cv = new ContentValues(); cv.put(ItemObject._ID, objId); cv.put(ItemObject.FEEDNAME, feedname); cv.put(ItemObject.TITLE, title); cv.put(ItemObject.DESC, desc); cv.put(ItemObject.TIMESTAMP, timestamp); cv.put(ItemObject.OBJHASH, hash); cv.put(ItemObject.PARENT_ID, parentid); if (raw != null) { cv.put(ItemObject.RAW, raw); } long newObjId = getWritableDatabase().insertOrThrow(ItemObject.TABLE, null, cv); return objId; }
From source file:org.hyperic.hq.measurement.shared.MeasTabManagerUtil.java
private static String getDateStr(long timems) { return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT) .format(new java.util.Date(timems)); }
From source file:org.apache.hadoop.filecache.TrackerDistributedCacheManager.java
/** * Download a given path to the local file system. * @param conf the job's configuration//from w w w .ja v a 2s .c om * @param source the source to copy from * @param destination where to copy the file. must be local fs * @param desiredTimestamp the required modification timestamp of the source * @param isArchive is this an archive that should be expanded * @param permission the desired permissions of the file. * @return for archives, the number of bytes in the unpacked directory * @throws IOException */ public static long downloadCacheObject(Configuration conf, URI source, Path destination, long desiredTimestamp, boolean isArchive, FsPermission permission) throws IOException { FileSystem sourceFs = FileSystem.get(source, conf); FileSystem localFs = FileSystem.getLocal(conf); Path sourcePath = new Path(source.getPath()); long modifiedTime = sourceFs.getFileStatus(sourcePath).getModificationTime(); if (modifiedTime != desiredTimestamp) { DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); throw new IOException("The distributed cache object " + source + " changed during the job from " + df.format(new Date(desiredTimestamp)) + " to " + df.format(new Date(modifiedTime))); } Path parchive = null; if (isArchive) { parchive = new Path(destination, destination.getName()); } else { parchive = destination; } // if the file already exists, we are done if (localFs.exists(parchive)) { return 0; } // the final directory for the object Path finalDir = parchive.getParent(); // the work directory for the object Path workDir = createRandomPath(finalDir); LOG.info("Creating " + destination.getName() + " in " + workDir + " with " + permission); if (!localFs.mkdirs(workDir, permission)) { throw new IOException("Mkdirs failed to create directory " + workDir); } Path workFile = new Path(workDir, parchive.getName()); sourceFs.copyToLocalFile(sourcePath, workFile); localFs.setPermission(workFile, permission); if (isArchive) { String tmpArchive = workFile.getName().toLowerCase(); File srcFile = new File(workFile.toString()); File destDir = new File(workDir.toString()); LOG.info(String.format("Extracting %s to %s", srcFile.toString(), destDir.toString())); if (tmpArchive.endsWith(".jar")) { RunJar.unJar(srcFile, destDir); } else if (tmpArchive.endsWith(".zip")) { FileUtil.unZip(srcFile, destDir); } else if (isTarFile(tmpArchive)) { FileUtil.unTar(srcFile, destDir); } else { LOG.warn(String.format("Cache file %s specified as archive, but not valid extension.", srcFile.toString())); // else will not do anyhting // and copy the file into the dir as it is } FileUtil.chmod(destDir.toString(), "ugo+rx", true); } // promote the output to the final location if (!localFs.rename(workDir, finalDir)) { localFs.delete(workDir, true); if (!localFs.exists(finalDir)) { throw new IOException("Failed to promote distributed cache object " + workDir + " to " + finalDir); } // someone else promoted first return 0; } LOG.info(String.format("Cached %s as %s", source.toString(), destination.toString())); long cacheSize = FileUtil.getDU(new File(parchive.getParent().toString())); return cacheSize; }
From source file:net.clcworld.thermometer.TakeTemperatureReadingActivity.java
public void sendData(final String patientId, final String temperature, final String feeling, final ArrayList<String> symptoms) { final String targetUrl = mPrefs.getString("targetUrl", ""); final String idField = mPrefs.getString("idField", ""); final String tempField = mPrefs.getString("tempField", ""); final String feelingField = mPrefs.getString("feelingField", ""); final String symptomsField = mPrefs.getString("symptomsField", ""); if (targetUrl.length() > 0) { UploadUtils.sendData(targetUrl, idField, tempField, feelingField, symptomsField, patientId, temperature, feeling, symptoms);//from www. ja va2s. co m Toast.makeText(mSelf, R.string.submitted, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(mSelf, R.string.saved, Toast.LENGTH_SHORT).show(); } String entry = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date()) + " " + temperature + "F " + feeling + "\n"; Editor editor = mPrefs.edit(); editor.putString(PREFSKEY_HISTORY, entry + mHistory); editor.commit(); finish(); }
From source file:com.diablominer.DiabloMiner.DiabloMiner.java
public static String dateTime() { return "[" + DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date()) + "]"; }
From source file:org.rhq.enterprise.server.measurement.util.MeasurementDataManagerUtility.java
public static String getNextRotationTime() { long now = System.currentTimeMillis(); long day = now / MILLISECONDS_PER_DAY; long timeOfDay = now - (day * MILLISECONDS_PER_DAY); long remaining = MILLISECONDS_PER_TABLE - timeOfDay; long nextRotation = now + remaining; if (nextRotation < now) { nextRotation += MILLISECONDS_PER_TABLE; }//from w w w.j a va 2 s . c o m return DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.FULL).format(new Date(nextRotation)); }
From source file:op.care.values.PnlValues.java
private JPanel createContentPanel4Year(final ResValueTypes vtype, final int year) { final String keyYears = vtype.getID() + ".xtypes." + Integer.toString(year) + ".year"; java.util.List<ResValue> myValues; synchronized (mapType2Values) { if (!mapType2Values.containsKey(keyYears)) { mapType2Values.put(keyYears, ResValueTools.getResValues(resident, vtype, year)); }// w w w.j a v a 2 s . c om if (mapType2Values.get(keyYears).isEmpty()) { JLabel lbl = new JLabel(SYSTools.xx("misc.msg.novalue")); JPanel pnl = new JPanel(); pnl.add(lbl); return pnl; } myValues = mapType2Values.get(keyYears); } JPanel pnlYear = new JPanel(new VerticalLayout()); pnlYear.setOpaque(false); for (final ResValue resValue : myValues) { String title = "<html><table border=\"0\">" + "<tr>" + "<td width=\"200\" align=\"left\">" + DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT).format(resValue.getPit()) + " [" + resValue.getID() + "]</td>" + "<td width=\"340\" align=\"left\">" + ResValueTools.getValueAsHTML(resValue) + "</td>" + "<td width=\"200\" align=\"left\">" + resValue.getUser().getFullname() + "</td>" + "</tr>" + "</table>" + "</html>"; final DefaultCPTitle pnlTitle = new DefaultCPTitle(title, null); pnlTitle.getMain().setBackground(GUITools.blend(vtype.getColor(), Color.WHITE, 0.1f)); pnlTitle.getMain().setOpaque(true); if (resValue.isObsolete()) { pnlTitle.getAdditionalIconPanel().add(new JLabel(SYSConst.icon22eraser)); } if (resValue.isReplacement()) { pnlTitle.getAdditionalIconPanel().add(new JLabel(SYSConst.icon22edited)); } if (!resValue.getText().trim().isEmpty()) { pnlTitle.getAdditionalIconPanel().add(new JLabel(SYSConst.icon22info)); } if (pnlTitle.getAdditionalIconPanel().getComponentCount() > 0) { pnlTitle.getButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { GUITools.showPopup( GUITools.getHTMLPopup(pnlTitle.getButton(), ResValueTools.getInfoAsHTML(resValue)), SwingConstants.NORTH); } }); } if (!resValue.getAttachedFilesConnections().isEmpty()) { /*** * _ _ _____ _ _ * | |__ | |_ _ __ | ___(_) | ___ ___ * | '_ \| __| '_ \| |_ | | |/ _ \/ __| * | |_) | |_| | | | _| | | | __/\__ \ * |_.__/ \__|_| |_|_| |_|_|\___||___/ * */ final JButton btnFiles = new JButton( Integer.toString(resValue.getAttachedFilesConnections().size()), SYSConst.icon22greenStar); btnFiles.setToolTipText(SYSTools.xx("misc.btnfiles.tooltip")); btnFiles.setForeground(Color.BLUE); btnFiles.setHorizontalTextPosition(SwingUtilities.CENTER); btnFiles.setFont(SYSConst.ARIAL18BOLD); btnFiles.setPressedIcon(SYSConst.icon22Pressed); btnFiles.setAlignmentX(Component.RIGHT_ALIGNMENT); btnFiles.setAlignmentY(Component.TOP_ALIGNMENT); btnFiles.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnFiles.setContentAreaFilled(false); btnFiles.setBorder(null); btnFiles.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgFiles(resValue, new Closure() { @Override public void execute(Object o) { EntityManager em = OPDE.createEM(); final ResValue myValue = em.find(ResValue.class, resValue.getID()); em.close(); synchronized (mapType2Values) { mapType2Values.get(keyYears).remove(resValue); mapType2Values.get(keyYears).add(myValue); Collections.sort(mapType2Values.get(keyYears)); } createCP4Year(vtype, year); buildPanel(); } }); } }); btnFiles.setEnabled(OPDE.isFTPworking()); pnlTitle.getRight().add(btnFiles); } if (!resValue.getAttachedProcessConnections().isEmpty()) { /*** * _ _ ____ * | |__ | |_ _ __ | _ \ _ __ ___ ___ ___ ___ ___ * | '_ \| __| '_ \| |_) | '__/ _ \ / __/ _ \/ __/ __| * | |_) | |_| | | | __/| | | (_) | (_| __/\__ \__ \ * |_.__/ \__|_| |_|_| |_| \___/ \___\___||___/___/ * */ final JButton btnProcess = new JButton( Integer.toString(resValue.getAttachedProcessConnections().size()), SYSConst.icon22redStar); btnProcess.setToolTipText(SYSTools.xx("misc.btnprocess.tooltip")); btnProcess.setForeground(Color.YELLOW); btnProcess.setHorizontalTextPosition(SwingUtilities.CENTER); btnProcess.setFont(SYSConst.ARIAL18BOLD); btnProcess.setPressedIcon(SYSConst.icon22Pressed); btnProcess.setAlignmentX(Component.RIGHT_ALIGNMENT); btnProcess.setAlignmentY(Component.TOP_ALIGNMENT); btnProcess.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnProcess.setContentAreaFilled(false); btnProcess.setBorder(null); btnProcess.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgProcessAssign(resValue, new Closure() { @Override public void execute(Object o) { if (o == null) { return; } Pair<ArrayList<QProcess>, ArrayList<QProcess>> result = (Pair<ArrayList<QProcess>, ArrayList<QProcess>>) o; ArrayList<QProcess> assigned = result.getFirst(); ArrayList<QProcess> unassigned = result.getSecond(); EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); ResValue myValue = em.merge(resValue); em.lock(myValue, LockModeType.OPTIMISTIC_FORCE_INCREMENT); ArrayList<SYSVAL2PROCESS> attached = new ArrayList<SYSVAL2PROCESS>( resValue.getAttachedProcessConnections()); for (SYSVAL2PROCESS linkObject : attached) { if (unassigned.contains(linkObject.getQProcess())) { linkObject.getQProcess().getAttachedNReportConnections() .remove(linkObject); linkObject.getResValue().getAttachedProcessConnections() .remove(linkObject); em.merge(new PReport( SYSTools.xx(PReportTools.PREPORT_TEXT_REMOVE_ELEMENT) + ": " + myValue.getTitle() + " ID: " + myValue.getID(), PReportTools.PREPORT_TYPE_REMOVE_ELEMENT, linkObject.getQProcess())); em.remove(linkObject); } } attached.clear(); for (QProcess qProcess : assigned) { java.util.List<QProcessElement> listElements = qProcess.getElements(); if (!listElements.contains(myValue)) { QProcess myQProcess = em.merge(qProcess); SYSVAL2PROCESS myLinkObject = em .merge(new SYSVAL2PROCESS(myQProcess, myValue)); em.merge(new PReport( SYSTools.xx(PReportTools.PREPORT_TEXT_ASSIGN_ELEMENT) + ": " + myValue.getTitle() + " ID: " + myValue.getID(), PReportTools.PREPORT_TYPE_ASSIGN_ELEMENT, myQProcess)); qProcess.getAttachedResValueConnections().add(myLinkObject); myValue.getAttachedProcessConnections().add(myLinkObject); } } em.getTransaction().commit(); synchronized (mapType2Values) { mapType2Values.get(keyYears).remove(resValue); mapType2Values.get(keyYears).add(myValue); Collections.sort(mapType2Values.get(keyYears)); } createCP4Year(vtype, year); buildPanel(); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (RollbackException ole) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } }); } }); btnProcess.setEnabled(OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)); pnlTitle.getRight().add(btnProcess); } /*** * __ __ * | \/ | ___ _ __ _ _ * | |\/| |/ _ \ '_ \| | | | * | | | | __/ | | | |_| | * |_| |_|\___|_| |_|\__,_| * */ final JButton btnMenu = new JButton(SYSConst.icon22menu); btnMenu.setPressedIcon(SYSConst.icon22Pressed); btnMenu.setAlignmentX(Component.RIGHT_ALIGNMENT); btnMenu.setAlignmentY(Component.TOP_ALIGNMENT); btnMenu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnMenu.setContentAreaFilled(false); btnMenu.setBorder(null); btnMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JidePopup popup = new JidePopup(); popup.setMovable(false); popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS)); popup.setOwner(btnMenu); popup.removeExcludedComponent(btnMenu); JPanel pnl = getMenu(resValue); popup.getContentPane().add(pnl); popup.setDefaultFocusComponent(pnl); GUITools.showPopup(popup, SwingConstants.WEST); } }); btnMenu.setEnabled(!resValue.isObsolete()); pnlTitle.getRight().add(btnMenu); pnlYear.add(pnlTitle.getMain()); synchronized (linemap) { linemap.put(resValue, pnlTitle.getMain()); } } return pnlYear; }