internal virtual string ExtractPassword(string pwFile) { if (pwFile.IsEmpty()) { // If there is no password file defined, we'll assume that we should do // an anonymous bind return(string.Empty); } StringBuilder password = new StringBuilder(); try { using (StreamReader reader = new InputStreamReader(new FileInputStream(pwFile), Charsets .Utf8)) { int c = reader.Read(); while (c > -1) { password.Append((char)c); c = reader.Read(); } return(password.ToString().Trim()); } } catch (IOException ioe) { throw new RuntimeException("Could not read password file: " + pwFile, ioe); } }
/// <exception cref="System.IO.IOException"></exception> private string ReadTestPatchFile(Encoding cs) { string patchFile = Sharpen.Extensions.GetTestName() + ".patch"; InputStream @in = GetType().GetResourceAsStream(patchFile); if (@in == null) { NUnit.Framework.Assert.Fail("No " + patchFile + " test vector"); return(null); } // Never happens try { InputStreamReader r = new InputStreamReader(@in, cs); char[] tmp = new char[2048]; StringBuilder s = new StringBuilder(); int n; while ((n = r.Read(tmp)) > 0) { s.Append(tmp, 0, n); } return(s.ToString()); } finally { @in.Close(); } }
/// <summary> /// Download a string from the specified URI. /// </summary> public string DownloadString(URL address) { URLConnection connection = null; InputStream inputStream = null; try { connection = OpenConnection(address); inputStream = connection.InputStream; var reader = new InputStreamReader(inputStream); var buffer = new char[BUFFER_SIZE]; var builder = new StringBuilder(); int len; while ((len = reader.Read(buffer, 0, BUFFER_SIZE)) > 0) { builder.Append(buffer, 0, len); } return(builder.ToString()); } finally { if (inputStream != null) { inputStream.Close(); } var httpConnection = connection as HttpURLConnection; if (httpConnection != null) { httpConnection.Disconnect(); } } }
/// <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 }; }
/// <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); }
public char GetDataFromDevice() { char value = ' '; if (objStreamReader != null) { value = (char)objStreamReader.Read(); } return(value); }
/// <summary> /// Get the entity content as a String, using the provided default character set /// if none is found in the entity. /// </summary> /// <remarks> /// Get the entity content as a String, using the provided default character set /// if none is found in the entity. /// If defaultCharset is null, the default "ISO-8859-1" is used. /// </remarks> /// <param name="entity">must not be null</param> /// <param name="defaultCharset">character set to be applied if none found in the entity /// </param> /// <returns> /// the entity content as a String. May be null if /// <see cref="Org.Apache.Http.HttpEntity.GetContent()">Org.Apache.Http.HttpEntity.GetContent() /// </see> /// is null. /// </returns> /// <exception cref="Org.Apache.Http.ParseException">if header elements cannot be parsed /// </exception> /// <exception cref="System.ArgumentException">if entity is null or if content length > Integer.MAX_VALUE /// </exception> /// <exception cref="System.IO.IOException">if an error occurs reading the input stream /// </exception> /// <exception cref="Sharpen.UnsupportedCharsetException"> /// Thrown when the named charset is not available in /// this instance of the Java virtual machine /// </exception> public static string ToString(HttpEntity entity, Encoding defaultCharset) { Args.NotNull(entity, "Entity"); InputStream instream = entity.GetContent(); if (instream == null) { return(null); } try { Args.Check(entity.GetContentLength() <= int.MaxValue, "HTTP entity too large to be buffered in memory" ); int i = (int)entity.GetContentLength(); if (i < 0) { i = 4096; } Encoding charset = null; try { ContentType contentType = ContentType.Get(entity); if (contentType != null) { charset = contentType.GetCharset(); } } catch (UnsupportedCharsetException ex) { throw new UnsupportedEncodingException(ex.Message); } if (charset == null) { charset = defaultCharset; } if (charset == null) { charset = HTTP.DefContentCharset; } StreamReader reader = new InputStreamReader(instream, charset); CharArrayBuffer buffer = new CharArrayBuffer(i); char[] tmp = new char[1024]; int l; while ((l = reader.Read(tmp)) != -1) { buffer.Append(tmp, 0, l); } return(buffer.ToString()); } finally { instream.Close(); } }
/** * Makes a radar search request and returns the results in a json format. * * @param keyword The keyword to be searched for. * @param location The location the radar search should be based around. * @return The results from the radar search request as a json */ private string getJsonPlaces(string keyword, LatLng location) { HttpURLConnection conn = null; StringBuilder jsonResults = new StringBuilder(); try { URL url = new URL( PLACES_API_BASE + TYPE_RADAR_SEARCH + OUT_JSON + "?location=" + location.Latitude + "," + location.Longitude + "&radius=" + (SEARCH_RADIUS / 2) + "&sensor=false" + "&key=" + API_KEY + "&keyword=" + keyword.Replace(" ", "%20") ); conn = (HttpURLConnection)url.OpenConnection(); InputStreamReader @in = new InputStreamReader(conn.InputStream); // Load the results into a StringBuilder int read; char[] buff = new char[1024]; while ((read = @in.Read(buff)) != -1) { jsonResults.Append(buff, 0, read); } } catch (MalformedURLException) { Toast.MakeText(this, "Error processing Places API URL", ToastLength.Short).Show(); return(null); } catch (IOException) { Toast.MakeText(this, "Error connecting to Places API", ToastLength.Short).Show(); return(null); } finally { if (conn != null) { conn.Disconnect(); } } return(jsonResults.ToString()); }
/// <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(); } }
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> /// Download a string from the specified URI. /// </summary> public string DownloadString(URL address) { URLConnection connection = null; InputStream inputStream = null; try { connection = OpenConnection(address); inputStream = connection.InputStream; var reader = new InputStreamReader(inputStream); var buffer = new char[BUFFER_SIZE]; var builder = new StringBuilder(); int len; while ((len = reader.Read(buffer, 0, BUFFER_SIZE)) > 0) { builder.Append(buffer, 0, len); } return builder.ToString(); } finally { if (inputStream != null) inputStream.Close(); var httpConnection = connection as HttpURLConnection; if (httpConnection != null) httpConnection.Disconnect(); } }
public void PickupLocationAutocomplete(object sender, EventArgs e) { string input = pickupLocation.Text.Trim(); if (input.Length > 1) { List <String> resultList = null; HttpURLConnection conn = null; StringBuilder jsonResults = new StringBuilder(); try { if (Convert.ToInt32(Android.OS.Build.VERSION.SdkInt) > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().PermitAll().Build(); StrictMode.SetThreadPolicy(policy); } StringBuilder sb = new StringBuilder(PLACES_API_BASE + TYPE_AUTOCOMPLETE + OUT_JSON); sb.Append("?key=" + API_KEY); sb.Append("&libraries=places"); sb.Append("&input=" + URLEncoder.Encode(input, "utf8")); URL url = new URL(sb.ToString()); conn = (HttpURLConnection)url.OpenConnection(); conn.Connect(); InputStreamReader ist = new InputStreamReader(conn.InputStream); int read; char[] buff = new char[1024]; while ((read = ist.Read(buff)) != -1) { jsonResults.Append(buff, 0, read); } } catch (MalformedURLException error) { } catch (IOException error) { } finally { if (conn != null) { conn.Disconnect(); } } try { JSONObject jsonObj = new JSONObject(jsonResults.ToString()); JSONArray predsJsonArray = jsonObj.GetJSONArray("predictions"); resultList = new List <String>(predsJsonArray.Length()); PickUpLocations = new List <Location>(); for (int i = 0; i < predsJsonArray.Length(); ++i) { Location location = new Location() { Description = predsJsonArray.GetJSONObject(i).GetString("description"), PlaceId = predsJsonArray.GetJSONObject(i).GetString("place_id"), }; PickUpLocations.Add(location); resultList.Add(predsJsonArray.GetJSONObject(i).GetString("description")); } } catch (JSONException error) { } string[] resultLists = resultList.ToArray(); ArrayAdapter autoCompleteAdapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleDropDownItem1Line, resultLists); pickupLocation.Adapter = autoCompleteAdapter; } }
public Location GetLocationDetails(string placeId, string description) { Location location = null; HttpURLConnection conn = null; StringBuilder jsonResults = new StringBuilder(); try { if (Convert.ToInt32(Android.OS.Build.VERSION.SdkInt) > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().PermitAll().Build(); StrictMode.SetThreadPolicy(policy); } StringBuilder sb = new StringBuilder("https://maps.googleapis.com/maps/api/place/details/json"); sb.Append("?key=" + API_KEY); sb.Append("&placeid=" + placeId); URL url = new URL(sb.ToString()); conn = (HttpURLConnection)url.OpenConnection(); conn.Connect(); InputStreamReader un = new InputStreamReader(conn.InputStream); // Load the results into a StringBuilder int read; char[] buff = new char[1024]; while ((read = un.Read(buff)) != -1) { jsonResults.Append(buff, 0, read); } } catch (MalformedURLException e) { return(location); } catch (IOException e) { return(location); } finally { if (conn != null) { conn.Disconnect(); } } try { // Create a JSON object hierarchy from the results JSONObject jsonObj = new JSONObject(jsonResults.ToString()); JObject jObject = JObject.Parse(jsonObj.ToString()); JToken result = jObject["result"]; JToken geometryObject = result["geometry"]; JToken locationObject = geometryObject["location"]; double longitude = (double)locationObject["lng"]; double latitude = (double)locationObject["lat"]; location = new Location() { Longitude = longitude, Latitude = latitude, Description = description, PlaceId = placeId }; return(location); } catch (JSONException e) { return(location); } }
private void InitBlock() { // TODO: This might very well fail. Best way to handle? OrderedMap <String, String> locale = new OrderedMap <String, String>(); int chunk = 100; System.IO.StreamReader isr; isr = new InputStreamReader(is_Renamed, "UTF-8"); bool done = false; char[] cbuf = new char[chunk]; int offset = 0; int curline = 0; System.String line = ""; while (!done) { //UPGRADE_TODO: Method 'java.io.InputStreamReader.read' was converted to 'System.IO.StreamReader.Read' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioInputStreamReaderread_char[]_int_int'" int read = isr.Read(cbuf, offset, chunk - offset); if (read == -1) { done = true; if ((System.Object)line != (System.Object) "") { parseAndAdd(locale, line, curline); } break; } System.String stringchunk = new System.String(cbuf, offset, read); int index = 0; while (index != -1) { //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'" int nindex = stringchunk.IndexOf('\n', index); //UTF-8 often doesn't encode with newline, but with CR, so if we //didn't find one, we'll try that if (nindex == -1) { //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'" nindex = stringchunk.IndexOf('\r', index); } if (nindex == -1) { line += stringchunk.Substring(index); break; } else { line += stringchunk.Substring(index, (nindex) - (index)); //Newline. process our string and start the next one. curline++; parseAndAdd(locale, line, curline); line = ""; } index = nindex + 1; } } is_Renamed.close(); return(locale); //trim whitespace. line = line.Trim(); //clear comments while (line.IndexOf("#") != -1) { line = line.Substring(0, (line.IndexOf("#")) - (0)); } if (line.IndexOf('=') == -1) { // TODO: Invalid line. Empty lines are fine, especially with comments, // but it might be hard to get all of those. if (line.Trim().Equals("")) { //Empty Line } else { System.Console.Out.WriteLine("Invalid line (#" + curline + ") read: " + line); } } else { //Check to see if there's anything after the '=' first. Otherwise there //might be some big problems. if (line.IndexOf('=') != line.Length - 1) { System.String value_Renamed = line.Substring(line.IndexOf('=') + 1, (line.Length) - (line.IndexOf('=') + 1)); locale.put(line.Substring(0, (line.IndexOf('=')) - (0)), value_Renamed); } else { System.Console.Out.WriteLine("Invalid line (#" + curline + ") read: '" + line + "'. No value follows the '='."); } } }
/// <exception cref="System.IO.IOException"/> public virtual int Read(char[] buf, int off, int len) { return(currentLogISR.Read(buf, off, len)); }
public static Process doShellCommand(Java.Lang.Process proc, string[] cmds, FFMpegCallbacks sc, bool runAsRoot, bool waitFor) { var r = Runtime.GetRuntime(); if (proc == null) { if (runAsRoot) { proc = r.Exec("su"); } else { proc = r.Exec("sh"); } } OutputStreamWriter outputStream = new OutputStreamWriter(proc.OutputStream); for (int i = 0; i < cmds.Length; i++) { logMessage("executing shell cmd: " + cmds[i] + "; runAsRoot=" + runAsRoot + ";waitFor=" + waitFor); outputStream.Write(cmds[i]); outputStream.Write("\n"); } outputStream.Flush(); outputStream.Write("exit\n"); outputStream.Flush(); if (waitFor) { char[] buf = new char[20]; // Consume the "stdout" InputStreamReader reader = new InputStreamReader(proc.InputStream); int read = 0; while ((read = reader.Read(buf)) != -1) { if (sc != null) { sc.ShellOut(new string(buf)); } } // Consume the "stderr" reader = new InputStreamReader(proc.ErrorStream); read = 0; while ((read = reader.Read(buf)) != -1) { if (sc != null) { sc.ShellOut(new string(buf)); } } proc.WaitFor(); } sc.ProcessComplete(proc.ExitValue()); return(proc); }