ToByteArray() 공개 정적인 메소드

Converts a array of object-type instances to a byte-type array.
public static ToByteArray ( object tempObjectArray ) : byte[]
tempObjectArray object Array to convert.
리턴 byte[]
예제 #1
0
 /// <summary> Returns the content of this RfcLdapSuperDN as a String.</summary>
 public System.String stringValue()
 {
     System.String s = null;
     try {
         System.Text.Encoding encoder = System.Text.Encoding.GetEncoding("utf-8");
         char[] dchar = encoder.GetChars(SupportClass.ToByteArray(content));
         s = new String(dchar);
     }
     catch (System.IO.IOException uee) {
         throw new System.SystemException(uee.ToString());
     }
     return(s);
 }
예제 #2
0
        /// <summary> Returns a string representation of this LdapAttribute
        ///
        /// </summary>
        /// <returns> a string representation of this LdapAttribute
        /// </returns>
        public override string ToString()
        {
            System.Text.StringBuilder result = new System.Text.StringBuilder("LdapAttribute: ");
            try
            {
                result.Append("{type='" + name + "'");
                if (values != null)
                {
                    result.Append(", ");
                    if (values.Length == 1)
                    {
                        result.Append("value='");
                    }
                    else
                    {
                        result.Append("values='");
                    }
                    for (int i = 0; i < values.Length; i++)
                    {
                        if (i != 0)
                        {
                            result.Append("','");
                        }
                        if (((sbyte[])values[i]).Length == 0)
                        {
                            continue;
                        }
                        System.Text.Encoding encoder = System.Text.Encoding.GetEncoding("utf-8");
                        //						char[] dchar = encoder.GetChars((byte[]) values[i]);
                        char[] dchar = encoder.GetChars(SupportClass.ToByteArray((sbyte[])values[i]));
                        string sval  = new string(dchar);

                        //						System.String sval = new String((sbyte[]) values[i], "UTF-8");
                        if (sval.Length == 0)
                        {
                            // didn't decode well, must be binary
                            result.Append("<binary value, length:" + sval.Length);
                            continue;
                        }
                        result.Append(sval);
                    }
                    result.Append("'");
                }
                result.Append("}");
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }
            return(result.ToString());
        }
예제 #3
0
        /// <summary>
        ///     Close Riff File.
        ///     Length is written too.
        /// </summary>
        public virtual int Close()
        {
            int retcode = DDC_SUCCESS;

            switch (Fmode)
            {
            case RFM_WRITE:
                try
                {
                    m_File.Seek(0, SeekOrigin.Begin);
                    try
                    {
                        sbyte[] br = new sbyte[8];
                        br[0] = (sbyte)((SupportClass.URShift(m_RiffHeader.CkId, 24)) & 0x000000FF);
                        br[1] = (sbyte)((SupportClass.URShift(m_RiffHeader.CkId, 16)) & 0x000000FF);
                        br[2] = (sbyte)((SupportClass.URShift(m_RiffHeader.CkId, 8)) & 0x000000FF);
                        br[3] = (sbyte)(m_RiffHeader.CkId & 0x000000FF);

                        br[7] = (sbyte)((SupportClass.URShift(m_RiffHeader.CkSize, 24)) & 0x000000FF);
                        br[6] = (sbyte)((SupportClass.URShift(m_RiffHeader.CkSize, 16)) & 0x000000FF);
                        br[5] = (sbyte)((SupportClass.URShift(m_RiffHeader.CkSize, 8)) & 0x000000FF);
                        br[4] = (sbyte)(m_RiffHeader.CkSize & 0x000000FF);
                        m_File.Write(SupportClass.ToByteArray(br), 0, 8);
                        m_File.Dispose();
                    }
                    catch
                    {
                        retcode = DDC_FILE_ERROR;
                    }
                }
                catch
                {
                    retcode = DDC_FILE_ERROR;
                }
                break;

            case RFM_READ:
                try
                {
                    m_File.Dispose();
                }
                catch
                {
                    retcode = DDC_FILE_ERROR;
                }
                break;
            }
            m_File = null;
            Fmode  = RFM_UNKNOWN;
            return(retcode);
        }
