List of usage examples for com.google.common.io CharSource readFirstLine
@Nullable public String readFirstLine() throws IOException
From source file:com.lyndir.masterpassword.gui.GUI.java
private static void checkUpdate() { try {/*from ww w. ja va 2 s. c o m*/ Enumeration<URL> manifestURLs = Thread.currentThread().getContextClassLoader() .getResources(JarFile.MANIFEST_NAME); while (manifestURLs.hasMoreElements()) { InputStream manifestStream = manifestURLs.nextElement().openStream(); Attributes attributes = new Manifest(manifestStream).getMainAttributes(); if (!GUI.class.getCanonicalName().equals(attributes.getValue(Attributes.Name.MAIN_CLASS))) continue; String manifestRevision = attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION); String upstreamRevisionURL = "http://masterpasswordapp.com/masterpassword-gui.jar.rev"; CharSource upstream = Resources.asCharSource(URI.create(upstreamRevisionURL).toURL(), Charsets.UTF_8); String upstreamRevision = upstream.readFirstLine(); logger.inf("Local Revision: <%s>", manifestRevision); logger.inf("Upstream Revision: <%s>", upstreamRevision); if (manifestRevision != null && !manifestRevision.equalsIgnoreCase(upstreamRevision)) { logger.wrn("You are not running the current official version. Please update from:\n" + "http://masterpasswordapp.com/masterpassword-gui.jar"); JOptionPane.showMessageDialog(null, "A new version of Master Password is available.\n" + "Please download the latest version from http://masterpasswordapp.com", "Update Available", JOptionPane.WARNING_MESSAGE); } } } catch (IOException e) { logger.wrn(e, "Couldn't check for version update."); } }
From source file:com.lyndir.masterpassword.GUI.java
private static void checkUpdate() { try {//from ww w .j a va 2 s. co m Enumeration<URL> manifestURLs = Thread.currentThread().getContextClassLoader() .getResources(JarFile.MANIFEST_NAME); while (manifestURLs.hasMoreElements()) { InputStream manifestStream = manifestURLs.nextElement().openStream(); Attributes attributes = new Manifest(manifestStream).getMainAttributes(); if (!GUI.class.getCanonicalName().equals(attributes.getValue(Attributes.Name.MAIN_CLASS))) continue; String manifestRevision = attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION); String upstreamRevisionURL = "http://masterpasswordapp.com/masterpassword-gui.jar.rev"; CharSource upstream = Resources.asCharSource(URI.create(upstreamRevisionURL).toURL(), Charsets.UTF_8); String upstreamRevision = upstream.readFirstLine(); logger.inf("Local Revision: <%s>", manifestRevision); logger.inf("Upstream Revision: <%s>", upstreamRevision); if (!manifestRevision.equalsIgnoreCase(upstreamRevision)) { logger.wrn("You are not running the current official version. Please update from:\n" + "http://masterpasswordapp.com/masterpassword-gui.jar"); JOptionPane.showMessageDialog(null, "A new version of Master Password is available.\n" + "Please download the latest version from http://masterpasswordapp.com", "Update Available", JOptionPane.WARNING_MESSAGE); } } } catch (IOException e) { logger.wrn(e, "Couldn't check for version update."); } }
From source file:br.com.objectos.jabuticava.debs.DataParser.java
public LocalDate get() { LocalDate res = null;/*from w ww . jav a 2 s. co m*/ try { CharSource charSource = CharSource.wrap(text); String line = charSource.readFirstLine(); line = Strings.nullToEmpty(line); Matcher matcher = REGEX.matcher(line); if (matcher.find()) { String data = matcher.group(0); res = new LocalDateCsvConverter("dd/MM/yyyy").convert(data); } } catch (IOException e) { } return res; }