private long dumpBestPath(DataOutputStream dataOutputStream, BatchNISTRecognizer.CTLUtterance ctlutterance, Token token)
        {
            if (token == null)
            {
                return(0L);
            }
            Token predecessor = token.getPredecessor();
            long  num         = this.dumpBestPath(dataOutputStream, ctlutterance, predecessor);

            if (token.isWord())
            {
                long            collectTime     = token.getCollectTime();
                WordSearchState wordSearchState = (WordSearchState)token.getSearchState();
                Word            word            = wordSearchState.getPronunciation().getWord();
                string          spelling        = word.getSpelling();
                if (!String.instancehelper_startsWith(spelling, "<"))
                {
                    string[] array = String.instancehelper_split(ctlutterance.name, "_");
                    dataOutputStream.write(String.instancehelper_getBytes(new StringBuilder().append(array[0]).append('_').append(array[1]).append('_').append(array[2]).append(" 1 ").append((double)((long)ctlutterance.startOffset + num) / 100.0).append(' ').append((double)(collectTime - num) / 100.0).append(' ').toString()));
                    dataOutputStream.write(BatchNISTRecognizer.hex2Binary(spelling));
                    dataOutputStream.write(String.instancehelper_getBytes(" 0.700000\n"));
                }
                return(collectTime);
            }
            return(num);
        }
Beispiel #2
0
 public override void writePacketData(DataOutputStream dataoutputstream)
 {
     dataoutputstream.write(status);
     dataoutputstream.writeInt(xPosition);
     dataoutputstream.write(yPosition);
     dataoutputstream.writeInt(zPosition);
     dataoutputstream.write(face);
 }
 public override void writePacketData(DataOutputStream dataoutputstream)
 {
     dataoutputstream.writeInt(xPosition);
     dataoutputstream.write(yPosition);
     dataoutputstream.writeInt(zPosition);
     dataoutputstream.write(type);
     dataoutputstream.write(metadata);
 }
Beispiel #4
0
 public override void writePacketData(DataOutputStream dataoutputstream)
 {
     dataoutputstream.writeInt(xLocation);
     dataoutputstream.writeShort(yLocation);
     dataoutputstream.writeInt(zLocation);
     dataoutputstream.write(instrumentType);
     dataoutputstream.write(pitch);
 }
Beispiel #5
0
 public override void writePacketData(DataOutputStream dataoutputstream)
 {
     dataoutputstream.writeInt(entityId);
     dataoutputstream.writeInt(xPosition);
     dataoutputstream.writeInt(yPosition);
     dataoutputstream.writeInt(zPosition);
     dataoutputstream.write(yaw);
     dataoutputstream.write(pitch);
 }