예제 #4
0
        /// <summary>  Description of the Method
        ///
        /// </summary>
        /// <param name="recordNumber">    Description of the Parameter
        /// </param>
        /// <returns>                  Description of the Return Value
        /// </returns>
        /// <exception cref="">  IOException  Description of the Exception
        /// </exception>
        //UPGRADE_NOTE: Synchronized keyword was removed from method 'read'. Lock expression was added. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1027"'
        public virtual System.String read(int recordNumber)
        {
            lock (this)
            {
                if (recordNumber < bufferIdx || recordNumber >= bufferIdx + 100)
                {
                    bufferIdx = (recordNumber / 100) * 100;
                    file.Seek(bufferIdx * recordSize + HEADER_SIZE, System.IO.SeekOrigin.Begin);
                    if (bufferIdx + 100 >= count)
                    {
                        SupportClass.ReadInput(file, ref bigBuffer, 0, (count - bufferIdx) * recordSize);
                    }
                    else
                    {
                        SupportClass.ReadInput(file, ref bigBuffer, 0, bigBuffer.Length);
                    }
                }
                //		long idx = (long)recordNumber * (long)recordSize + HEADER_SIZE;
                int idx = (recordNumber - bufferIdx) * recordSize;
                //		System.out.println("rn="+recordNumber+",bi="+bufferIdx+",idx="+idx+",rs="+recordSize+",bbs="+bigBuffer.length+",bs="+readBuffer.length);
                try
                {
                    Array.Copy(SupportClass.ToByteArray(bigBuffer), idx, SupportClass.ToByteArray(readBuffer), 0, recordSize);
                    //Array.Copy(SupportClass.ToByteArray((System.Array) bigBuffer), idx, SupportClass.ToByteArray((System.Array) readBuffer), 0, recordSize);
                }
                catch (System.Exception e)
                {
                    SupportClass.WriteStackTrace(e, Console.Error);
                    System.Console.Out.WriteLine("rn=" + recordNumber + ",bi=" + bufferIdx + ",idx=" + idx + ",rs=" + recordSize + ",bbs=" + bigBuffer.Length + ",bs=" + readBuffer.Length);
                }

                /*
                 * file.seek(idx);
                 * file.readFully(readBuffer);*/
                //		System.out.println("read id="+recordNumber+":"+(new String(readBuffer,0,recordSize)));
                for (int i = 0; i < recordSize; i++)
                {
                    if (readBuffer[i] == '^')
                    {
                        char[] tmpChar;
                        tmpChar = new char[readBuffer.Length];
                        readBuffer.CopyTo(tmpChar, 0);
                        return(new System.String(tmpChar, 0, i));
                    }
                }
                char[] tmpChar2;
                tmpChar2 = new char[readBuffer.Length];
                readBuffer.CopyTo(tmpChar2, 0);
                return(new System.String(tmpChar2, 0, recordSize - 1));
            }
        }
예제 #5
0
 internal static String bytesToString(sbyte[] bytes, int offset, int length, String encoding)
 {
     try
     {
         return(Encoding.GetEncoding(encoding).GetString(SupportClass.ToByteArray(bytes), offset, length));
     }
     catch (IOException uee)
     {
         // This should only be used when 'encoding' is an encoding that must necessarily
         // be supported by the JVM, like UTF-8
         //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
         throw new SystemException("Platform does not support required encoding: " + uee);
     }
 }
