Пример #1
0
        internal static sbyte[] Encode(char[] ca, int off, int len)
        {
            String csn = Charset.DefaultCharset().Name();

            try
            {
                // use charset name encode() variant which provides caching.
                return(Encode(csn, ca, off, len));
            }
            catch (UnsupportedEncodingException)
            {
                WarnUnsupportedCharset(csn);
            }
            try
            {
                return(Encode("ISO-8859-1", ca, off, len));
            }
            catch (UnsupportedEncodingException x)
            {
                // If this code is hit during VM initialization, MessageUtils is
                // the only way we will be able to get any kind of error message.
                MessageUtils.err("ISO-8859-1 charset not available: " + x.ToString());
                // If we can not find ISO-8859-1 (a required encoding) then things
                // are seriously wrong with the installation.
                Environment.Exit(1);
                return(null);
            }
        }
Пример #2
0
        private Console()
        {
            ReadLock  = new Object();
            WriteLock = new Object();
            String csname = encoding();

            if (csname != null)
            {
                try
                {
                    Cs = Charset.ForName(csname);
                }
                catch (Exception)
                {
                }
            }
            if (Cs == null)
            {
                Cs = Charset.DefaultCharset();
            }
            @out           = StreamEncoder.forOutputStreamWriter(new FileOutputStream(FileDescriptor.@out), WriteLock, Cs);
            Pw             = new PrintWriterAnonymousInnerClassHelper(this, @out);
            Formatter      = new Formatter(@out);
            Reader_Renamed = new LineReader(this, StreamDecoder.forInputStreamReader(new FileInputStream(FileDescriptor.@in), ReadLock, Cs));
            Rcb            = new char[1024];
        }
Пример #3
0
 public OutDataBuffer()
 {
     this.stream       = new ByteArrayOutputStream();
     this.charset      = Charset.DefaultCharset();
     this.charByte     = new byte[1];
     this.shortBytes   = new byte[2];
     this.mediumBytes  = new byte[3];
     this.intBytes     = new byte[4];
     this.longintBytes = new byte[8];
 }
Пример #4
0
        private void StartMessages(IWebSocket webSocket)
        {
            // we want to ping every 2 seconds
            new Timer(state =>
            {
                var buffer = new OkBuffer();
                buffer.WriteString("Ping!", Charset.DefaultCharset());
                webSocket.SendPing(buffer);
            }, null, TimeSpan.Zero, TimeSpan.FromSeconds(2));

            // we want to send a message every 5 seconds
            new Timer(state =>
            {
                var body = RequestBody.Create(WebSocket.Text, "Hello World!");
                webSocket.SendMessage(body);
            }, null, TimeSpan.Zero, TimeSpan.FromSeconds(3));
        }
Пример #5
0
        /// <summary>
        /// Return the header string for a set of XML formatted records.
        /// </summary>
        /// <param name="h">  The target handler (can be null) </param>
        /// <returns>  a valid XML string </returns>
        public override String GetHead(Handler h)
        {
            StringBuilder sb = new StringBuilder();
            String        encoding;

            sb.Append("<?xml version=\"1.0\"");

            if (h != null)
            {
                encoding = h.Encoding;
            }
            else
            {
                encoding = null;
            }

            if (encoding == null)
            {
                // Figure out the default encoding.
                encoding = Charset.DefaultCharset().Name();
            }
            // Try to map the encoding name to a canonical name.
            try
            {
                Charset cs = Charset.ForName(encoding);
                encoding = cs.Name();
            }
            catch (Exception)
            {
                // We hit problems finding a canonical name.
                // Just use the raw encoding name.
            }

            sb.Append(" encoding=\"");
            sb.Append(encoding);
            sb.Append("\"");
            sb.Append(" standalone=\"no\"?>\n");
            sb.Append("<!DOCTYPE log SYSTEM \"logger.dtd\">\n");
            sb.Append("<log>\n");
            return(sb.ToString());
        }
Пример #6
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            Button   startTest = FindViewById <Button>(Resource.Id.startTest);
            ListView listView  = FindViewById <ListView>(Resource.Id.listView);

            startTest.Click += delegate
            {
                ArrayAdapter <string> adapter = new ArrayAdapter <string>(
                    this,
                    Android.Resource.Layout.SimpleListItem1,
                    Android.Resource.Id.Text1);
                listView.Adapter = adapter;

                OkHttpClient client = new OkHttpClient();

                // Create request for remote resource.
                Request request = new Request.Builder()
                                  .Url(Endpoint)
                                  .Build();

                // Execute the request and retrieve the response.
                WebSocketCall     call     = WebSocketCall.Create(client, request);
                WebSocketListener listener = call.Enqueue();

                // attach handlers to the various events
                listener.Close += (sender, e) =>
                {
                    RunOnUiThread(() => adapter.Add(string.Format("{0}: {1}", e.Code, e.Reason)));
                };
                listener.Failure += (sender, e) =>
                {
                    if (e.Exception != null)
                    {
                        RunOnUiThread(() => adapter.Add(e.Exception.Message));
                    }
                    else
                    {
                        RunOnUiThread(() => adapter.Add("Unknown Error!"));
                    }
                };
                listener.Message += (sender, e) =>
                {
                    string payload = e.Payload.ReadString(Charset.DefaultCharset());
                    e.Payload.Close();
                    RunOnUiThread(() => adapter.Add(string.Format("{0}: {1}", e.PayloadType, payload)));
                };
                listener.Open += (sender, e) =>
                {
                    RunOnUiThread(() => adapter.Add("Opened Web Socket."));

                    StartMessages(e.WebSocket);
                };
                listener.Pong += (sender, e) =>
                {
                    string payload = e.Payload.ReadString(Charset.DefaultCharset());
                    e.Payload.Close();
                    RunOnUiThread(() => adapter.Add(payload));
                };
            };
        }