Beispiel #6
0
 public override void writePacketData(DataOutputStream dataoutputstream)
 {
     dataoutputstream.writeInt(xPosition);
     dataoutputstream.writeShort(yPosition);
     dataoutputstream.writeInt(zPosition);
     dataoutputstream.write(xSize - 1);
     dataoutputstream.write(ySize - 1);
     dataoutputstream.write(zSize - 1);
     dataoutputstream.writeInt(chunkSize);
     dataoutputstream.write(chunk, 0, chunkSize);
 }
        /// <summary>
        ///     Encodes this <seealso cref="ChecksumTable" /> and encrypts the final whirlpool hash.
        /// </summary>
        /// <param name="whirlpool"> If whirlpool digests should be encoded. </param>
        /// <param name="modulus"> The modulus. </param>
        /// <param name="privateKey"> The private key. </param>
        /// <returns> The encoded <seealso cref="ByteBuffer" />. </returns>
        /// <exception cref="IOException"> if an I/O error occurs. </exception>
        public virtual ByteBuffer Encode(bool whirlpool, BigInteger modulus, BigInteger privateKey)
        {
            var bout = new ByteArrayOutputStream();
            var os   = new DataOutputStream(bout);

            try
            {
                /* as the new whirlpool format is more complicated we must write the number of entries */
                if (whirlpool)
                {
                    os.write(entries.Length);
                }

                /* encode the individual entries */
                for (var i = 0; i < entries.Length; i++)
                {
                    var entry = entries[i];
                    os.writeInt(entry.GetCrc());
                    os.writeInt(entry.GetVersion());
                    if (whirlpool)
                    {
                        os.write(entry.GetWhirlpool());
                    }
                }

                /* compute (and encrypt) the digest of the whole table */
                byte[] bytes;
                if (whirlpool)
                {
                    bytes = bout.toByteArray();
                    var temp = ByteBuffer.allocate(66);
                    temp.put(0);
                    temp.put(Whirlpool.Crypt(bytes, 5, bytes.Length - 5));
                    temp.put(0);
                    temp.flip();

                    if (modulus != null && privateKey != null)
                    {
                        temp = Rsa.Crypt(temp, modulus, privateKey);
                    }

                    bytes = new byte[temp.limit()];
                    temp.get(bytes);
                    os.write(bytes);
                }

                bytes = bout.toByteArray();
                return(ByteBuffer.wrap(bytes));
            }
            finally
            {
                os.close();
            }
        }
        public override void writePacketData(DataOutputStream dataoutputstream)
        {
            dataoutputstream.writeInt(xPosition);
            dataoutputstream.writeInt(zPosition);
            dataoutputstream.writeShort((short)size);
            for (int i = 0; i < size; i++)
            {
                dataoutputstream.writeShort(coordinateArray[i]);
            }

            dataoutputstream.write(typeArray);
            dataoutputstream.write(metadataArray);
        }
        public override void WriteTo(OutputStream os)
        {
            DataOutputStream dos = new DataOutputStream(os);

            dos.write(PrimaryKey != null ? SchemaType.Object.TypeIdWithPrimaryKey : SchemaType.Object.TypeId);

            dos.writeUTF(getName());
            if (primaryKey != null)
            {
                VarInt.writeVInt(dos, primaryKey.numFields());
                for (int i = 0; i < primaryKey.numFields(); i++)
                {
                    dos.writeUTF(primaryKey.getFieldPath(i));
                }
            }

            dos.writeShort(size);
            for (int i = 0; i < size; i++)
            {
                dos.writeUTF(fieldNames[i]);
                dos.writeUTF(fieldTypes[i].name());
                if (fieldTypes[i] == FieldType.REFERENCE)
                {
                    dos.writeUTF(referencedTypes[i]);
                }
            }
        }
Beispiel #10
0
        public void writexml(DataOutputStream @out)
        {
            StringBuffer stringBuffer = new StringBuffer();

            stringBuffer.append("<house ").append("id=\"").append(this.getName()).append("\"").append(" macroObject=\"OBJECT_MM_").append(this.getName()).append("\"").append(" >\n");
            string str1 = stringBuffer.toString();

            sbyte[] b1 = new sbyte[str1.Length];
            for (int index = 0; index < str1.Length; ++index)
            {
                b1[index] = (sbyte)str1[index];
            }
            @out.write(b1, 0, b1.Length);
            int num1 = this.m_rooms.size();

            for (int index = 0; index < num1; ++index)
            {
                ((PlaceableObject)this.m_rooms.elementAt(index)).writexml((OutputStream)@out);
            }
            int num2 = this.m_doors.size();

            for (int index = 0; index < num2; ++index)
            {
                ((PlaceableObject)this.m_doors.elementAt(index)).writexml((OutputStream)@out);
            }
            int num3 = this.m_windows.size();

            for (int index = 0; index < num3; ++index)
            {
                ((PlaceableObject)this.m_windows.elementAt(index)).writexml((OutputStream)@out);
            }
            int num4 = this.m_objects.size();

            for (int index = 0; index < num4; ++index)
            {
                ((PlaceableObject)this.m_objects.elementAt(index)).writexml((OutputStream)@out);
            }
            string str2 = "</house>\n";

            sbyte[] b2 = new sbyte[str2.Length];
            for (int index = 0; index < str2.Length; ++index)
            {
                b2[index] = (sbyte)str2[index];
            }
            @out.write(b2, 0, b2.Length);
        }