예제 #6
0
 private void  sendMessage(System.String theMessage)
 {
     sbyte[] temp_sbyteArray;
     temp_sbyteArray = SupportClass.ToSByteArray(SupportClass.ToByteArray(HL7_START_OF_MESSAGE));
     os.Write(SupportClass.ToByteArray(temp_sbyteArray), 0, temp_sbyteArray.Length);
     sbyte[] temp_sbyteArray2;
     temp_sbyteArray2 = SupportClass.ToSByteArray(SupportClass.ToByteArray(theMessage));
     os.Write(SupportClass.ToByteArray(temp_sbyteArray2), 0, temp_sbyteArray2.Length);
     sbyte[] temp_sbyteArray3;
     temp_sbyteArray3 = SupportClass.ToSByteArray(SupportClass.ToByteArray(HL7_END_OF_MESSGAE));
     os.Write(SupportClass.ToByteArray(temp_sbyteArray3), 0, temp_sbyteArray3.Length);
     os.WriteByte((System.Byte) 13);
     os.Flush();
 }
예제 #7
0
파일: LBERDecoder.cs 프로젝트: cmsd2/oidc
        public virtual Asn1Object decode(sbyte[] value_Renamed)
        {
            Asn1Object asn1 = null;

            System.IO.MemoryStream in_Renamed = new System.IO.MemoryStream(SupportClass.ToByteArray(value_Renamed));
            try
            {
                asn1 = decode(in_Renamed);
            }
            catch (System.IO.IOException ioe)
            {
            }
            return(asn1);
        }
예제 #8
0
 public RfcBindResponse(Asn1Decoder dec, System.IO.Stream in_Renamed, int len) : base(dec, in_Renamed, len)
 {
     // Decode optional referral from Asn1OctetString to Referral.
     if (size() > 3)
     {
         Asn1Tagged     obj = (Asn1Tagged)get_Renamed(3);
         Asn1Identifier id  = obj.getIdentifier();
         if (id.Tag == RfcLdapResult.REFERRAL)
         {
             sbyte[] content             = ((Asn1OctetString)obj.taggedValue()).byteValue();
             System.IO.MemoryStream bais = new System.IO.MemoryStream(SupportClass.ToByteArray(content));
             set_Renamed(3, new RfcReferral(dec, bais, content.Length));
         }
     }
 }
        public virtual Asn1Object decode(sbyte[] value_Renamed)
        {
            Asn1Object asn1 = null;

            var in_Renamed = new MemoryStream(SupportClass.ToByteArray(value_Renamed));

            try
            {
                asn1 = decode(in_Renamed);
            }
            catch (IOException ioe)
            {
                LogManager.GetCurrentClassLogger().Warn("Exception swallowed", ioe);
            }
            return(asn1);
        }
예제 #10
0
 /// <summary>
 /// Write NumBytes data.
 /// </summary>
 internal virtual int Write(sbyte[] data, int numBytes)
 {
     if (Fmode != RF_WRITE)
     {
         return(DDC_INVALID_CALL);
     }
     try {
         _File.Write(SupportClass.ToByteArray(data), 0, numBytes);
         Fmode = RF_WRITE;
     }
     catch {
         return(DDC_FILE_ERROR);
     }
     _RiffHeader.CkSize += numBytes;
     return(DDC_SUCCESS);
 }
예제 #11
0
 internal static System.String bytesToString(sbyte[] bytes, int offset, int length, System.String encoding)
 {
     try
     {
         System.String tempStr;
         //UPGRADE_TODO: The differences in the Format  of parameters for constructor 'java.lang.String.String'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
         tempStr = System.Text.Encoding.GetEncoding(encoding).GetString(SupportClass.ToByteArray(bytes));
         return(new System.String(tempStr.ToCharArray(), offset, length));
     }
     catch (System.IO.IOException uee)
     {
         // This should only be used when 'encoding' is an encoding that must necessarily
         // be supported by the JVM, like UTF-8
         //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
         throw new System.Exception("Platform does not support required encoding: " + uee);
     }
 }
예제 #12
0
        protected Asn1Sequence getTaggedSequence(Asn1Tagged tagvalue, GeneralEventField tagid)
        {
            Asn1Object obj = tagvalue.taggedValue();

            if ((int)tagid != tagvalue.getIdentifier().Tag)
            {
                throw new IOException("Unknown Tagged Data");
            }

            byte[]       dbytes = SupportClass.ToByteArray(((Asn1OctetString)obj).byteValue());
            MemoryStream data   = new MemoryStream(dbytes);

            LBERDecoder dec    = new LBERDecoder();
            int         length = dbytes.Length;

            return(new Asn1Sequence(dec, data, length));
        }
