private java.io.FileInputStream searchDefaultCacerts() { try { string javaHome = java.lang.System.getProperty("java.home"); if (javaHome == null) { return(null); } string keyStorePath = javaHome + "/lib/security/cacerts"; //Console.WriteLine("keyStorePath = {0}", keyStorePath); java.io.File f = new java.io.File(keyStorePath); if (!f.exists()) { return(null); } return(new java.io.FileInputStream(f)); } catch (Exception e) { #if DEBUG //todo log it Console.WriteLine(e.GetType() + ":" + e.Message + "\n" + e.StackTrace); #endif return(null); } }
public static bool Exists(string path) { bool exists = false; if (path != null && path.Length != 0) { var file = new java.io.File(path); exists = file.exists() && file.isDirectory(); } return(exists); }
// Don't allow others to instantiate this class /// <summary>Scan a file for OBB information.</summary> /// <remarks>Scan a file for OBB information.</remarks> /// <param name="filePath">path to the OBB file to be scanned.</param> /// <returns>ObbInfo object information corresponding to the file path</returns> /// <exception cref="System.ArgumentException">if the OBB file couldn't be found</exception> /// <exception cref="System.IO.IOException">if the OBB file couldn't be read</exception> public static android.content.res.ObbInfo getObbInfo(string filePath) { if (filePath == null) { throw new System.ArgumentException("file path cannot be null"); } java.io.File obbFile = new java.io.File(filePath); if (!obbFile.exists()) { throw new System.ArgumentException("OBB file does not exist: " + filePath); } string canonicalFilePath = obbFile.getCanonicalPath(); android.content.res.ObbInfo obbInfo = new android.content.res.ObbInfo(); obbInfo.filename = canonicalFilePath; getObbInfo_native(canonicalFilePath, obbInfo); return obbInfo; }
// Don't allow others to instantiate this class /// <summary>Scan a file for OBB information.</summary> /// <remarks>Scan a file for OBB information.</remarks> /// <param name="filePath">path to the OBB file to be scanned.</param> /// <returns>ObbInfo object information corresponding to the file path</returns> /// <exception cref="System.ArgumentException">if the OBB file couldn't be found</exception> /// <exception cref="System.IO.IOException">if the OBB file couldn't be read</exception> public static android.content.res.ObbInfo getObbInfo(string filePath) { if (filePath == null) { throw new System.ArgumentException("file path cannot be null"); } java.io.File obbFile = new java.io.File(filePath); if (!obbFile.exists()) { throw new System.ArgumentException("OBB file does not exist: " + filePath); } string canonicalFilePath = obbFile.getCanonicalPath(); android.content.res.ObbInfo obbInfo = new android.content.res.ObbInfo(); obbInfo.filename = canonicalFilePath; getObbInfo_native(canonicalFilePath, obbInfo); return(obbInfo); }
public void inform(ResourceLoader loader) { string wordFiles = (string)args.get(PROTECTED_TOKENS); if (wordFiles != null) { try { File protectedWordFiles = new File(wordFiles); if (protectedWordFiles.exists()) { List /*<String>*/ wlist = loader.getLines(wordFiles); //This cast is safe in Lucene protectedWords = new CharArraySet(wlist, false);//No need to go through StopFilter as before, since it just uses a List internally } else { List /*<String>*/ files = StrUtils.splitFileNames(wordFiles); for (var iter = files.iterator(); iter.hasNext();) { string file = (string)iter.next(); List /*<String>*/ wlist = loader.getLines(file.Trim()); if (protectedWords == null) { protectedWords = new CharArraySet(wlist, false); } else { protectedWords.addAll(wlist); } } } } catch (IOException e) { throw new System.ApplicationException("Unexpected exception", e); } } }
private SSLSocketFactory getSSLSocketFactory() { SSLSocketFactory factory = null; try { //reading the keyStore path and password from the environment properties string keyStorePath = java.lang.System.getProperty("javax.net.ssl.keyStore"); java.io.FileInputStream keyStoreStream = null; if (keyStorePath != null) { java.io.File file = new java.io.File(keyStorePath); if(file.exists()) keyStoreStream = new java.io.FileInputStream(file); else keyStoreStream = searchDefaultCacerts(); } else keyStoreStream = searchDefaultCacerts(); string keyStorePassWord = java.lang.System.getProperty("javax.net.ssl.keyStorePassword"); if (keyStorePassWord == null) keyStorePassWord = "******"; char[] passphrase = keyStorePassWord.ToCharArray(); //initiating SSLContext SSLContext ctx = SSLContext.getInstance("TLS"); KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); KeyStore ks = KeyStore.getInstance("JKS"); if (keyStoreStream != null) ks.load(keyStoreStream,passphrase); else ks.load(null,null); kmf.init(ks, passphrase); tmf.init(ks); ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); factory = ctx.getSocketFactory(); } catch (Exception e) { factory = null; #if DEBUG Console.WriteLine("Can't get SSL Socket Factory, the exception is {0}, {1}", e.GetType(), e.Message); #endif } return factory; }
private java.io.FileInputStream searchDefaultCacerts() { try { string javaHome = java.lang.System.getProperty("java.home"); if(javaHome == null) return null; string keyStorePath = javaHome + "/lib/security/cacerts"; //Console.WriteLine("keyStorePath = {0}", keyStorePath); java.io.File f = new java.io.File(keyStorePath); if(!f.exists()) return null; return new java.io.FileInputStream(f); } catch(Exception e) { #if DEBUG //todo log it Console.WriteLine(e.GetType() + ":" + e.Message + "\n" + e.StackTrace); #endif return null; } }
private SSLSocketFactory getSSLSocketFactory() { SSLSocketFactory factory = null; try { //reading the keyStore path and password from the environment properties string keyStorePath = java.lang.System.getProperty("javax.net.ssl.keyStore"); java.io.FileInputStream keyStoreStream = null; if (keyStorePath != null) { java.io.File file = new java.io.File(keyStorePath); if (file.exists()) { keyStoreStream = new java.io.FileInputStream(file); } else { keyStoreStream = searchDefaultCacerts(); } } else { keyStoreStream = searchDefaultCacerts(); } string keyStorePassWord = java.lang.System.getProperty("javax.net.ssl.keyStorePassword"); if (keyStorePassWord == null) { keyStorePassWord = "******"; } char[] passphrase = keyStorePassWord.ToCharArray(); //initiating SSLContext SSLContext ctx = SSLContext.getInstance("TLS"); KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); KeyStore ks = KeyStore.getInstance("JKS"); if (keyStoreStream != null) { ks.load(keyStoreStream, passphrase); } else { ks.load(null, null); } kmf.init(ks, passphrase); tmf.init(ks); ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); factory = ctx.getSocketFactory(); } catch (Exception e) { factory = null; #if DEBUG Console.WriteLine("Can't get SSL Socket Factory, the exception is {0}, {1}", e.GetType(), e.Message); #endif } return(factory); }
public override java.io.File getExternalFilesDir(string type) { lock (mSync) { if (mExternalFilesDir == null) { mExternalFilesDir = android.os.Environment.getExternalStorageAppFilesDirectory(getPackageName ()); } if (!mExternalFilesDir.exists()) { try { (new java.io.File(android.os.Environment.getExternalStorageAndroidDataDir(), ".nomedia" )).createNewFile(); } catch (System.IO.IOException) { } if (!mExternalFilesDir.mkdirs()) { android.util.Log.w(TAG, "Unable to create external files directory"); return null; } } if (type == null) { return mExternalFilesDir; } java.io.File dir = new java.io.File(mExternalFilesDir, type); if (!dir.exists()) { if (!dir.mkdirs()) { android.util.Log.w(TAG, "Unable to create external media directory " + dir); return null; } } return dir; } }
protected void buildReadPaths(org.w3c.dom.Node dataFileStoreNode) { javax.xml.xpath.XPathFactory pathFactory = javax.xml.xpath.XPathFactory.newInstance(); javax.xml.xpath.XPath pathFinder = pathFactory.newXPath(); try { org.w3c.dom.NodeList locationNodes = (org.w3c.dom.NodeList)pathFinder.evaluate( "/dataFileStore/readLocations/location", dataFileStoreNode.getFirstChild(), javax.xml.xpath.XPathConstants.NODESET); for (int i = 0; i < locationNodes.getLength(); i++) { org.w3c.dom.Node location = locationNodes.item(i); String prop = pathFinder.evaluate("@property", location); String wwDir = pathFinder.evaluate("@wwDir", location); String append = pathFinder.evaluate("@append", location); String isInstall = pathFinder.evaluate("@isInstall", location); String isMarkWhenUsed = pathFinder.evaluate("@isMarkWhenUsed", location); String path = buildLocationPath(prop, append, wwDir); if (path == null) { Logging.logger().log(Level.WARNING, "FileStore.LocationInvalid", prop != null ? prop : Logging.getMessage("generic.Unknown")); continue; } StoreLocation oldStore = this.storeLocationFor(path); if (oldStore != null) // filter out duplicates { continue; } // Even paths that don't exist or are otherwise problematic are added to the list because they may // become readable during the session. E.g., removable media. So add them to the search list. java.io.File pathFile = new java.io.File(path); if (pathFile.exists() && !pathFile.isDirectory()) { Logging.logger().log(Level.WARNING, "FileStore.LocationIsFile", pathFile.getPath()); } bool pathIsInstall = isInstall != null && (isInstall.contains("t") || isInstall.contains("T")); StoreLocation newStore = new StoreLocation(pathFile, pathIsInstall); // If the input parameter "markWhenUsed" is null or empty, then the StoreLocation should keep its // default value. Otherwise the store location value is set to true when the input parameter contains // "t", and is set to false otherwise. if (isMarkWhenUsed != null && isMarkWhenUsed.length() > 0) { newStore.setMarkWhenUsed(isMarkWhenUsed.toLowerCase().contains("t")); } this.readLocations.add(newStore); } } catch (javax.xml.xpath.XPathExpressionException e) { String message = Logging.getMessage("FileStore.ExceptionReadingConfigurationFile"); Logging.logger().severe(message); throw new IllegalStateException(message, e); } }