Beispiel #11
0
 public override void writePacketData(DataOutputStream dataoutputstream)
 {
     dataoutputstream.writeInt(xPosition);
     dataoutputstream.write(yPosition);
     dataoutputstream.writeInt(zPosition);
     dataoutputstream.write(direction);
     if (itemStack == null)
     {
         dataoutputstream.writeShort(-1);
     }
     else
     {
         dataoutputstream.writeShort(itemStack.itemID);
         dataoutputstream.writeByte(itemStack.stackSize);
         dataoutputstream.writeShort(itemStack.getItemDamage());
     }
 }
Beispiel #12
0
        /// <summary>
        ///     Encodes this <seealso cref="Archive" /> into a <seealso cref="ByteBuffer" />.
        ///     <p />
        ///     Please note that this is a fairly simple implementation that does not
        ///     attempt to use more than one chunk.
        /// </summary>
        /// <returns> An encoded <seealso cref="ByteBuffer" />. </returns>
        /// <exception cref="IOException"> if an I/O error occurs. </exception>
        public virtual ByteBuffer Encode() // TODO: an implementation that can use more than one chunk
        {
            var bout = new ByteArrayOutputStream();
            var os   = new DataOutputStream(bout);

            try
            {
                /* add the data for each entry */
                for (var id = 0; id < entries.Length; id++)
                {
                    /* copy to temp buffer */
                    var temp = new byte[entries[id].limit()];
                    entries[id].position(0);
                    try
                    {
                        entries[id].get(temp);
                    }
                    finally
                    {
                        entries[id].position(0);
                    }

                    /* copy to output stream */
                    os.write(temp);
                }

                /* write the chunk lengths */
                var prev = 0;
                for (var id = 0; id < entries.Length; id++)
                {
                    /*
                     * since each file is stored in the only chunk, just write the
                     * delta-encoded file size
                     */
                    var chunkSize = entries[id].limit();
                    os.writeInt(chunkSize - prev);
                    prev = chunkSize;
                }

                /* we only used one chunk due to a limitation of the implementation */
                bout.write(1);

                /* wrap the bytes from the stream in a buffer */
                var bytes = bout.toByteArray();
                return(ByteBuffer.wrap(bytes));
            }
            finally
            {
                os.close();
            }
        }
Beispiel #13
0
        /// <summary>
        /// Encodes the archive into a <see cref="ByteBuffer"/>.
        /// </summary>
        /// <returns>A <see cref="ByteBuffer"/> containing the archive contents</returns>
        public ByteBuffer Encode()
        {
            using (var bOutStream = new ByteArrayOutputStream())
            {
                using (var outStream = new DataOutputStream(bOutStream))
                {
                    /* add the data for each entry */
                    for (var id = 0; id < this.Entries.Length; id++)
                    {
                        /* copy to temp buffer */
                        var temp = new byte[this.Entries[id].limit()];
                        this.Entries[id].position(0);
                        try
                        {
                            this.Entries[id].get(temp);
                        }
                        finally
                        {
                            this.Entries[id].position(0);
                        }

                        /* copy to output stream */
                        outStream.write(temp);
                    }

                    /* write the chunk lengths */
                    var prev = 0;
                    for (var id = 0; id < this.Entries.Length; id++)
                    {
                        /*
                         * since each file is stored in the only chunk, just write the
                         * delta-encoded file size
                         */
                        var chunkSize = this.Entries[id].limit();
                        outStream.writeInt(chunkSize - prev);
                        prev = chunkSize;
                    }

                    /* we only used one chunk due to a limitation of the implementation */
                    bOutStream.write(1);

                    /* wrap the bytes from the stream in a buffer */
                    var bytes = bOutStream.toByteArray();
                    return(ByteBuffer.wrap(bytes));
                }
            }
        }
        private void func_22107_a(File file, ArrayList arraylist, int i, int j, IProgressUpdate iprogressupdate)
        {
            Collections.sort(arraylist);
            var abyte0 = new byte[4096];
            int i1;

            for (Iterator iterator = arraylist.iterator(); iterator.hasNext(); iprogressupdate.setLoadingProgress(i1))
            {
                var        filematcher = (FileMatcher)iterator.next();
                int        k           = filematcher.func_22205_b();
                int        l           = filematcher.func_22204_c();
                RegionFile regionfile  = RegionFileCache.func_22123_a(file, k, l);
                if (!regionfile.isChunkSaved(k & 0x1f, l & 0x1f))
                {
                    try
                    {
                        var datainputstream =
                            new DataInputStream(new GZIPInputStream(new FileInputStream(filematcher.func_22207_a())));
                        DataOutputStream dataoutputstream = regionfile.getChunkDataOutputStream(k & 0x1f, l & 0x1f);
                        for (int j1 = 0; (j1 = datainputstream.read(abyte0)) != -1;)
                        {
                            dataoutputstream.write(abyte0, 0, j1);
                        }

                        dataoutputstream.close();
                        datainputstream.close();
                    }
                    catch (IOException ioexception)
                    {
                        ioexception.printStackTrace();
                    }
                }
                i++;
                i1 = (int)Math.round((100D * i) / j);
            }

            RegionFileCache.func_22122_a();
        }