예제 #13
0
        /// <summary>
        /// Write the byte array to the output stream
        ///
        /// </summary>
        /// <param name="bytes">
        /// </param>
        /// <param name="out">
        /// </param>
        /// <throws>  IOException </throws>
        public static void  writeToOutput(sbyte[] bytes, System.IO.Stream out_Renamed, long[] tally)
        {
            int offset = 0;
            int remain = bytes.Length;

            while (remain > 0)
            {
                int toRead = (remain < CHUNK_SIZE)?remain:CHUNK_SIZE;
                out_Renamed.Write(SupportClass.ToByteArray(bytes), offset, toRead);
                remain -= toRead;
                offset += toRead;
                if (tally != null)
                {
                    tally[0] += toRead;
                }
            }
        }
예제 #14
0
        /// <summary> Decode a CharacterString directly from a stream.</summary>
        public object decodeCharacterString(Stream in_Renamed, int len)
        {
            sbyte[] octets = new sbyte[len];

            for (int i = 0; i < len; i++)
            {
                int ret = in_Renamed.ReadByte(); // blocks
                if (ret == -1)
                {
                    throw new EndOfStreamException("LBER: CHARACTER STRING: decode error: EOF");
                }
                octets[i] = (sbyte)ret;
            }
            Encoding encoder = Encoding.GetEncoding("utf-8");

            char[] dchar = encoder.GetChars(SupportClass.ToByteArray(octets));
            return(new String(dchar));
        }
예제 #15
0
 /// <summary> Write NumBytes data.
 /// </summary>
 public virtual int Write(sbyte[] Data, int NumBytes)
 {
     if (fmode != RFM_WRITE)
     {
         return(DDC_INVALID_CALL);
     }
     try
     {
         file.Write(SupportClass.ToByteArray(Data), 0, NumBytes);
         fmode = RFM_WRITE;
     }
     catch (System.IO.IOException ioe)
     {
         return(DDC_FILE_ERROR);
     }
     riff_header.ckSize += NumBytes;
     return(DDC_SUCCESS);
 }
예제 #16
0
        protected string getTaggedStringValue(Asn1Tagged tagvalue, GeneralEventField tagid)
        {
            var obj = tagvalue.taggedValue();

            if ((int)tagid != tagvalue.getIdentifier().Tag)
            {
                throw new IOException("Unknown Tagged Data");
            }

            var dbytes = SupportClass.ToByteArray(((Asn1OctetString)obj).byteValue());
            var data   = new MemoryStream(dbytes);

            var dec = new LBERDecoder();

            var length = dbytes.Length;

            return((string)dec.decodeCharacterString(data, length));
        }
예제 #17
0
        //UPGRADE_NOTE: Synchronized keyword was removed from method 'readBytesAsc'. Lock expression was added. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1027'"
        public static byte[] readBytesAsc(int count, int pad)
        {
            lock (typeof(com.dalsemi.onewire.utils.IOHelper))
            {
                try
                {
                    System.String s   = br.ReadLine();
                    int           len = s.Length > count?count:s.Length;
                    byte[]        ret;

                    if (count > 0)
                    {
                        ret = new byte[count];
                    }
                    else
                    {
                        ret = new byte[s.Length];
                    }

                    if (count == 0)
                    {
                        //Array.Copy(SupportClass.ToByteArray(SupportClass.ToByteArray(s)), 0, ret, 0, s.Length);
                        Array.Copy(SupportClass.ToByteArray(s), 0, ret, 0, s.Length);

                        return(ret);
                    }

                    //Array.Copy(SupportClass.ToByteArray(SupportClass.ToByteArray(s)), 0, ret, 0, len);
                    Array.Copy(SupportClass.ToByteArray(s), 0, ret, 0, len);

                    for (; len < count; len++)
                    {
                        ret[len] = (byte)pad;
                    }

                    return(ret);
                }
                catch (System.IO.IOException e)
                {
                    return(new byte[count]);
                }
            }
        }
