List of usage examples for java.io IOException getMessage
public String getMessage()
From source file:Main.java
public static List<String> getExtSDCardPaths() { List<String> paths = new ArrayList<String>(); String extFileStatus = Environment.getExternalStorageState(); File extFile = Environment.getExternalStorageDirectory(); if (extFileStatus.endsWith(Environment.MEDIA_UNMOUNTED) && extFile.exists() && extFile.isDirectory() && extFile.canWrite()) { paths.add(extFile.getAbsolutePath()); }/*from w w w. j ava 2 s .com*/ try { // obtain executed result of command line code of 'mount', to judge // whether tfCard exists by the result Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec("mount"); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line = null; int mountPathIndex = 1; while ((line = br.readLine()) != null) { // format of sdcard file system: vfat/fuse if ((!line.contains("fat") && !line.contains("fuse") && !line.contains("storage")) || line.contains("secure") || line.contains("asec") || line.contains("firmware") || line.contains("shell") || line.contains("obb") || line.contains("legacy") || line.contains("data")) { continue; } String[] parts = line.split(" "); int length = parts.length; if (mountPathIndex >= length) { continue; } String mountPath = parts[mountPathIndex]; if (!mountPath.contains("/") || mountPath.contains("data") || mountPath.contains("Data")) { continue; } File mountRoot = new File(mountPath); if (!mountRoot.exists() || !mountRoot.isDirectory() || !mountRoot.canWrite()) { continue; } boolean equalsToPrimarySD = mountPath.equals(extFile.getAbsolutePath()); if (equalsToPrimarySD) { continue; } paths.add(mountPath); } } catch (IOException e) { Log.e(TAG, "IOException:" + e.getMessage()); } return paths; }
From source file:com.rdonasco.security.utils.EncryptionUtil.java
private static void generateEncryptedPassword(String propsFile, String outFile) throws Exception { FileInputStream fis = null;// www.j av a 2s . c om FileOutputStream fos = null; try { fis = new FileInputStream(new File(propsFile)); Properties props = new Properties(); props.load(fis); String stringToEncrypt = props.getProperty("password"); String passphrase = props.getProperty("passphrase"); System.out.println("passphrase:<" + passphrase + ">"); System.out.println("encrypting " + stringToEncrypt); String encrypted = EncryptionUtil.encryptWithPassword(stringToEncrypt, passphrase); System.out.println("encrypted:" + encrypted); String decrypted = EncryptionUtil.decryptWithPassword(encrypted, passphrase); System.out.println("decrypted:" + decrypted); if (!stringToEncrypt.equals(decrypted)) { throw new Exception( "password cannot be decrypted properly, please choose another password or change passphrase."); } Properties keyProperties = new Properties(); keyProperties.put("encrypted", encrypted); fos = new FileOutputStream(new File(outFile)); keyProperties.store(fos, "last updated " + new SimpleDateFormat("dd/MMM/yyyy HH:mm:ss").format(new Date())); } finally { if (null != fis) { try { fis.close(); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getMessage(), ex); } } if (null != fos) { try { fos.close(); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getMessage(), ex); } } } }
From source file:de.bayern.gdi.App.java
private static void initConfig(String dir) { try {// www . j a va2 s .c o m Config.initialize(dir); } catch (IOException ex) { System.err.println("Loading config failed: " + ex.getMessage()); System.exit(1); } }
From source file:de.l3s.dlg.ncbikraken.ftp.NcbiFTPClient.java
public static void getMedline(MedlineFileType type) { FileOutputStream out = null;//from ww w. j av a 2 s. c o m FTPClient ftp = new FTPClient(); try { // Connection String LOGGER.info("Connecting to FTP server " + SERVER_NAME); ftp.connect(SERVER_NAME); ftp.login("anonymous", ""); ftp.cwd(BASELINE_PATH); ftp.cwd(type.getServerPath()); try { ftp.pasv(); } catch (IOException e) { LOGGER.error( "Can not access the passive mode. Maybe a problem with your (Windows) firewall. Just try to run as administrator: \nnetsh advfirewall set global StatefulFTP disable"); return; } for (FTPFile file : ftp.listFiles()) { if (file.isFile()) { File meshF = new File(file.getName()); LOGGER.debug("Downloading file: " + SERVER_NAME + ":" + BASELINE_PATH + "/" + type.getServerPath() + "/" + meshF.getName()); out = new FileOutputStream(Configuration.INSTANCE.getMedlineDir() + File.separator + meshF); ftp.retrieveFile(meshF.getName(), out); out.flush(); out.close(); } } } catch (IOException ioe) { LOGGER.error(ioe.getMessage()); } finally { IOUtils.closeQuietly(out); try { ftp.disconnect(); } catch (IOException e) { LOGGER.error(e.getMessage()); } } }
From source file:edu.wpi.checksims.ChecksimsRunner.java
/** * @return Current version of Checksims//from ww w . j a v a 2s. co m */ static String getChecksimsVersion() { InputStream resource = ChecksimsCommandLine.class.getResourceAsStream("version.txt"); if (resource == null) { return "Error obtaining version number: could not obtain input stream for version.txt"; } try { return IOUtils.toString(resource); } catch (IOException e) { return "Error obtaining version number: " + e.getMessage(); } }
From source file:fr.xebia.workshop.android.core.utils.ServerUtils.java
public static Long registerUser(PlusClient plusClient) { try {// w w w. j a v a2 s . c o m HttpResponse httpResponse = doHttpCall(buildUserRegistationRequest(plusClient)); return new JSONObject(EntityUtils.toString(httpResponse.getEntity())).getLong("id"); } catch (IOException e) { Log.e(TAG, e.getMessage()); return null; } catch (JSONException e) { Log.e(TAG, e.getMessage()); return null; } }
From source file:gov.nih.nci.cabig.caaers.utils.XmlValidator.java
public static boolean validateAgainstSchema(String xmlContent, String xsdUrl, StringBuffer validationResult) { boolean validXml = false; try {// w w w . j a va 2 s.co m // parse an XML document into a DOM tree DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setValidating(false); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder parser = documentBuilderFactory.newDocumentBuilder(); Document document = parser.parse(new InputSource(new StringReader(xmlContent))); // create a SchemaFactory capable of understanding WXS schemas SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); // load a WXS schema, represented by a Schema instance Source schemaFile = new StreamSource(getResources(xsdUrl)[0].getFile()); Schema schema = schemaFactory.newSchema(schemaFile); // create a Validator instance, which can be used to validate an instance document Validator validator = schema.newValidator(); // validate the DOM tree validator.validate(new DOMSource(document)); validXml = true; } catch (FileNotFoundException ex) { throw new CaaersSystemException("File Not found Exception", ex); } catch (IOException ioe) { validationResult.append(ioe.getMessage()); logger.error(ioe.getMessage()); } catch (SAXParseException spe) { validationResult.append("Line : " + spe.getLineNumber() + " - " + spe.getMessage()); logger.error("Line : " + spe.getLineNumber() + " - " + spe.getMessage()); } catch (SAXException e) { validationResult.append(e.toString()); logger.error(e.toString()); } catch (ParserConfigurationException pce) { validationResult.append(pce.getMessage()); } return validXml; }
From source file:com.github.dactiv.common.utils.PropertiesUtils.java
/** * properties, ???.//from www . ja v a2 s . co m * Spring Resource?, ?UTF-8. * * @param resourcesPaths Spring Resource path */ public static Properties loadProperties(String... resourcesPaths) { Properties props = new Properties(); for (String location : resourcesPaths) { logger.debug("Loading properties file from:" + location); InputStream is = null; try { Resource resource = resourceLoader.getResource(location); is = resource.getInputStream(); propertiesPersister.load(props, new InputStreamReader(is, DEFAULT_ENCODING)); } catch (IOException ex) { logger.info("Could not load properties from classpath:" + location + ": " + ex.getMessage()); } finally { IOUtils.closeQuietly(is); } } return props; }
From source file:com.canoo.webtest.boundary.StreamBoundary.java
/** * Close an InputStream ignoring an errors. * * Wraps IOException's.// w ww .ja v a2 s .c o m * * @param inStream */ public static void closeInputStream(final InputStream inStream) { if (inStream != null) { try { inStream.close(); } catch (IOException e) { LOG.warn("Error closing stream: " + e.getMessage(), e); } } }
From source file:com.canoo.webtest.boundary.StreamBoundary.java
/** * Close an OutputStream ignoring an errors. * * Wraps IOException's.//from www.j a v a2 s . c o m * * @param outStream */ public static void closeOutputStream(final OutputStream outStream) { if (outStream != null) { try { outStream.close(); } catch (IOException e) { LOG.warn("Error closing stream: " + e.getMessage(), e); } } }