public override void Run() { try { InputStreamReader isr = new InputStreamReader(@is); BufferedReader br = new BufferedReader(isr); string s = null; //noinspection ConstantConditions while (s == null && shouldRun) { while ((s = br.ReadLine()) != null) { outputFileHandle.Write(s); outputFileHandle.Write("\n"); } Thread.Sleep(1000); } isr.Close(); br.Close(); outputFileHandle.Flush(); } catch (Exception ex) { System.Console.Out.WriteLine("Problem reading stream :" + @is.GetType().GetCanonicalName() + " " + ex); Sharpen.Runtime.PrintStackTrace(ex); } }
/// <summary>Loads edits file, uses visitor to process all elements</summary> /// <exception cref="System.IO.IOException"/> public override void LoadEdits() { try { XMLReader xr = XMLReaderFactory.CreateXMLReader(); xr.SetContentHandler(this); xr.SetErrorHandler(this); xr.SetDTDHandler(null); xr.Parse(new InputSource(fileReader)); visitor.Close(null); } catch (SAXParseException e) { System.Console.Out.WriteLine("XML parsing error: " + "\n" + "Line: " + e.GetLineNumber () + "\n" + "URI: " + e.GetSystemId() + "\n" + "Message: " + e.Message); visitor.Close(e); throw new IOException(e.ToString()); } catch (SAXException e) { visitor.Close(e); throw new IOException(e.ToString()); } catch (RuntimeException e) { visitor.Close(e); throw; } finally { fileReader.Close(); } }
private string DoGet() { var txtUsername = FindViewById <EditText>(Resource.Id.txt_login_name); var username = txtUsername.Text; var password = FindViewById <EditText>(Resource.Id.txt_login_pwd).Text; var result = string.Empty; var url = new URL(@"http://192.168.1.115:49152"); var urlConn = url.OpenConnection() as HttpURLConnection; if (urlConn == null) { return(result); } try { var inStream = new InputStreamReader(urlConn.InputStream); var bufferReader = new BufferedReader(inStream); var readLine = string.Empty; while ((readLine = bufferReader.ReadLine()) != null) { result += readLine; } inStream.Close(); urlConn.Disconnect(); } catch (Exception ex) { } return(result); }
/** * Helper function to load file from assets */ private string readFile(string fileName, Context context) { StringBuilder returnString = new StringBuilder(); Stream fIn = null; InputStreamReader isr = null; BufferedReader input = null; try { fIn = context.Resources.Assets.Open(fileName); isr = new InputStreamReader(fIn); input = new BufferedReader(isr); string line; while ((line = input.ReadLine()) != null) { returnString.Append(line); } } catch (System.Exception e) { string s = e.Message; } finally { try { if (isr != null) { isr.Close(); } if (fIn != null) { fIn.Close(); } if (input != null) { input.Close(); } } catch (System.Exception e2) { string s = e2.Message; } } return(returnString.ToString()); }
/// <exception cref="System.Exception"/> public override void Init(Properties config, ServletContext servletContext, long tokenValidity) { string signatureSecretFile = config.GetProperty(AuthenticationFilter.SignatureSecretFile , null); StreamReader reader = null; if (signatureSecretFile != null) { try { StringBuilder sb = new StringBuilder(); reader = new InputStreamReader(new FileInputStream(signatureSecretFile), Charsets .Utf8); int c = reader.Read(); while (c > -1) { sb.Append((char)c); c = reader.Read(); } secret = Runtime.GetBytesForString(sb.ToString(), Extensions.GetEncoding ("UTF-8")); } catch (IOException) { throw new RuntimeException("Could not read signature secret file: " + signatureSecretFile ); } finally { if (reader != null) { try { reader.Close(); } catch (IOException) { } } } } // nothing to do secrets = new byte[][] { secret }; }
/// <exception cref="System.IO.IOException"></exception> protected internal static void CheckFile(FilePath f, string checkData) { StreamReader r = new InputStreamReader(new FileInputStream(f), "ISO-8859-1"); try { char[] data = new char[(int)f.Length()]; if (f.Length() != r.Read(data)) { throw new IOException("Internal error reading file data from " + f); } NUnit.Framework.Assert.AreEqual(checkData, new string(data)); } finally { r.Close(); } }
/// <exception cref="Javax.Servlet.ServletException"/> /// <exception cref="System.IO.IOException"/> protected override void DoGet(HttpServletRequest request, HttpServletResponse response ) { InputStreamReader @in = new InputStreamReader(request.GetInputStream()); TextWriter @out = new TextWriter(response.GetOutputStream()); calledTimes++; try { requestUri = new URI(null, null, request.GetRequestURI(), request.GetQueryString( ), null); } catch (URISyntaxException) { } @in.Close(); @out.Close(); }
public TraditionalSimplifiedCharacterMap(string path) { // TODO: gzipped maps might be faster try { FileInputStream fis = new FileInputStream(path); InputStreamReader isr = new InputStreamReader(fis, "utf-8"); BufferedReader br = new BufferedReader(isr); Init(br); br.Close(); isr.Close(); fis.Close(); } catch (IOException e) { throw new RuntimeIOException(e); } }
/// <summary>Returns the hadoop-auth configuration from HttpFSServer's configuration. /// </summary> /// <remarks> /// Returns the hadoop-auth configuration from HttpFSServer's configuration. /// <p> /// It returns all HttpFSServer's configuration properties prefixed with /// <code>httpfs.authentication</code>. The <code>httpfs.authentication</code> /// prefix is removed from the returned property names. /// </remarks> /// <param name="configPrefix">parameter not used.</param> /// <param name="filterConfig">parameter not used.</param> /// <returns>hadoop-auth configuration read from HttpFSServer's configuration.</returns> /// <exception cref="Javax.Servlet.ServletException"/> protected override Properties GetConfiguration(string configPrefix, FilterConfig filterConfig) { Properties props = new Properties(); Configuration conf = HttpFSServerWebApp.Get().GetConfig(); props.SetProperty(AuthenticationFilter.CookiePath, "/"); foreach (KeyValuePair <string, string> entry in conf) { string name = entry.Key; if (name.StartsWith(ConfPrefix)) { string value = conf.Get(name); name = Sharpen.Runtime.Substring(name, ConfPrefix.Length); props.SetProperty(name, value); } } string signatureSecretFile = props.GetProperty(SignatureSecretFile, null); if (signatureSecretFile == null) { throw new RuntimeException("Undefined property: " + SignatureSecretFile); } try { StringBuilder secret = new StringBuilder(); StreamReader reader = new InputStreamReader(new FileInputStream(signatureSecretFile ), Charsets.Utf8); int c = reader.Read(); while (c > -1) { secret.Append((char)c); c = reader.Read(); } reader.Close(); props.SetProperty(AuthenticationFilter.SignatureSecret, secret.ToString()); } catch (IOException) { throw new RuntimeException("Could not read HttpFS signature secret file: " + signatureSecretFile ); } return(props); }
/// <summary> /// Метод, осуществляющий Http подключение по url запросу и считывающий информацию о маршруте. /// </summary> /// <param name="reqUrl">Url запрос</param> /// <returns>Информация о маршруте</returns> public string RequestDirection(string reqUrl) { string responseString = ""; Stream inputStream = null; HttpURLConnection httpURLConnection = null; try { // Подключение и считывание информации о маршруте. URL url = new URL(reqUrl); httpURLConnection = (HttpURLConnection)url.OpenConnection(); httpURLConnection.Connect(); inputStream = httpURLConnection.InputStream; InputStreamReader inputStreamReader = new InputStreamReader(inputStream); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); StringBuffer stringBuffer = new StringBuffer(); string line = ""; while ((line = bufferedReader.ReadLine()) != null) { stringBuffer.Append(line); } responseString = stringBuffer.ToString(); bufferedReader.Close(); inputStreamReader.Close(); } catch (System.Exception e) { Log.Error("Error", e.Message); } finally { if (inputStream != null) { inputStream.Close(); } httpURLConnection.Disconnect(); } return(responseString); }
public virtual void TranslateFile(string input, string output) { try { FileInputStream fis = new FileInputStream(input); InputStreamReader isr = new InputStreamReader(fis, "utf-8"); BufferedReader br = new BufferedReader(isr); FileOutputStream fos = new FileOutputStream(output); OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8"); BufferedWriter bw = new BufferedWriter(osw); TranslateLines(br, bw); bw.Close(); osw.Close(); fos.Close(); br.Close(); isr.Close(); fis.Close(); } catch (IOException e) { throw new RuntimeIOException(e); } }
//帮助文档 private void Help_Click(object sender, EventArgs e) { var fs = Resources.OpenRawResource(Resource.Raw.Help); InputStreamReader read = new InputStreamReader(fs, "gbk"); BufferedReader reader = new BufferedReader(read); StringBuffer sb = new StringBuffer(""); while (true) { var line = reader.ReadLine(); if (line == null) { break; } sb.Append(line); sb.Append("\n"); } read.Close(); fs.Close(); reader.Close(); MessageBox.Show(sb.ToString()); }
/// <summary>Read /proc/meminfo, parse and compute memory information</summary> /// <param name="readAgain">if false, read only on the first time</param> private void ReadProcMemInfoFile(bool readAgain) { if (readMemInfoFile && !readAgain) { return; } // Read "/proc/memInfo" file BufferedReader @in = null; InputStreamReader fReader = null; try { fReader = new InputStreamReader(new FileInputStream(procfsMemFile), Sharpen.Extensions.GetEncoding ("UTF-8")); @in = new BufferedReader(fReader); } catch (FileNotFoundException) { // shouldn't happen.... return; } Matcher mat = null; try { string str = @in.ReadLine(); while (str != null) { mat = ProcfsMemfileFormat.Matcher(str); if (mat.Find()) { if (mat.Group(1).Equals(MemtotalString)) { ramSize = long.Parse(mat.Group(2)); } else { if (mat.Group(1).Equals(SwaptotalString)) { swapSize = long.Parse(mat.Group(2)); } else { if (mat.Group(1).Equals(MemfreeString)) { ramSizeFree = long.Parse(mat.Group(2)); } else { if (mat.Group(1).Equals(SwapfreeString)) { swapSizeFree = long.Parse(mat.Group(2)); } else { if (mat.Group(1).Equals(InactiveString)) { inactiveSize = long.Parse(mat.Group(2)); } } } } } } str = @in.ReadLine(); } } catch (IOException io) { Log.Warn("Error reading the stream " + io); } finally { // Close the streams try { fReader.Close(); try { @in.Close(); } catch (IOException) { Log.Warn("Error closing the stream " + @in); } } catch (IOException) { Log.Warn("Error closing the stream " + fReader); } } readMemInfoFile = true; }
private static string readFile(File file, char[] buffer) { StringBuilder outFile = new StringBuilder(); try { int read; Reader reader = new InputStreamReader(new FileInputStream(file), "UTF-8"); do { read = reader.Read(buffer, 0, buffer.Length); if (read > 0) { outFile.Append(buffer, 0, read); } } while (read >= 0); reader.Close(); } catch(IOException io) { } return outFile.ToString(); }
/// <summary>Read /proc/stat file, parse and calculate cumulative CPU</summary> private void ReadProcStatFile() { // Read "/proc/stat" file BufferedReader @in = null; InputStreamReader fReader = null; try { fReader = new InputStreamReader(new FileInputStream(procfsStatFile), Sharpen.Extensions.GetEncoding ("UTF-8")); @in = new BufferedReader(fReader); } catch (FileNotFoundException) { // shouldn't happen.... return; } Matcher mat = null; try { string str = @in.ReadLine(); while (str != null) { mat = CpuTimeFormat.Matcher(str); if (mat.Find()) { long uTime = long.Parse(mat.Group(1)); long nTime = long.Parse(mat.Group(2)); long sTime = long.Parse(mat.Group(3)); cpuTimeTracker.UpdateElapsedJiffies(BigInteger.ValueOf(uTime + nTime + sTime), GetCurrentTime ()); break; } str = @in.ReadLine(); } } catch (IOException io) { Log.Warn("Error reading the stream " + io); } finally { // Close the streams try { fReader.Close(); try { @in.Close(); } catch (IOException) { Log.Warn("Error closing the stream " + @in); } } catch (IOException) { Log.Warn("Error closing the stream " + fReader); } } }
/// <exception cref="System.Exception"/> public static void Main(string[] args) { if (args.Length < 4) { System.Console.Out.WriteLine("Arguments: <WORKDIR> <MINIKDCPROPERTIES> " + "<KEYTABFILE> [<PRINCIPALS>]+" ); System.Environment.Exit(1); } FilePath workDir = new FilePath(args[0]); if (!workDir.Exists()) { throw new RuntimeException("Specified work directory does not exists: " + workDir .GetAbsolutePath()); } Properties conf = CreateConf(); FilePath file = new FilePath(args[1]); if (!file.Exists()) { throw new RuntimeException("Specified configuration does not exists: " + file.GetAbsolutePath ()); } Properties userConf = new Properties(); InputStreamReader r = null; try { r = new InputStreamReader(new FileInputStream(file), Charsets.Utf8); userConf.Load(r); } finally { if (r != null) { r.Close(); } } foreach (KeyValuePair <object, object> entry in userConf) { conf[entry.Key] = entry.Value; } Org.Apache.Hadoop.Minikdc.MiniKdc miniKdc = new Org.Apache.Hadoop.Minikdc.MiniKdc (conf, workDir); miniKdc.Start(); FilePath krb5conf = new FilePath(workDir, "krb5.conf"); if (miniKdc.GetKrb5conf().RenameTo(krb5conf)) { FilePath keytabFile = new FilePath(args[2]).GetAbsoluteFile(); string[] principals = new string[args.Length - 3]; System.Array.Copy(args, 3, principals, 0, args.Length - 3); miniKdc.CreatePrincipal(keytabFile, principals); System.Console.Out.WriteLine(); System.Console.Out.WriteLine("Standalone MiniKdc Running"); System.Console.Out.WriteLine("---------------------------------------------------" ); System.Console.Out.WriteLine(" Realm : " + miniKdc.GetRealm()); System.Console.Out.WriteLine(" Running at : " + miniKdc.GetHost() + ":" + miniKdc .GetHost()); System.Console.Out.WriteLine(" krb5conf : " + krb5conf); System.Console.Out.WriteLine(); System.Console.Out.WriteLine(" created keytab : " + keytabFile); System.Console.Out.WriteLine(" with principals : " + Arrays.AsList(principals)); System.Console.Out.WriteLine(); System.Console.Out.WriteLine(" Do <CTRL-C> or kill <PID> to stop it"); System.Console.Out.WriteLine("---------------------------------------------------" ); System.Console.Out.WriteLine(); Runtime.GetRuntime().AddShutdownHook(new _Thread_170(miniKdc)); } else { throw new RuntimeException("Cannot rename KDC's krb5conf to " + krb5conf.GetAbsolutePath ()); } }
/// <summary>Read /proc/cpuinfo, parse and calculate CPU information</summary> private void ReadProcCpuInfoFile() { // This directory needs to be read only once if (readCpuInfoFile) { return; } // Read "/proc/cpuinfo" file BufferedReader @in = null; InputStreamReader fReader = null; try { fReader = new InputStreamReader(new FileInputStream(procfsCpuFile), Sharpen.Extensions.GetEncoding ("UTF-8")); @in = new BufferedReader(fReader); } catch (FileNotFoundException) { // shouldn't happen.... return; } Matcher mat = null; try { numProcessors = 0; string str = @in.ReadLine(); while (str != null) { mat = ProcessorFormat.Matcher(str); if (mat.Find()) { numProcessors++; } mat = FrequencyFormat.Matcher(str); if (mat.Find()) { cpuFrequency = (long)(double.ParseDouble(mat.Group(1)) * 1000); } // kHz str = @in.ReadLine(); } } catch (IOException io) { Log.Warn("Error reading the stream " + io); } finally { // Close the streams try { fReader.Close(); try { @in.Close(); } catch (IOException) { Log.Warn("Error closing the stream " + @in); } } catch (IOException) { Log.Warn("Error closing the stream " + fReader); } } readCpuInfoFile = true; }
/// <summary> /// Loads the CharHandlers for the given range of characters from the /// resource file with the given name. /// </summary> /// <remarks> /// Loads the CharHandlers for the given range of characters from the /// resource file with the given name. /// </remarks> internal static GeneralLegacyIndexCodes.CharHandler[] LoadCodes(string codesFilePath , char firstChar, char lastChar) { int numCodes = (AsUnsignedChar(lastChar) - AsUnsignedChar(firstChar)) + 1; GeneralLegacyIndexCodes.CharHandler[] values = new GeneralLegacyIndexCodes.CharHandler [numCodes]; IDictionary <string, GeneralLegacyIndexCodes.Type> prefixMap = new Dictionary <string , GeneralLegacyIndexCodes.Type>(); prefixMap.Put("S", GeneralLegacyIndexCodes.Type.SIMPLE); prefixMap.Put("I", GeneralLegacyIndexCodes.Type.INTERNATIONAL); prefixMap.Put("U", GeneralLegacyIndexCodes.Type.UNPRINTABLE); prefixMap.Put("P", GeneralLegacyIndexCodes.Type.UNPRINTABLE_EXT); prefixMap.Put("Z", GeneralLegacyIndexCodes.Type.INTERNATIONAL_EXT); prefixMap.Put("X", GeneralLegacyIndexCodes.Type.IGNORED); InputStreamReader reader = null; try { reader = new InputStreamReader(Database.GetResourceAsStream(codesFilePath ), "US-ASCII"); int start = AsUnsignedChar(firstChar); int end = AsUnsignedChar(lastChar); for (int i = start; i <= end; ++i) { char c = (char)i; GeneralLegacyIndexCodes.CharHandler ch = null; if (char.IsHighSurrogate(c) || char.IsLowSurrogate(c)) { // surrogate chars are not included in the codes files ch = SURROGATE_CHAR_HANDLER; } else { string codeLine = reader.ReadLine(); ch = ParseCodes(prefixMap, codeLine); } values[(i - start)] = ch; } } catch (IOException e) { throw new RuntimeException("failed loading index codes file " + codesFilePath, e); } finally { if (reader != null) { try { reader.Close(); } catch (IOException) { } } } // ignored return(values); }