예제 #18
0
        /// <summary>  Description of the Method
        ///
        /// </summary>
        /// <param name="value"> Description of the Parameter
        /// </param>
        private void  fillWriteBuffer(System.String value_Renamed)
        {
            int len = value_Renamed.Length;

            sbyte[] buffer = SupportClass.ToSByteArray(SupportClass.ToByteArray(value_Renamed));

            if (len < (recordSize - 1))
            {
                //account for end of line char
                Array.Copy(SupportClass.ToByteArray(buffer), 0, SupportClass.ToByteArray(writeBuffer), 0, len);
                Array.Copy(SupportClass.ToByteArray(zapBuffer), 0, SupportClass.ToByteArray(writeBuffer), len, recordSize - len - 1);
                writeBuffer[recordSize - 1] = Convert.ToSByte('\n');
            }
            else
            {
                Array.Copy(SupportClass.ToByteArray(buffer), 0, SupportClass.ToByteArray(writeBuffer), 0, recordSize - 1);
                writeBuffer[recordSize - 1] = zapBuffer[recordSize - 1];
            }
        }
        private static void  decodeKanjiSegment(BitSource bits, System.Text.StringBuilder result, int count)
        {
            // Each character will require 2 bytes. Read the characters as 2-byte pairs
            // and decode as Shift_JIS afterwards
            sbyte[] buffer = new sbyte[2 * count];
            int     offset = 0;

            while (count > 0)
            {
                // Each 13 bits encodes a 2-byte character
                int twoBytes          = bits.readBits(13);
                int assembledTwoBytes = ((twoBytes / 0x0C0) << 8) | (twoBytes % 0x0C0);
                if (assembledTwoBytes < 0x01F00)
                {
                    // In the 0x8140 to 0x9FFC range
                    assembledTwoBytes += 0x08140;
                }
                else
                {
                    // In the 0xE040 to 0xEBBF range
                    assembledTwoBytes += 0x0C140;
                }
                buffer[offset]     = (sbyte)(assembledTwoBytes >> 8);
                buffer[offset + 1] = (sbyte)assembledTwoBytes;
                offset            += 2;
                count--;
            }
            // Shift_JIS may not be supported in some environments:
            try
            {
                //UPGRADE_TODO: The differences in the Format  of parameters for constructor 'java.lang.String.String'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
#if WINDOWS_PHONE
                byte[] byteArray = SupportClass.ToByteArray(buffer);
                result.Append(System.Text.Encoding.GetEncoding(SHIFT_JIS).GetString(byteArray, 0, byteArray.Length));
#else
                result.Append(System.Text.Encoding.GetEncoding(SHIFT_JIS).GetString(SupportClass.ToByteArray(buffer)));
#endif
            }
            catch (System.IO.IOException uee)
            {
                throw ReaderException.Instance;
            }
        }
예제 #20
0
 /// <summary>Copy an array of Strings to bytes.</summary>
 public static byte[] StringsToByteArray(String[] o, int maxLen)
 {
     byte[] res = new byte[o.Length * maxLen];
     for (int i = 0; i < o.Length; i += 1)
     {
         byte[] bstr = SupportClass.ToByteArray(o[i]);
         int    cnt  = bstr.Length;
         if (cnt > maxLen)
         {
             cnt = maxLen;
         }
         Array.Copy(bstr, 0, res, i * maxLen, cnt);
         for (int j = cnt; j < maxLen; j += 1)
         {
             res[i * maxLen + j] = (byte)SupportClass.Identity(' ');
         }
     }
     return(res);
 }
예제 #21
0
        public static sbyte[] getClassHash(System.Type type)
        {
            sbyte[] hash = new sbyte[CLASS_HASH_SIZE];
            //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
            sbyte[] md5 = MD5.hash(SupportClass.ToSByteArray(SupportClass.ToByteArray(type.FullName)));             //add support for a salt, in case of collision?

            for (int i = 0; i < hash.Length; i++)
            {
                hash[i] = md5[i];
            }
            sbyte[] badHash = new sbyte[] { 0, 4, 78, 97 };
            if (PrototypeFactory.compareHash(badHash, hash))
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                System.Console.Out.WriteLine("BAD CLASS: " + type.FullName);
            }

            return(hash);
        }
