List of usage examples for java.util Date parse
@Deprecated public static long parse(String s)
From source file:org.gradle.api.internal.artifacts.repositories.transport.http.HttpGetResource.java
public long getLastModified() { Header responseHeader = method.getResponseHeader("last-modified"); if (responseHeader == null) { return 0; }// w w w.java 2 s .c om try { return Date.parse(responseHeader.getValue()); } catch (Exception e) { return 0; } }
From source file:com.breadwallet.tools.util.JsonParser.java
public static JSONArray getBackUpJSonArray(Activity activity) { String jsonString = callURL("https://bitpay.com/rates"); JSONArray jsonArray = null;//from w w w .j a va2 s . c o m if (jsonString == null) return null; try { JSONObject obj = new JSONObject(jsonString); jsonArray = obj.getJSONArray("data"); JSONObject headers = obj.getJSONObject("headers"); String secureDate = headers.getString("Date"); @SuppressWarnings("deprecation") long date = Date.parse(secureDate) / 1000; SharedPreferencesManager.putSecureTime(activity, date); } catch (JSONException e) { e.printStackTrace(); } return jsonArray; }
From source file:com.android.applications.todoist.containers.Task.java
public Task(JSONObject obj, String type) { this.type = type; try {/*from w ww . j a v a2s. c o m*/ this.due_date = new Date(Date.parse(obj.getString(Constants.JSON_DUEDATE))); } catch (JSONException e) { this.due_date = new Date(); e.printStackTrace(); } try { this.user_id = obj.getString(Constants.JSON_USERID); } catch (JSONException e) { this.user_id = ""; e.printStackTrace(); } try { this.collapsed = obj.getBoolean(Constants.JSON_COLLAPSED); } catch (JSONException e) { this.collapsed = false; e.printStackTrace(); } try { this.in_history = obj.getBoolean(Constants.JSON_INHISTORY); } catch (JSONException e8) { this.in_history = false; e8.printStackTrace(); } try { this.priority = obj.getInt(Constants.JSON_PRIORITY); } catch (JSONException e7) { this.priority = 0; e7.printStackTrace(); } try { this.item_order = obj.getInt(Constants.JSON_ITEMORDER); } catch (JSONException e6) { this.item_order = 0; e6.printStackTrace(); } try { this.content = obj.getString(Constants.JSON_CONTENT); } catch (JSONException e5) { this.content = ""; e5.printStackTrace(); } try { this.indent = obj.getInt(Constants.JSON_INDENT); } catch (JSONException e4) { this.indent = 0; e4.printStackTrace(); } try { this.project_id = obj.getString(Constants.JSON_PROJECTID); } catch (JSONException e3) { this.project_id = ""; e3.printStackTrace(); } try { this.id = obj.getString(Constants.JSON_ID); } catch (JSONException e2) { this.id = ""; e2.printStackTrace(); } try { this.checked = obj.getBoolean(Constants.JSON_CHECKED); } catch (JSONException e1) { this.checked = false; e1.printStackTrace(); } try { this.date_string = obj.getString(Constants.JSON_DATESTRING); } catch (JSONException e) { this.date_string = ""; e.printStackTrace(); } }
From source file:org.nuxeo.cm.mail.actionpipe.ExtractMessageInformation.java
@Override @SuppressWarnings("deprecation") public boolean execute(ExecutionContext context) throws MessagingException { File tmpOutput = null;//from ww w . j av a 2s . c om OutputStream out = null; try { Message originalMessage = context.getMessage(); if (log.isDebugEnabled()) { log.debug("Transforming message, original subject: " + originalMessage.getSubject()); } // fully load the message before trying to parse to // override most of server bugs, see // http://java.sun.com/products/javamail/FAQ.html#imapserverbug Message message; if (originalMessage instanceof MimeMessage) { message = new MimeMessage((MimeMessage) originalMessage); if (log.isDebugEnabled()) { log.debug("Transforming message after full load: " + message.getSubject()); } } else { // stuck with the original one message = originalMessage; } Address[] from = message.getFrom(); if (from != null) { Address addr = from[0]; if (addr instanceof InternetAddress) { InternetAddress iAddr = (InternetAddress) addr; context.put(SENDER_KEY, iAddr.getPersonal()); context.put(SENDER_EMAIL_KEY, iAddr.getAddress()); } else { context.put(SENDER_KEY, addr.toString()); } } Date receivedDate = message.getReceivedDate(); if (receivedDate == null) { // try to get header manually String[] dateHeader = message.getHeader("Date"); if (dateHeader != null) { try { long time = Date.parse(dateHeader[0]); receivedDate = new Date(time); } catch (IllegalArgumentException e) { // nevermind } } } if (receivedDate != null) { Calendar date = Calendar.getInstance(); date.setTime(receivedDate); context.put(RECEPTION_DATE_KEY, date); } String subject = message.getSubject(); if (subject != null) { subject = subject.trim(); } if (subject == null || "".equals(subject)) { subject = "<Unknown>"; } context.put(SUBJECT_KEY, subject); String[] messageIdHeader = message.getHeader("Message-ID"); if (messageIdHeader != null) { context.put(MESSAGE_ID_KEY, messageIdHeader[0]); } // TODO: pass it through initial context MimetypeRegistry mimeService = (MimetypeRegistry) context.getInitialContext().get(MIMETYPE_SERVICE_KEY); if (mimeService == null) { log.error("Could not retrieve mimetype service"); } // add all content as first blob tmpOutput = File.createTempFile("injectedEmail", ".eml"); Framework.trackFile(tmpOutput, tmpOutput); out = new FileOutputStream(tmpOutput); message.writeTo(out); Blob blob = Blobs.createBlob(tmpOutput, MESSAGE_RFC822_MIMETYPE, null, subject + ".eml"); List<Blob> blobs = new ArrayList<>(); blobs.add(blob); context.put(ATTACHMENTS_KEY, blobs); // process content getAttachmentParts(message, subject, mimeService, context); return true; } catch (IOException e) { log.error(e); } finally { IOUtils.closeQuietly(out); } return false; }
From source file:org.blanco.techmun.android.cproviders.ComentariosFetcher.java
public FetchComentariosResult fetchComentarios(Long eventoId, Integer pagina) { FetchComentariosResult result = new FetchComentariosResult(); HttpPost request = new HttpPost( TechMunContentProvider.MESAS_REST_SERVICE_BSAE_URI + "/comentarios/" + eventoId); HttpResponse response = null;/*from w w w . j a v a2s.c om*/ try { //prepare the entity for the request List<BasicNameValuePair> parameters = new ArrayList<BasicNameValuePair>(); parameters.add(new BasicNameValuePair("eventoId", eventoId.toString())); parameters.add(new BasicNameValuePair("pagina", pagina.toString())); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters, "utf-8"); request.setEntity(entity); response = httpClient.execute(request); if (response.getStatusLine().getStatusCode() == 200) { Comentarios comentarios = new Comentarios(); //The response return a Json object with the next page available for the net fetch and the selected objects JSONObject jsonComents = XmlParser.parseJSONObjectFromHttpEntity(response.getEntity()); pagina = jsonComents.getInt("pagina"); boolean mas = jsonComents.getBoolean("mas"); JSONArray coments = jsonComents.getJSONArray("comentarios"); for (int i = 0; i < coments.length(); i++) { long id = coments.getJSONObject(i).getLong("id"); String comentario = coments.getJSONObject(i).getString("comentario"); String autor = ""; if (coments.getJSONObject(i).has("autor")) { autor = coments.getJSONObject(i).getString("autor"); } String contacto = ""; if (coments.getJSONObject(i).has("contacto")) { contacto = coments.getJSONObject(i).getString("contacto"); } Date fecha = new Date(Date.parse(coments.getJSONObject(i).getString("fecha"))); Comentario c = new Comentario(); c.setId(id); c.setAutor(autor); c.setComentario(comentario); c.setContacto(contacto); c.setFecha(fecha); //if all the parsing went well add the new object to the results comentarios.addComentario(c); } //Prepare the result result.comentarios = comentarios; result.pagina = pagina; result.mas = mas; } } catch (Exception ex) { Log.e("techmun", "Error posting comentario", ex); } return result; }
From source file:com.breadwallet.tools.util.JsonParser.java
private static String callURL(String myURL) { // System.out.println("Requested URL_EA:" + myURL); StringBuilder sb = new StringBuilder(); HttpURLConnection urlConn = null; InputStreamReader in = null;// ww w . j av a 2 s . c o m try { URL url = new URL(myURL); urlConn = (HttpURLConnection) url.openConnection(); int versionNumber = 0; MainActivity app = MainActivity.app; if (app != null) { try { PackageInfo pInfo = null; pInfo = app.getPackageManager().getPackageInfo(app.getPackageName(), 0); versionNumber = pInfo.versionCode; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } } int stringId = 0; String appName = ""; if (app != null) { stringId = app.getApplicationInfo().labelRes; appName = app.getString(stringId); } String message = String.format(Locale.getDefault(), "%s/%d/%s", appName.isEmpty() ? "breadwallet" : appName, versionNumber, System.getProperty("http.agent")); urlConn.setRequestProperty("User-agent", message); urlConn.setReadTimeout(60 * 1000); String strDate = urlConn.getHeaderField("date"); if (strDate == null || app == null) { Log.e(TAG, "callURL: strDate == null!!!"); } else { @SuppressWarnings("deprecation") long date = Date.parse(strDate) / 1000; SharedPreferencesManager.putSecureTime(app, date); Assert.assertTrue(date != 0); } if (urlConn.getInputStream() != null) { in = new InputStreamReader(urlConn.getInputStream(), Charset.defaultCharset()); BufferedReader bufferedReader = new BufferedReader(in); int cp; while ((cp = bufferedReader.read()) != -1) { sb.append((char) cp); } bufferedReader.close(); } assert in != null; in.close(); } catch (Exception e) { return null; } return sb.toString(); }
From source file:org.transdroid.search.Isohunt.IsohuntAdapter.java
@Override public List<SearchResult> search(String query, SortOrder order, int maxResults) throws Exception { if (query == null) { return null; }//from ww w . j a v a 2s .c om // Build a search request parameters String encodedQuery = ""; try { encodedQuery = URLEncoder.encode(query, "UTF-8"); } catch (UnsupportedEncodingException e) { throw e; } // Build full URL string final int startAt = 0; // Provides future support for paged results String url = String.format(RPC_QUERYURL, encodedQuery, String.valueOf(startAt), String.valueOf(maxResults)); if (order == SortOrder.BySeeders) { url += RPC_SORT_SEEDS; } else { url += RPC_SORT_COMPOSITE; } // Setup request using GET HttpParams httpparams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpparams, CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(httpparams, CONNECTION_TIMEOUT); DefaultHttpClient httpclient = new DefaultHttpClient(httpparams); HttpGet httpget = new HttpGet(url); // Make request HttpResponse response = httpclient.execute(httpget); // Read JSON response InputStream instream = response.getEntity().getContent(); JSONObject json = new JSONObject(HttpHelper.ConvertStreamToString(instream)); instream.close(); // Empty result set? if (json.getInt(RPC_RESULTS) == 0) { return new ArrayList<SearchResult>(); } // Retrieve the items list JSONObject list = json.getJSONObject(RPC_ITEMS); JSONArray items = list.getJSONArray(RPC_ITEMS_LIST); // Add search results List<SearchResult> results = new ArrayList<SearchResult>(); for (int i = 0; i < items.length(); i++) { JSONObject item = items.getJSONObject(i); results.add(new SearchResult(item.getString(RPC_ITEM_TITLE).replaceAll("\\<.*?>", ""), item.getString(RPC_ITEM_URL), item.getString(RPC_ITEM_LINK), item.getString(RPC_ITEM_SIZE), new Date(Date.parse(item.getString(RPC_ITEM_PUBDATE))), item.getInt(RPC_ITEM_SEEDS), item.getInt(RPC_ITEM_LEECHERS))); } // Return the results list return results; }
From source file:com.maverick.http.MultiStatusResponse.java
private long processDate(String date) { long retval = 0; try {/*from w w w . j av a 2 s .com*/ retval = Date.parse(date); } catch (Throwable t) { try { /* * org.joda.time.DateTime dt = new * org.joda.time.DateTime(properties.getProperty("creationdate")); * retval = dt.getMillis(); */ return 0; // TODO change } catch (Throwable t2) { } } return retval; }
From source file:edu.cornell.mannlib.semservices.util.DateConverter.java
/** * Convert the specified input object into an output object of the specified * type./*from w ww .j av a2 s . c o m*/ * * @param type * XMLGregorianCalendar type to which this value should be * converted * @param value * The input value to be converted * * @exception ConversionException * if conversion cannot be performed successfully */ @SuppressWarnings({ "unchecked", "deprecation" }) public Object convert(Class type, Object value) { String dateValue = value.toString(); if (value instanceof Date) { return (value); } else { try { JSONObject jsonObj = JSONObject.fromObject(value.toString()); dateValue = jsonObj.optString("Date" /* Date.class.toString() */); } catch (JSONException e) { /* empty, could fail.. */ LOG.debug("no date object found in the json"); } } XMLGregorianCalendar calendar = (XMLGregorianCalendar) converter.convert(type, dateValue); Object result = null; try { result = calendar.toGregorianCalendar().getTime(); } catch (Exception exception) { /* * empty, had some error parsing the * time */ LOG.debug("Error converting the time"); if (result == null) { try { result = new Date(Date.parse(dateValue)); } catch (IllegalArgumentException argException) { // last chance result = java.sql.Date.valueOf(dateValue); } } } if (result != null && (result instanceof Date) && type.equals(java.sql.Date.class)) { result = new java.sql.Date(((Date) result).getTime()); } return result; }