List of usage examples for java.text DateFormat getInstance
public static final DateFormat getInstance()
From source file:org.talend.updates.runtime.preference.UpdatesRuntimePreference.java
public Date getDate(String key) throws Exception { String str = getValue(key);/*from w w w . j a va 2s. co m*/ if (StringUtils.isBlank(str)) { return null; } return DateFormat.getInstance().parse(str); }
From source file:com.rodaxsoft.junit.mailgun.MailgunManagerTestCase.java
/** * @return A ListMemberRequest object//ww w. j av a2 s . c o m */ private ListMemberRequest getListMemberRequest() { // Create the vars object JSONObject objects = new JSONObject(); objects.put("city", "Seattle"); objects.put("created", DateFormat.getInstance().format(new Date())); objects.put("province", "WA"); // Create the request object ListMemberRequest member = new ListMemberRequest().setAddress(LIST_MEMBER_ADDRESS).setName("John Doe") .setJSONVar(objects.toString()); return member; }
From source file:org.bombusim.networking.NetworkSocketDataStream.java
public void setTLS() throws IOException { LimeLog.i("Socket", "Switching to secure socket layer", null); //TODO: check on different devices: // !!! ENSURE TLS enabled in account settings before test // 1. emulator/2.2 - SSLPeerUnverifiedException (jabber.ru, google.com) - bug in emulator v2.2 // 2. cyanogen/2.3 - works (all hosts) // 3. emulator/ics - works // 4. Gratia/2.2 - works SSLSocketFactory sf =/* www . jav a 2 s . c o m*/ //SSLCertificateSocketFactory.getDefault(20000, null); SSLCertificateSocketFactory.getInsecure(20000, null); //TODO: check on different devices: // 1. emulator/2.2 - works // 2. cyanogen/2.3 - works //KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); //trustStore.load(null, null); //SSLSocketFactory sf = new AndroidSSLSocketFactory(trustStore); //sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); final SSLSocket ssls = (SSLSocket) sf.createSocket(socket, host, port, true); ssls.addHandshakeCompletedListener(new HandshakeCompletedListener() { @Override public void handshakeCompleted(HandshakeCompletedEvent event) { X509Certificate[] certs; try { certs = ssls.getSession().getPeerCertificateChain(); } catch (SSLPeerUnverifiedException e) { return; } StringBuilder so = new StringBuilder(); for (X509Certificate cert : certs) { so.append("X509 Certificate:\n").append(" Subject:"); appendPrincipal(so, cert.getSubjectDN()); so.append("\n Issued by:"); appendPrincipal(so, cert.getIssuerDN()); so.append("\n Valid from: ").append(DateFormat.getInstance().format(cert.getNotBefore())); so.append("\n Expired after: ").append(DateFormat.getInstance().format(cert.getNotAfter())); so.append("\n\n"); } certificateInfo = so.toString(); LimeLog.i("Socket", "Certificate chain verified", certificateInfo); } private void appendPrincipal(StringBuilder so, Principal p) { String name = p.getName(); if (name == null) { so.append("<null>\n"); return; } String elements[] = name.split(","); for (String e : elements) { so.append("\n ").append(e); } so.append("\n"); } }); ssls.startHandshake(); socket = ssls; istream = socket.getInputStream(); ostream = socket.getOutputStream(); }
From source file:org.sonatype.gshell.commands.vfs.FileInfoCommand.java
public Object execute(final CommandContext context) throws Exception { assert context != null; IO io = context.getIo();/*from w w w . j a v a 2 s. c om*/ FileObject file = resolveFile(context, path); io.println("URL: {}", file.getURL()); io.println("Name: {}", file.getName()); io.println("BaseName: {}", file.getName().getBaseName()); io.println("Extension: {}", file.getName().getExtension()); io.println("Path: {}", file.getName().getPath()); io.println("Scheme: {}", file.getName().getScheme()); io.println("URI: {}", file.getName().getURI()); io.println("Root URI: {}", file.getName().getRootURI()); io.println("Parent: {}", file.getName().getParent()); io.println("Type: {}", file.getType()); io.println("Exists: {}", file.exists()); io.println("Readable: {}", file.isReadable()); io.println("Writeable: {}", file.isWriteable()); io.println("Root path: {}", file.getFileSystem().getRoot().getName().getPath()); if (file.exists()) { FileContent content = file.getContent(); FileContentInfo contentInfo = content.getContentInfo(); io.println("Content type: {}", contentInfo.getContentType()); io.println("Content encoding: {}", contentInfo.getContentEncoding()); try { // noinspection unchecked Map<String, Object> attrs = content.getAttributes(); if (attrs != null && !attrs.isEmpty()) { io.println("Attributes:"); for (Map.Entry<String, Object> entry : attrs.entrySet()) { io.println(" {}='{}'", entry.getKey(), entry.getValue()); } } } catch (FileSystemException e) { io.println("File attributes are NOT supported"); } try { Certificate[] certs = content.getCertificates(); if (certs != null && certs.length != 0) { io.println("Certificate:"); for (Certificate cert : certs) { io.println(" {}", cert); } } } catch (FileSystemException e) { io.println("File certificates are NOT supported"); } if (file.getType().equals(FileType.FILE)) { io.println("Size: {} bytes", content.getSize()); } else if (file.getType().hasChildren() && file.isReadable()) { FileObject[] children = file.getChildren(); io.println("Directory with {} files", children.length); for (int iterChildren = 0; iterChildren < children.length; iterChildren++) { io.println("#{}:{}", iterChildren, children[iterChildren].getName()); if (iterChildren > 5) { break; } } } io.println("Last modified: {}", DateFormat.getInstance().format(new Date(content.getLastModifiedTime()))); } else { io.println("The file does not exist"); } FileObjects.close(file); return Result.SUCCESS; }
From source file:org.talend.updates.runtime.preference.UpdatesRuntimePreference.java
public Date getDefaultDate(String key) throws Exception { String str = getDefault(key); if (StringUtils.isBlank(str)) { return null; }/* w w w . j a va 2 s. c om*/ return DateFormat.getInstance().parse(str); }
From source file:org.talend.updates.runtime.preference.UpdatesRuntimePreference.java
public void setDate(String key, Date date) { String dateStr = null;// w w w . ja va 2 s . com if (date != null) { dateStr = DateFormat.getInstance().format(date); } setValue(key, dateStr, false); }
From source file:org.talend.updates.runtime.preference.UpdatesRuntimePreference.java
public void setDefault(String key, Date date) { String dateStr = null;/*from w w w.ja v a 2 s . c o m*/ if (date != null) { dateStr = DateFormat.getInstance().format(date); } setValue(key, dateStr, true); }
From source file:tain.kr.test.vfs.v01.ShowProperties.java
private static void test01(String[] args) throws Exception { if (flag)/*from ww w .j ava 2 s . c o m*/ new ShowProperties(); if (flag) { if (args.length == 0) { System.err.println("Please pass the name of a file as parameter."); System.err.println("e.g. java org.apache.commons.vfs2.example.ShowProperties LICENSE.txt"); return; } for (final String arg : args) { try { final FileSystemManager mgr = VFS.getManager(); System.out.println(); System.out.println("Parsing : " + arg); final FileObject file = mgr.resolveFile(arg); System.out.println("URL : " + file.getURL()); System.out.println("getName() : " + file.getName()); System.out.println("BaseName : " + file.getName().getBaseName()); System.out.println("Extension : " + file.getName().getExtension()); System.out.println("Path : " + file.getName().getPath()); System.out.println("Scheme : " + file.getName().getScheme()); System.out.println("URI : " + file.getName().getURI()); System.out.println("Root URI : " + file.getName().getRootURI()); System.out.println("Parent : " + file.getName().getParent()); System.out.println("Type : " + file.getType()); System.out.println("Exists : " + file.exists()); System.out.println("Readable : " + file.isReadable()); System.out.println("Writeable : " + file.isWriteable()); System.out.println("Root path : " + file.getFileSystem().getRoot().getName().getPath()); if (file.exists()) { if (file.getType().equals(FileType.FILE)) { System.out.println("Size: " + file.getContent().getSize() + " bytes"); } else if (file.getType().equals(FileType.FOLDER) && file.isReadable()) { final FileObject[] children = file.getChildren(); System.out.println("Directory with " + children.length + " files"); for (int iterChildren = 0; iterChildren < children.length; iterChildren++) { System.out.println("#" + iterChildren + ": " + children[iterChildren].getName()); if (iterChildren > SHOW_MAX) { break; } } } System.out.println("Last modified: " + DateFormat.getInstance() .format(new Date(file.getContent().getLastModifiedTime()))); } else { System.out.println("The file does not exist"); } file.close(); } catch (final FileSystemException ex) { ex.printStackTrace(); } } } }
From source file:com.nbos.phonebook.sync.syncadapter.SyncAdapter.java
void doSync() throws AuthenticationException, ParseException, JSONException, IOException { Log.i(tag, "doSync()"); String lastUpdated = accountManager.getUserData(account, Constants.ACCOUNT_LAST_UPDATED), lastUpdateStarted = accountManager.getUserData(account, Constants.ACCOUNT_LAST_UPDATE_STARTED); Log.i(tag, "Last update started: " + lastUpdateStarted + ", updated is: " + lastUpdated); Cloud cloud = new Cloud(context, account.name, authtoken); String startTimestamp = cloud.getTimestamp(); accountManager.setUserData(account, Constants.ACCOUNT_LAST_UPDATE_STARTED, startTimestamp); String endTimestamp = cloud.sync(lastUpdated); Log.i(tag, "Timestamp is: " + endTimestamp); accountManager.setUserData(account, Constants.ACCOUNT_LAST_UPDATED, endTimestamp); Widget.AppService.message = "Phonebook last updated: " + DateFormat.getInstance().format(new Date(Long.parseLong(endTimestamp))); context.startService(new Intent(context, AppService.class)); }
From source file:uk.ac.ox.oucs.vle.ModuleImpl.java
/** * Email course administrator if course component is about to close * @param groups A list of all groups that may have closing components. *//*from ww w . j ava 2s.c o m*/ private void modulesClosing(final List<CourseGroupDAO> groups) { for (CourseGroupDAO group : groups) { final Set<CourseComponentDAO> components = group.getComponents(); final Set<CourseComponentDAO> componentsClosing = new HashSet<CourseComponentDAO>(); for (CourseComponentDAO component : components) { if (isToday(component.getCloses())) { // Component is about to close log.info("Component is about to close [" + component.getPresentationId() + ":" + DateFormat.getInstance().format(component.getCloses()) + ":" + component.getTitle() + "]"); componentsClosing.add(component); } } if (!componentsClosing.isEmpty()) { for (String administrator : group.getAdministrators()) { sendModuleClosingEmail(administrator, group, componentsClosing); } } } }