예제 #22
0
        /// <summary> Returns the content of this Asn1OctetString as a String.</summary>
        public string stringValue()
        {
            string s = null;

            try
            {
                var encoder = Encoding.GetEncoding("utf-8");
                var dchar   = encoder.GetChars(SupportClass.ToByteArray(content));
                s = new string(dchar);
//				sbyte *sb=content;
//				s = new  String(sb,0,content.Length, new System.Text.UTF8Encoding());
            }
            catch (IOException uee)
            {
                throw new Exception(uee.ToString());
            }

            return(s);
        }
예제 #23
0
        /// <summary> Encode an Asn1Tagged directly into the specified outputstream.</summary>
        public void encode(Asn1Tagged t, Stream out_Renamed)
        {
            if (t.Explicit)
            {
                encode(t.getIdentifier(), out_Renamed);

                /* determine the encoded length of the base type. */
                MemoryStream encodedContent = new MemoryStream();
                t.taggedValue().encode(this, encodedContent);

                encodeLength((int)encodedContent.Length, out_Renamed);
                sbyte[] temp_sbyteArray;
                temp_sbyteArray = SupportClass.ToSByteArray(encodedContent.ToArray());
                out_Renamed.Write(SupportClass.ToByteArray(temp_sbyteArray), 0, temp_sbyteArray.Length);
            }
            else
            {
                t.taggedValue().encode(this, out_Renamed);
            }
        }
        /// <summary> See ISO 16022:2006, 5.2.9 and Annex B, B.2</summary>
        private static void  decodeBase256Segment(BitSource bits, System.Text.StringBuilder result, System.Collections.ArrayList byteSegments)
        {
            // Figure out how long the Base 256 Segment is.
            int d1 = bits.readBits(8);
            int count;

            if (d1 == 0)
            {
                // Read the remainder of the symbol
                count = bits.available() / 8;
            }
            else if (d1 < 250)
            {
                count = d1;
            }
            else
            {
                count = 250 * (d1 - 249) + bits.readBits(8);
            }
            sbyte[] bytes = new sbyte[count];
            for (int i = 0; i < count; i++)
            {
                bytes[i] = unrandomize255State(bits.readBits(8), i);
            }
            byteSegments.Add(SupportClass.ToByteArray(bytes));
            try
            {
                //UPGRADE_TODO: The differences in the Format  of parameters for constructor 'java.lang.String.String'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
#if WINDOWS_PHONE
                byte[] byteArray = SupportClass.ToByteArray(bytes);
                result.Append(System.Text.Encoding.GetEncoding("ISO8859_1").GetString(byteArray, 0, byteArray.Length));
#else
                result.Append(System.Text.Encoding.GetEncoding("ISO8859_1").GetString(SupportClass.ToByteArray(bytes)));
#endif
            }
            catch (System.IO.IOException uee)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                throw new System.SystemException("Platform does not support required encoding: " + uee);
            }
        }