Beispiel #15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.storageengine.api.WritableChannel put(byte[] value, int length) throws java.io.IOException
        public override WritableChannel Put(sbyte[] value, int length)
        {
            _dataOutputStream.write(value, 0, length);
            return(this);
        }
Beispiel #16
0
 public static void writePacket(Packet packet, DataOutputStream dataoutputstream)
 {
     dataoutputstream.write(packet.getPacketId());
     packet.writePacketData(dataoutputstream);
 }
Beispiel #17
0
 public override void writePacketData(DataOutputStream dataoutputstream)
 {
     dataoutputstream.writeInt(xPosition);
     dataoutputstream.writeInt(yPosition);
     dataoutputstream.write(mode ? 1 : 0);
 }
Beispiel #18
0
 public override void writePacketData(DataOutputStream dataoutputstream)
 {
     dataoutputstream.write(onGround ? 1 : 0);
 }
Beispiel #19
0
        public static void Main(string[] args)
        {
            File fileToc1 = new File("tmp/umdbuffer1.toc");
            File fileIso1 = new File("tmp/umdbuffer1.iso");
            File fileToc2 = new File("tmp/umdbuffer2.toc");
            File fileIso2 = new File("tmp/umdbuffer2.iso");
            File fileToc  = new File("tmp/umdbuffer.toc");
            File fileIso  = new File("tmp/umdbuffer.iso");

            try
            {
                System.IO.FileStream fosToc  = new System.IO.FileStream(fileToc, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                System.IO.FileStream fosIso  = new System.IO.FileStream(fileIso, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                System.IO.FileStream fisToc1 = new System.IO.FileStream(fileToc1, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                System.IO.FileStream fisIso1 = new System.IO.FileStream(fileIso1, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                System.IO.FileStream fisToc2 = new System.IO.FileStream(fileToc2, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                DataOutput           toc     = new DataOutputStream(fosToc);
                DataOutput           iso     = new DataOutputStream(fosIso);
                DataInput            toc1    = new DataInputStream(fisToc1);
                DataInput            iso1    = new DataInputStream(fisIso1);
                DataInput            toc2    = new DataInputStream(fisToc2);
                RandomAccessFile     iso2    = new RandomAccessFile(fileIso2, "r");

                int numSectors      = toc1.readInt();
                int numSectorsMerge = toc2.readInt();
                toc.writeInt(System.Math.Max(numSectors, numSectorsMerge));

                Dictionary <int, int> tocHashMap = new Dictionary <int, int>();
                for (int i = 4; i < fileToc1.Length(); i += 8)
                {
                    int sectorNumber         = toc1.readInt();
                    int bufferedSectorNumber = toc1.readInt();
                    tocHashMap[sectorNumber] = bufferedSectorNumber;
                    toc.writeInt(sectorNumber);
                    toc.writeInt(bufferedSectorNumber);
                }

                sbyte[] buffer = new sbyte[sectorLength];
                for (int i = 0; i < fileIso1.Length(); i += buffer.Length)
                {
                    iso1.readFully(buffer);
                    iso.write(buffer);
                }

                int nextFreeBufferedSectorNumber = (int)(fileIso1.Length() / sectorLength);
                for (int i = 4; i < fileToc2.Length(); i += 8)
                {
                    int sectorNumber         = toc2.readInt();
                    int bufferedSectorNumber = toc2.readInt();
                    if (!tocHashMap.ContainsKey(sectorNumber))
                    {
                        iso2.seek(bufferedSectorNumber * (long)sectorLength);
                        iso2.readFully(buffer);
                        iso.write(buffer);

                        toc.writeInt(sectorNumber);
                        toc.writeInt(nextFreeBufferedSectorNumber);
                        tocHashMap[sectorNumber] = nextFreeBufferedSectorNumber;
                        nextFreeBufferedSectorNumber++;
                    }
                }

                fosToc.Close();
                fosIso.Close();
                fisToc1.Close();
                fisIso1.Close();
                fisToc2.Close();
                iso2.close();
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
        }
Beispiel #20
0
        public byte[] UploadValues(Uri address, NameValueCollection data)
        {
            // http://www.xyzws.com/Javafaq/how-to-use-httpurlconnection-post-data-to-web-server/139
            // http://stackoverflow.com/questions/3038176/httpurlconnection-does-not-read-the-whole-respnse

            var addressString = address.ToString();
            //Console.WriteLine("enter UploadValues " + new { addressString });



            //             String urlParameters =
            //"fName=" + URLEncoder.encode("???", "UTF-8") +
            //"&lName=" + URLEncoder.encode("???", "UTF-8")

            var m = new MemoryStream();

            try
            {
                //Console.WriteLine("before urlParameters");
                #region urlParameters
                var urlParameters = new StringBuilder();

                //Implementation not found for type import :
                //type: System.Collections.Specialized.NameObjectCollectionBase
                //method: KeysCollection get_Keys()
                //Did you forget to add the [Script] attribute?
                //Please double check the signature!

                //foreach (string key in data.Keys)

                foreach (string key in data.AllKeys)
                {
                    if (urlParameters.Length > 0)
                    {
                        urlParameters.Append("&");
                    }


                    urlParameters.Append(
                        key + "=" + URLEncoder.encode(data[key], "UTF-8")
                        );
                }
                #endregion

                //Console.WriteLine("after urlParameters");

                //            Y:\staging\web\java\ScriptCoreLibJava\BCLImplementation\System\Net\__WebClient___c__DisplayClass2.java:60: error: unreported exception UnsupportedEncodingException; must be caught or declared to be thrown
                //builder0.Append(__String.Concat(string1, "=", URLEncoder.encode(this.data.get_Item(string1), "UTF-8")));
                //                                                               ^

                //Console.WriteLine(
                //    new { addressString }
                //);

                var url = new java.net.URL(addressString);

                // https://developer.android.com/training/articles/security-ssl.html

                var connection = (HttpURLConnection)url.openConnection();
                var https      = connection as HttpsURLConnection;
                if (https != null)
                {
                    Console.WriteLine(new { https });
                }


                connection.setUseCaches(false);
                connection.setDoInput(true);
                connection.setDoOutput(true);
                connection.setChunkedStreamingMode(0);

                // Numeric status code, 403: Forbidden

                // UserAgent:  Java/1.7.0_45
                //HtmlElement: Access denied | my.monese.com used CloudFlare to restrict access</title>
                //- Http: Request, POST /xml/GetCurrencyRateBasedOnString
                //   Command: POST
                // + URI: /xml/GetCurrencyRateBasedOnString
                //   ProtocolVersion: HTTP/1.1
                // + ContentType:  application/x-www-form-urlencoded
                //   Cache-Control:  no-cache
                //   Pragma:  no-cache
                //   UserAgent:  Java/1.7.0_45
                //   Host:  my.monese.com
                //   Accept:  text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
                //   Connection:  keep-alive
                //   ContentLength:  106
                //   HeaderEnd: CRLF

                //- Http: Request, POST /xml/GetCurrencyRateBasedOnString
                //   Command: POST
                // + URI: /xml/GetCurrencyRateBasedOnString
                //   ProtocolVersion: HTTP/1.1
                // + ContentType:  application/x-www-form-urlencoded
                //   Host:  my.monese.com
                //   ContentLength:  106
                //   Expect:  100-continue
                //   Connection:  Keep-Alive
                //   HeaderEnd: CRLF


                //                error { Message = Connection timed out: connect, StackTrace = java.net.ConnectException: Connection timed out: connect
                //at java.net.DualStackPlainSocketImpl.connect0(Native Method)

                connection.setRequestMethod("POST");

                // https://issues.jenkins-ci.org/browse/JENKINS-21033?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
                // https://github.com/scalaj/scalaj-http/issues/27

                connection.setRequestProperty("User-Agent", "WebClient");
                connection.setRequestProperty("Accept", "application/xml");

                connection.setRequestProperty(
                    "Content-Type", "application/x-www-form-urlencoded"
                    );

                var bytes = Encoding.UTF8.GetBytes(
                    urlParameters.ToString()
                    );


                connection.setRequestProperty("Content-Length", "" + bytes.Length);

                //connection.setRequestProperty("Content-Language", "en-US");


                if (Headers != null)
                {
                    foreach (string key in Headers.AllKeys)
                    {
                        connection.addRequestProperty(key, Headers[key]);
                    }
                }

                //Console.WriteLine("before writeBytes " + new { bytes.Length });

                #region Send request
                var wr = new DataOutputStream(
                    connection.getOutputStream());

                wr.write((sbyte[])(object)bytes);

                //wr.writeBytes(urlParameters.ToString());
                wr.flush();
                #endregion

                //error { Message = Server returned HTTP response code: 403 for URL:
                //        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
                //        at ScriptCoreLibJava.BCLImplementation.System.Net.__WebClient___c__DisplayClass2._UploadValuesAsync_b__1(__WebClient___c__DisplayClass2.java:82)

                //Console.WriteLine("before Read ");

                // X:\jsc.svn\core\ScriptCoreLibJava\BCLImplementation\System\Net\WebClient.cs

                //Get Response
                // namespace java.io

                var asw = Stopwatch.StartNew();

                var ResponseCode = connection.getResponseCode();

                //Console.WriteLine("awaiting for input...");
                var xis = connection.getInputStream().ToNetworkStream();

                var buffer = new byte[0x4000];
                //var buffer = new byte[0x10000];

                // do we have to wait on android?
                //Console.WriteLine(new { xis.DataAvailable, asw.ElapsedMilliseconds });

                //var ss = xis.Read(buffer, 0, 0);

                //Console.WriteLine(new { ss, xis.DataAvailable, asw.ElapsedMilliseconds });


                //I/System.Console( 7821): { DataAvailable = false, ElapsedMilliseconds = 8278 }
                //I/System.Console( 7821): awaiting for input... { s = 2730 }
                //I/System.Console( 7821): awaiting for input... { s = 1340 }
                //I/System.Console( 7821): awaiting for input... { s = 438 }
                //I/System.Console( 7821): awaiting for input... { s = -1 }
                //I/System.Console( 7821): bytes: {{ Length = 4508 }}
                //I/System.Console( 7821): source: {{ Length = 4496 }}

                //I/System.Console(10970): { DataAvailable = true, ElapsedMilliseconds = 236 }
                //I/System.Console(10970): { ss = 0, DataAvailable = true, ElapsedMilliseconds = 237 }

                //var ok = true;

                while (xis.DataAvailable)
                //while (ok)
                {
                    var s = xis.Read(buffer, 0, buffer.Length);
                    //Console.WriteLine("awaiting for input... " + new { s });

                    //if (s < 0)
                    //{
                    //    ok = false;
                    //}
                    //else
                    if (s > 0)
                    {
                        m.Write(buffer, 0, s);
                    }
                }

                //wr.close();
                //xis.Close();
                if (connection != null)
                {
                    connection.disconnect();
                }
                //xis.Read(
                //xis.readall
            }
            catch (Exception ex)
            {
                //error { Message = failed to connect to apps.emta.ee/213.184.49.80 (port 80): connect failed: ETIMEDOUT (Connection timed out), StackTrace = java.net.ConnectException: failed to connect to apps.emta.ee/213.184.49.80 (port 80): connect failed: ETIMEDOUT (Connection timed out)
                //       at libcore.io.IoBridge.connect(IoBridge.java:114)
                //       at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
                //       at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
                //       at java.net.Socket.connect(Socket.java:843)
                //       at com.android.okhttp.internal.Platform.connectSocket(Platform.java:131)
                //       at com.android.okhttp.Connection.connect(Connection.java:101)
                //       at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:294)
                //       at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
                //       at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
                //       at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
                //       at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89)
                //       at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:197)

                // ?
                Console.WriteLine("error " + new { ex.Message, ex.StackTrace });
            }

            //Thread.Sleep(666);
            var Result = m.ToArray();

            return(Result);
        }
Beispiel #21
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public PackOutput writeByte(byte value) throws java.io.IOException
        public override PackOutput WriteByte(sbyte value)
        {
            Data.write(value);
            return(this);
        }
Beispiel #22
0
        /// <summary>
        ///     Encodes this <seealso cref="ReferenceTable" /> into a <seealso cref="ByteBuffer" />.
        /// </summary>
        /// <returns> The <seealso cref="ByteBuffer" />. </returns>
        /// <exception cref="IOException"> if an I/O error occurs. </exception>
        public virtual ByteBuffer Encode()
        {
            /*
             * we can't (easily) predict the size ahead of time, so we write to a
             * stream and then to the buffer
             */
            var bout = new ByteArrayOutputStream();
            var os   = new DataOutputStream(bout);

            try
            {
                /* write the header */
                os.write(format);
                if (format >= 6)
                {
                    os.writeInt(version);
                }
                os.write(flags);

                /* calculate and write the number of non-null entries */
                os.writeShort(entries.Count);

                /* write the ids */
                var last = 0;
                for (var id = 0; id < Capacity(); id++)
                {
                    if (entries.ContainsKey(id))
                    {
                        var delta = id - last;
                        os.writeShort(delta);
                        last = id;
                    }
                }

                /* write the identifiers if required */
                if ((flags & FLAG_IDENTIFIERS) != 0)
                {
                    foreach (var entry in entries.Values)
                    {
                        os.writeInt(entry.identifier);
                    }
                }

                /* write the CRC checksums */
                foreach (var entry in entries.Values)
                {
                    os.writeInt(entry.crc);
                }

                /* write the whirlpool digests if required */
                if ((flags & FLAG_WHIRLPOOL) != 0)
                {
                    foreach (var entry in entries.Values)
                    {
                        os.write(entry.whirlpool);
                    }
                }

                /* write the versions */
                foreach (var entry in entries.Values)
                {
                    os.writeInt(entry.version);
                }

                /* calculate and write the number of non-null child entries */
                foreach (var entry in entries.Values)
                {
                    os.writeShort(entry.entries.Count);
                }

                /* write the child ids */
                foreach (var entry in entries.Values)
                {
                    last = 0;
                    for (var id = 0; id < entry.Capacity(); id++)
                    {
                        if (entry.entries.ContainsKey(id))
                        {
                            var delta = id - last;
                            os.writeShort(delta);
                            last = id;
                        }
                    }
                }

                /* write the child identifiers if required  */
                if ((flags & FLAG_IDENTIFIERS) != 0)
                {
                    foreach (var entry in entries.Values)
                    {
                        foreach (var child in entry.entries.Values)
                        {
                            os.writeInt(child.identifier);
                        }
                    }
                }

                /* convert the stream to a byte array and then wrap a buffer */
                var bytes = bout.toByteArray();
                return(ByteBuffer.wrap(bytes));
            }
            finally
            {
                os.close();
            }
        }
Beispiel #23
0
        /// <summary>
        ///     Encodes this <seealso cref="Sprite" /> into a <seealso cref="ByteBuffer" />.
        ///     <p />
        ///     Please note that this is a fairly simple implementation which only
        ///     supports vertical encoding. It does not attempt to use the offsets
        ///     to save space.
        /// </summary>
        /// <returns> The buffer. </returns>
        /// <exception cref="IOException"> if an I/O exception occurs. </exception>
        public ByteBuffer Encode()
        {
            var bout = new ByteArrayOutputStream();
            var os   = new DataOutputStream(bout);

            try
            {
                /* set up some variables */
                IList <int?> palette = new List <int?>();
                palette.Add(0); // transparent colour

                /* write the sprites */
                foreach (var image in frames)
                {
                    /* check if we can encode this */
                    if (image.getWidth() != width || image.getHeight() != height)
                    {
                        throw new IOException("All frames must be the same size.");
                    }

                    /* loop through all the pixels constructing a palette */
                    var flags = FLAG_VERTICAL; // TODO: do we need to support horizontal encoding?
                    for (var x = 0; x < width; x++)
                    {
                        for (var y = 0; y < height; y++)
                        {
                            /* grab the colour of this pixel */
                            var argb  = image.getRGB(x, y);
                            var alpha = (argb >> 24) & 0xFF;
                            var rgb   = argb & 0xFFFFFF;
                            if (rgb == 0)
                            {
                                rgb = 1;
                            }

                            /* we need an alpha channel to encode this image */
                            if (alpha != 0 && alpha != 255)
                            {
                                flags |= FLAG_ALPHA;
                            }

                            /* add the colour to the palette if it isn't already in the palette */
                            if (!palette.Contains(rgb))
                            {
                                if (palette.Count >= 256)
                                {
                                    throw new IOException("Too many colours in this sprite!");
                                }
                                palette.Add(rgb);
                            }
                        }
                    }

                    /* write this sprite */
                    os.write(flags);
                    for (var x = 0; x < width; x++)
                    {
                        for (var y = 0; y < height; y++)
                        {
                            var argb  = image.getRGB(x, y);
                            var alpha = (argb >> 24) & 0xFF;
                            var rgb   = argb & 0xFFFFFF;
                            if (rgb == 0)
                            {
                                rgb = 1;
                            }

                            if ((flags & FLAG_ALPHA) == 0 && alpha == 0)
                            {
                                os.write(0);
                            }
                            else
                            {
                                os.write(palette.IndexOf(rgb));
                            }
                        }
                    }

                    /* write the alpha channel if this sprite has one */
                    if ((flags & FLAG_ALPHA) != 0)
                    {
                        for (var x = 0; x < width; x++)
                        {
                            for (var y = 0; y < height; y++)
                            {
                                var argb  = image.getRGB(x, y);
                                var alpha = (argb >> 24) & 0xFF;
                                os.write(alpha);
                            }
                        }
                    }
                }

                /* write the palette */
                for (var i = 1; i < palette.Count; i++)
                {
                    var rgb = (int)palette[i];
                    os.write((byte)(rgb >> 16));
                    os.write((byte)(rgb >> 8));
                    os.write((byte)rgb);
                }

                /* write the max width, height and palette size */
                os.writeShort(width);
                os.writeShort(height);
                os.write(palette.Count - 1);

                /* write the individual offsets and dimensions */
                for (var i = 0; i < frames.Length; i++)
                {
                    os.writeShort(0); // offset X
                    os.writeShort(0); // offset Y
                    os.writeShort(width);
                    os.writeShort(height);
                }

                /* write the number of frames */
                os.writeShort(frames.Length);

                /* convert the stream to a byte array and then wrap a buffer */
                var bytes = bout.toByteArray();
                return(ByteBuffer.wrap(bytes));
            }
            finally
            {
                os.close();
            }
        }
Beispiel #24
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void send(java.io.DataOutputStream dataOut, byte[] bytesToSend) throws java.io.IOException
        private static void Send(DataOutputStream dataOut, sbyte[] bytesToSend)
        {
            dataOut.write(bytesToSend);
            dataOut.flush();
        }