예제 #25
0
        internal void ConnectHTTPProxy()
        {
            HTTPRequest request = new HTTPRequest("CONNECT "
                                                  + hostname
                                                  + ":"
                                                  + port
                                                  + " HTTP/1.0");

            request.SetHeaderField("User-Agent", "Maverick.NET");
            request.SetHeaderField("Pragma", "No-Cache");
            request.SetHeaderField("Host", hostname);
            request.SetHeaderField("Proxy-Connection", "Keep-Alive");

            byte[] tmp;

            if (username != null)
            {
                tmp = SupportClass.ToByteArray(username + ":" + (password == null ? "" : password));
                request.SetHeaderField("Proxy-Authorization",
                                       "Basic " + Convert.ToBase64String(tmp, 0, tmp.Length));
            }

            tmp = SupportClass.ToByteArray(request.ToString());
            netStream.Write(tmp, 0, tmp.Length);

            HTTPResponse response = new HTTPResponse(netStream);

            if (response.Status == 407)
            {
                throw new IOException("Proxy authentication required method="
                                      + response.AuthenticationMethod
                                      + " realm="
                                      + response.AuthenticationRealm);
            }

            if ((response.Status < 200) || (response.Status > 299))
            {
                throw new IOException("Proxy tunnel setup failed: " +
                                      response.GetStartLine());
            }
        }
        private static void  decodeByteSegment(BitSource bits, System.Text.StringBuilder result, int count, CharacterSetECI currentCharacterSetECI, System.Collections.ArrayList byteSegments)
        {
            sbyte[] readBytes = new sbyte[count];
            if (count << 3 > bits.available())
            {
                throw ReaderException.Instance;
            }
            for (int i = 0; i < count; i++)
            {
                readBytes[i] = (sbyte)bits.readBits(8);
            }
            System.String encoding;
            if (currentCharacterSetECI == null)
            {
                // The spec isn't clear on this mode; see
                // section 6.4.5: t does not say which encoding to assuming
                // upon decoding. I have seen ISO-8859-1 used as well as
                // Shift_JIS -- without anything like an ECI designator to
                // give a hint.
                encoding = guessEncoding(readBytes);
            }
            else
            {
                encoding = currentCharacterSetECI.EncodingName;
            }
            try
            {
                //UPGRADE_TODO: The differences in the Format  of parameters for constructor 'java.lang.String.String'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
#if WINDOWS_PHONE
                byte[] byteArray = SupportClass.ToByteArray(readBytes);
                result.Append(System.Text.Encoding.GetEncoding(encoding).GetString(byteArray, 0, byteArray.Length));
#else
                result.Append(System.Text.Encoding.GetEncoding(encoding).GetString(SupportClass.ToByteArray(readBytes)));
#endif
            }
            catch (System.IO.IOException uce)
            {
                throw ReaderException.Instance;
            }
            byteSegments.Add(SupportClass.ToByteArray(readBytes));
        }
예제 #27
0
        /* Asn1 TYPE NOT YET SUPPORTED
         * Encode an Asn1ObjectIdentifier directly to a stream.
         * public void encode(Asn1ObjectIdentifier oi, OutputStream out)
         * throws IOException
         * {
         * throw new IOException("LBEREncoder: Encode to a stream not implemented");
         * }
         */

        /* Asn1 TYPE NOT YET SUPPORTED
         * Encode an Asn1CharacterString directly to a stream.
         * public void encode(Asn1CharacterString cs, OutputStream out)
         * throws IOException
         * {
         * throw new IOException("LBEREncoder: Encode to a stream not implemented");
         * }
         */

        /* Encoders for ASN.1 structured types
         */

        /// <summary> Encode an Asn1Structured into the specified outputstream.  This method
        /// can be used to encode SET, SET_OF, SEQUENCE, SEQUENCE_OF
        /// </summary>
        public void encode(Asn1Structured c, System.IO.Stream out_Renamed)
        {
            encode(c.getIdentifier(), out_Renamed);

            Asn1Object[] value_Renamed = c.toArray();

            MemoryStream output = new MemoryStream();

            /* Cycle through each element encoding each element */
            for (int i = 0; i < value_Renamed.Length; i++)
            {
                (value_Renamed[i]).encode(this, output);
            }

            /* Encode the length */
            encodeLength((int)output.Length, out_Renamed);

            /* Add each encoded element into the output stream */
            sbyte[] temp_sbyteArray;
            temp_sbyteArray = SupportClass.ToSByteArray(output.ToArray());
            out_Renamed.Write(SupportClass.ToByteArray(temp_sbyteArray), 0, temp_sbyteArray.Length);;;
        }
예제 #28
0
 /// <summary>  Constructor for the DBase3Record object
 ///
 /// </summary>
 /// <param name="db">              Description of the Parameter
 /// </param>
 /// <exception cref="">  IOException  Description of the Exception
 /// </exception>
 public DBase3Record(DBase3 db)
 {
     this.db = db;
     values  = new System.String[db.fields.Length];
     sbyte[] buffer = new sbyte[db.longestFieldLength];
     deleted = (db.db.ReadByte() == (int)'*');
     for (int i = 0; i < values.Length; i++)
     {
         //			buffer = new byte[db.fields[i].length];
         if (!db.cache)
         {
             SupportClass.ReadInput(db.db, ref buffer, 0, db.fields[i].length);
         }
         else
         {
             Array.Copy(SupportClass.ToByteArray(db.fileBuffer), db.fileOffset, SupportClass.ToByteArray(buffer), 0, db.fields[i].length);
             db.fileOffset += db.fields[i].length;
         }
         //			System.out.println(new String(buffer));
         values[i] = DBase3.getString(buffer, db.fields[i].length);
         //			System.out.println(values[i]);
     }
 }
예제 #29
0
        /// <summary>
        ///     Write NumBytes data.
        /// </summary>
        public virtual int Write(RiffChunkHeader riffHeader, int numBytes)
        {
            sbyte[] br = new sbyte[8];
            br[0] = (sbyte)(SupportClass.URShift(riffHeader.CkId, 24) & 0x000000FF);
            br[1] = (sbyte)(SupportClass.URShift(riffHeader.CkId, 16) & 0x000000FF);
            br[2] = (sbyte)(SupportClass.URShift(riffHeader.CkId, 8) & 0x000000FF);
            br[3] = (sbyte)(riffHeader.CkId & 0x000000FF);

            sbyte br4 = (sbyte)(SupportClass.URShift(riffHeader.CkSize, 24) & 0x000000FF);
            sbyte br5 = (sbyte)(SupportClass.URShift(riffHeader.CkSize, 16) & 0x000000FF);
            sbyte br6 = (sbyte)(SupportClass.URShift(riffHeader.CkSize, 8) & 0x000000FF);
            sbyte br7 = (sbyte)(riffHeader.CkSize & 0x000000FF);

            br[4] = br7;
            br[5] = br6;
            br[6] = br5;
            br[7] = br4;

            if (Fmode != RFM_WRITE)
            {
                return(DDC_INVALID_CALL);
            }

            try
            {
                m_File.Write(SupportClass.ToByteArray(br), 0, numBytes);
                Fmode = RFM_WRITE;
            }
            catch
            {
                return(DDC_FILE_ERROR);
            }

            m_RiffHeader.CkSize += numBytes;

            return(DDC_SUCCESS);
        }
예제 #30
0
        public static System.String elementToString(Element e)
        {
            KXmlSerializer serializer = new KXmlSerializer();

            System.IO.MemoryStream bos = new System.IO.MemoryStream();
            //UPGRADE_TODO: Class 'java.io.DataOutputStream' was converted to 'System.IO.BinaryWriter' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataOutputStream'"
            System.IO.BinaryWriter dos = new System.IO.BinaryWriter(bos);
            System.String          s   = null;
            try
            {
                serializer.setOutput(dos, null);
                e.write(serializer);
                serializer.flush();
                //UPGRADE_TODO: The differences in the Format  of parameters for constructor 'java.lang.String.String'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                s = System.Text.Encoding.GetEncoding("UTF-8").GetString(SupportClass.ToByteArray(SupportClass.ToSByteArray(bos.ToArray())));
                return(s);
            }
            catch (System.IO.IOException uce)
            {
                SupportClass.WriteStackTrace(uce, Console.Error);
            }
            catch (System.Exception ex)
            {
                if (ex is org.javarosa.core.io.StreamsUtil.DirectionalIOException)
                {
                    ((org.javarosa.core.io.StreamsUtil.DirectionalIOException)ex).printStackTrace();
                }
                else
                {
                    SupportClass.WriteStackTrace(ex, Console.Error);
                }
                return(null);
            }

            return(null);
        }