Ejemplo n.º 1
0
 private static void WriteJavaMethod(this DataOutputStream stream, MetadataJavaMethod method)
 {
     stream.WriteUTF(method.Name);
     stream.WriteUTF(method.ReturnType);
     stream.WriteAccessFlagsParameter(method.AccessFlags);
     stream.WriteArray(method.Parameters, stream.WriteJavaParameter);
 }
Ejemplo n.º 2
0
 private static void WriteJavaField(this DataOutputStream stream, MetadataJavaField field)
 {
     stream.WriteUTF(field.Name);
     stream.WriteUTF(field.Type);
     stream.WriteAccessFlagsParameter(field.AccessFlags);
     stream.WriteBoolean(field.ConstantValue != null);
     if (field.ConstantValue != null)
     {
         stream.WriteArray(field.ConstantValue, b => stream.WriteByte(b));
     }
 }
 public virtual void Save(DataOutputStream @out)
 {
     try
     {
         @out.WriteUTF(word);
         @out.WriteUTF(tag);
     }
     catch (Exception e)
     {
         Sharpen.Runtime.PrintStackTrace(e);
     }
 }
Ejemplo n.º 4
0
 /// <summary>Write a string representation of a Pair to a DataStream.</summary>
 /// <remarks>
 /// Write a string representation of a Pair to a DataStream.
 /// The <code>toString()</code> method is called on each of the pair
 /// of objects and a <code>String</code> representation is written.
 /// This might not allow one to recover the pair of objects unless they
 /// are of type <code>String</code>.
 /// </remarks>
 public virtual void Save(DataOutputStream @out)
 {
     try
     {
         @out.WriteUTF(first.ToString());
         @out.WriteUTF(second.ToString());
     }
     catch (Exception e)
     {
         Sharpen.Runtime.PrintStackTrace(e);
     }
 }
Ejemplo n.º 5
0
            /// <exception cref="System.IO.IOException"/>
            public virtual void WriteApplicationACLs(IDictionary <ApplicationAccessType, string
                                                                  > appAcls)
            {
                DataOutputStream @out = this.writer.PrepareAppendKey(-1);

                ApplicationAclKey.Write(@out);
                @out.Close();
                @out = this.writer.PrepareAppendValue(-1);
                foreach (KeyValuePair <ApplicationAccessType, string> entry in appAcls)
                {
                    @out.WriteUTF(entry.Key.ToString());
                    @out.WriteUTF(entry.Value);
                }
                @out.Close();
            }
Ejemplo n.º 6
0
        private void WriteToDisk(System.IO.IsolatedStorage.IsolatedStorageFile iso, string storeFile)
        {
            DataOutputStream dos = FileUtils.WriteIsolatedStorageFileToDataInput(iso, storeFile);

            try
            {
                dos.WriteUTF(HEADER);
                dos.WriteInt(nextRecordId);
                dos.WriteInt(records.Count);
                for (int i = 0; i < records.Count; i++)
                {
                    RecordItem ri    = records[i];
                    long       pSize = ri.data.Length;
                    int        pId   = ri.id;
                    dos.WriteLong(pSize);
                    dos.WriteInt(pId);
                    dos.Write(ri.data);
                }
            }
            catch (Exception e)
            {
                throw new RecordStoreException("Error writing store to disk: " + e.StackTrace);
            }
            finally
            {
                if (dos != null)
                {
                    dos.Close();
                }
                dos = null;
            }
        }
Ejemplo n.º 7
0
 /*
  * public void save(String filename) {
  * try {
  * DataOutputStream rf = IOUtils.getDataOutputStream(filename);
  * save(rf);
  * rf.close();
  * } catch (Exception e) {
  * e.printStackTrace();
  * }
  * }
  */
 internal virtual void Save(DataOutputStream file)
 {
     string[] arr = Sharpen.Collections.ToArray(dict.Keys, new string[dict.Keys.Count]);
     try
     {
         file.WriteInt(arr.Length);
         log.Info("Saving dictionary of " + arr.Length + " words ...");
         foreach (string word in arr)
         {
             TagCount count = Get(word);
             file.WriteUTF(word);
             count.Save(file);
         }
         int[] arrverbs = Sharpen.Collections.ToArray(this.partTakingVerbs.Keys, new int[partTakingVerbs.Keys.Count]);
         file.WriteInt(arrverbs.Length);
         foreach (int iO in arrverbs)
         {
             CountWrapper tC = this.partTakingVerbs[iO];
             file.WriteInt(iO);
             tC.Save(file);
         }
     }
     catch (Exception e)
     {
         Sharpen.Runtime.PrintStackTrace(e);
     }
 }
Ejemplo n.º 8
0
        public override void ToOutputStream(DataOutputStream writer)
        {
            //Server to Client
            writer.WriteBoolean(DeckImage != null);
            if (DeckImage != null)
            {
                writer.WriteInt(ImageSlot);
                //Byte array lenght
                writer.WriteInt(DeckImage.InternalBitmap.Length);
                writer.Write(DeckImage.InternalBitmap);
                Json headerContent = new Json();


                headerContent.Font          = " ";
                headerContent.Size          = CurrentItem.Decksize;
                headerContent.Position      = CurrentItem.Deckposition;
                headerContent.Text          = CurrentItem.Deckname;
                headerContent.Color         = CurrentItem.Deckcolor;
                headerContent.Stroke_color  = CurrentItem.Stroke_color;
                headerContent.Stroke_dx     = CurrentItem.Stroke_dxtext;
                headerContent.Stroke_radius = CurrentItem.Stroke_radius;
                headerContent.Stroke_dy     = CurrentItem.Stroke_Dy;
                headerContent.IsStroke      = CurrentItem.IsStroke;
                headerContent.Isboldtext    = CurrentItem.Isboldtext;
                headerContent.Isnormaltext  = CurrentItem.Isnormaltext;
                headerContent.Isitalictext  = CurrentItem.Isitalictext;
                headerContent.Ishinttext    = CurrentItem.Ishinttext;
                string jsonString = JsonConvert.SerializeObject(headerContent, Formatting.None);

                writer.WriteUTF(jsonString);
            }
        }
        /// <summary>
        /// <see cref="AsyncTask.DoInBackground(Java.Lang.Object[])"/>
        /// </summary>
        override protected Java.Lang.Object DoInBackground(params Java.Lang.Object[] @params)
        {
            ServerSocket serverSocket = new ServerSocket(m_Port);

            Socket clientSocket = serverSocket.Accept();

            int         res;
            List <byte> buffer = new List <byte>();

            while ((res = clientSocket.InputStream.ReadByte()) != -1)
            {
                buffer.Add((byte)res);
            }

            m_Activity.RunOnUiThread(() =>
            {
                Toast.MakeText(m_Activity, $"Message received : {System.Text.Encoding.UTF8.GetString(buffer.ToArray())}", ToastLength.Short).Show();
            });

            DataOutputStream outputStream = new DataOutputStream(clientSocket.OutputStream);

            outputStream.WriteUTF("Merci !");
            outputStream.Close();

            m_Activity.RunOnUiThread(() =>
            {
                Toast.MakeText(m_Activity, $"Message sent : Merci !", ToastLength.Short).Show();
            });

            serverSocket.Close();

            return(null);
        }
Ejemplo n.º 10
0
        public static MetadataJavaField ToMetadata(this JavaField field)
        {
            var javaField = new MetadataJavaField
            {
                Name = field.Name,
                Type = field.Type.GetSignature()
            };

            if (field.ConstantValue != null)
            {
                using var stream = new MemoryStream();
                using var ms     = new MemoryOutputStream(stream);
                using var dos    = new DataOutputStream(ms);

                field.ConstantValue.Dump(dos);

                //Write the original string there to be able to create a new constantpool from metadata
                if (field.ConstantValue is ConstantString constantString)
                {
                    dos.WriteUTF(constantString.GetBytes(field.ConstantPool));
                }

                javaField.ConstantValue = stream.ToArray();
            }

            return(javaField);
        }
Ejemplo n.º 11
0
        public int write(DataOutputStream dos)
        {
            int size = 5;

            dos.WriteUTF(Streamable.MESSAGE_IONO);             // 5
            dos.WriteInt(STREAM_V); size += 4;
            dos.WriteLong(health); size  += 8;
            dos.WriteDouble(utcA1); size += 8;
            dos.WriteDouble(utcA0); size += 8;
            dos.WriteLong(utcTOW); size  += 8;
            dos.WriteInt(utcWNT); size   += 4;
            dos.WriteInt(utcLS); size    += 4;
            dos.WriteInt(utcWNF); size   += 4;
            dos.WriteInt(utcDN); size    += 4;
            dos.WriteInt(utcLSF); size   += 4;
            for (int i = 0; i < alpha.Count(); i++)
            {
                dos.WriteFloat(alpha[i]); size += 4;
            }
            for (int i = 0; i < beta.Count(); i++)
            {
                dos.WriteFloat(beta[i]); size += 4;
            }
            dos.WriteBoolean(validHealth); size    += 1;
            dos.WriteBoolean(validUTC); size       += 1;
            dos.WriteBoolean(validKlobuchar); size += 1;
            dos.WriteLong(refTime == null ? -1 : refTime.getMsec()); size += 8;

            return(size);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Serialize the token data for communication between server and client.
        /// </summary>
        /// <exception cref="IOException"></exception>
        public void Serialize(DataOutputStream writer)
        {
            writer.WriteUTF(Id);
            writer.WriteUTF(Version);
            writer.WriteInt32(SourceFiles.Count);

            foreach (KeyValuePair <string, IList <RevisionFile> > pair in SourceFiles)
            {
                writer.WriteUTF(pair.Key);
                writer.WriteInt32(pair.Value.Count);
                foreach (RevisionFile file in pair.Value)
                {
                    writer.WriteUTF(file.FileName);
                    writer.WriteInt64(file.Length);
                }
            }
        }
Ejemplo n.º 13
0
        public void Run()
        {
            Socket           socket       = new Socket("10.0.0.25", 1800);
            DataOutputStream outputStream = new DataOutputStream(socket.OutputStream);

            outputStream.WriteUTF("Hello World! Java...");
            socket.Close();
        }
Ejemplo n.º 14
0
            /// <exception cref="System.IO.IOException"/>
            public virtual void WriteApplicationOwner(string user)
            {
                DataOutputStream @out = this.writer.PrepareAppendKey(-1);

                ApplicationOwnerKey.Write(@out);
                @out.Close();
                @out = this.writer.PrepareAppendValue(-1);
                @out.WriteUTF(user);
                @out.Close();
            }
Ejemplo n.º 15
0
 public override void ToOutputStream(DataOutputStream writer)
 {
     //From server to client
     //Tell the client if they are going to receive a device Guid
     writer.WriteBoolean(!hasDeviceGuid);
     if (!hasDeviceGuid)
     {
         DeviceGuid = Guid.NewGuid();
         writer.WriteUTF(DeviceGuid.ToString());
     }
 }
Ejemplo n.º 16
0
 private static void WriteJarClass(this DataOutputStream stream, MetadataJavaClass @class)
 {
     stream.WriteUTF(@class.ClassName);
     stream.WriteAccessFlagsParameter(@class.AccessFlags);
     stream.WriteArray(@class.Interfaces, stream.WriteUTF);
     stream.WriteArray(@class.AllInterfaces, stream.WriteUTF);
     stream.WriteArray(@class.Interfaces, stream.WriteUTF);
     stream.WriteArray(@class.AllSuperClasses, stream.WriteUTF);
     stream.WriteArray(@class.Methods, stream.WriteJavaMethod);
     stream.WriteArray(@class.Fields, stream.WriteJavaField);
 }
Ejemplo n.º 17
0
        /// <summary>
        /// <see cref="AsyncTask.DoInBackground(Java.Lang.Object[])"/>
        /// </summary>
        protected override Java.Lang.Object DoInBackground(params Java.Lang.Object[] @params)
        {
            ServerSocket serverSocket = new ServerSocket(m_Port);
            Socket       clientSocket = serverSocket.Accept();

            DataOutputStream outputStream = new DataOutputStream(clientSocket.OutputStream);

            outputStream.WriteUTF("Coucou");
            outputStream.Flush();

            return(null);
        }
        public override void ToOutputStream(DataOutputStream writer)
        {
            //Server to Client
            if (String.IsNullOrEmpty(Text) == false)
            {
                writer.WriteInt(Id);
                //font
                writer.WriteUTF(Font);
                //text

                writer.WriteUTF(Text);
                //size
                writer.WriteInt(Size);
                //position
                writer.WriteInt(Position);

                //color

                writer.WriteUTF(Color);
            }
        }
Ejemplo n.º 19
0
 /// <summary>Saves the object to the file.</summary>
 /// <param name="rf">
 /// is a file handle
 /// Supposedly other objects will be written after this one in the file. The method does not close the file. The TagCount is saved at the current position.
 /// </param>
 protected internal virtual void Save(DataOutputStream rf)
 {
     try
     {
         rf.WriteInt(map.Count);
         foreach (string tag in map.Keys)
         {
             if (tag == null)
             {
                 rf.WriteUTF(NullSymbol);
             }
             else
             {
                 rf.WriteUTF(tag);
             }
             rf.WriteInt(map[tag]);
         }
     }
     catch (Exception e)
     {
         Sharpen.Runtime.PrintStackTrace(e);
     }
 }
Ejemplo n.º 20
0
        /* (non-Javadoc)
         * @see org.gogpsproject.Streamable#write(java.io.DataOutputStream)
         */
        public int write(DataOutputStream dos)
        {
            int size = 5;

            dos.WriteUTF(Streamable.MESSAGE_EPHEMERIS); // 5
            dos.WriteInt(STREAM_V); size += 4;          // 4

            dos.WriteLong(refTime == null?-1:refTime.getMsec());  size += 8;
            dos.Write(satID);  size  += 1;
            dos.WriteInt(week); size += 4;

            dos.WriteInt(L2Code); size += 4;
            dos.WriteInt(L2Flag); size += 4;

            dos.WriteInt(svAccur); size  += 4;
            dos.WriteInt(svHealth); size += 4;

            dos.WriteInt(iode); size += 4;
            dos.WriteInt(iodc); size += 4;

            dos.WriteDouble(toc); size += 8;
            dos.WriteDouble(toe); size += 8;

            dos.WriteDouble(af0); size += 8;
            dos.WriteDouble(af1); size += 8;
            dos.WriteDouble(af2); size += 8;
            dos.WriteDouble(tgd); size += 8;


            dos.WriteDouble(rootA); size  += 8;
            dos.WriteDouble(e); size      += 8;
            dos.WriteDouble(i0); size     += 8;
            dos.WriteDouble(iDot); size   += 8;
            dos.WriteDouble(omega); size  += 8;
            dos.WriteDouble(omega0); size += 8;

            dos.WriteDouble(omegaDot); size += 8;
            dos.WriteDouble(M0); size       += 8;
            dos.WriteDouble(deltaN); size   += 8;
            dos.WriteDouble(crc); size      += 8;
            dos.WriteDouble(crs); size      += 8;
            dos.WriteDouble(cuc); size      += 8;
            dos.WriteDouble(cus); size      += 8;
            dos.WriteDouble(cic); size      += 8;
            dos.WriteDouble(cis); size      += 8;

            dos.WriteDouble(fitInt); size += 8;

            return(size);
        }
Ejemplo n.º 21
0
        private void SendDeckLabel(DataOutputStream writer, int slot, DeckItemMisc item)
        {
            //Write the slot
            if (item.GetItemImage() != null)
            {
                Json headerContent = new Json();


                writer.WriteInt(slot);
                //Byte array lenght
                writer.WriteInt(item.GetItemImage().InternalBitmap.Length);
                writer.Write(item.GetItemImage().InternalBitmap);

                headerContent.Font     = " ";
                headerContent.Size     = item.Decksize;
                headerContent.Position = item.Deckposition;
                headerContent.Text     = item.Deckname;
                headerContent.Color    = item.Deckcolor;

                headerContent.Stroke_color  = item.Stroke_color;
                headerContent.Stroke_dx     = item.Stroke_dxtext;
                headerContent.Stroke_radius = item.Stroke_radius;
                headerContent.Stroke_dy     = item.Stroke_Dy;
                headerContent.IsStroke      = item.IsStroke;
                headerContent.Isboldtext    = item.Isboldtext;
                headerContent.Isnormaltext  = item.Isnormaltext;
                headerContent.Isitalictext  = item.Isitalictext;
                headerContent.Ishinttext    = item.Ishinttext;
                string jsonString = JsonConvert.SerializeObject(headerContent, Formatting.None);

                writer.WriteUTF(jsonString);

                ////text

                //writer.WriteUTF(text);
                ////size
                //writer.WriteInt(size);
                ////position
                //writer.WriteInt(pos);

                ////color

                //writer.WriteUTF(color);
            }
        }
Ejemplo n.º 22
0
 protected internal virtual void Save(DataOutputStream file, IDictionary <string, ICollection <string> > tagTokens)
 {
     try
     {
         file.WriteInt(index.Size());
         foreach (string item in index)
         {
             file.WriteUTF(item);
             if (learnClosedTags)
             {
                 if (tagTokens[item].Count < closedTagThreshold)
                 {
                     MarkClosed(item);
                 }
             }
             file.WriteBoolean(IsClosed(item));
         }
     }
     catch (IOException e)
     {
         throw new RuntimeIOException(e);
     }
 }
Ejemplo n.º 23
0
        /**
         * Entry point to the Compile application.
         * <p>
         * This program takes any number of arguments: the first is the name of the
         * desired stemming algorithm to use (a list is available in the package
         * description) , all of the rest should be the path or paths to a file or
         * files containing a stemmer table to compile.
         *
         * @param args the command line arguments
         */
        public static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                return;
            }

            args[0].ToUpperInvariant();

            backward = args[0][0] == '-';
            int  qq        = (backward) ? 1 : 0;
            bool storeorig = false;

            if (args[0][qq] == '0')
            {
                storeorig = true;
                qq++;
            }

            multi = args[0][qq] == 'M';
            if (multi)
            {
                qq++;
            }

            // LUCENENET TODO: Is this any different than Encoding.UTF8?
            //String charset = System.getProperty("egothor.stemmer.charset", "UTF-8");

            char[] optimizer = new char[args[0].Length - qq];
            for (int i = 0; i < optimizer.Length; i++)
            {
                optimizer[i] = args[0][qq + i];
            }

            for (int i = 1; i < args.Length; i++)
            {
                TextReader @in;
                // System.out.println("[" + args[i] + "]");
                Diff diff = new Diff();
                //int stems = 0; // not used
                int words = 0;


                AllocTrie();

                Console.WriteLine(args[i]);
                using (@in = new StreamReader(
                           new FileStream(args[i], FileMode.Open, FileAccess.Read), Encoding.UTF8))
                {
                    for (string line = @in.ReadLine(); line != null; line = @in.ReadLine())
                    {
                        try
                        {
                            line = line.ToLowerInvariant();
                            StringTokenizer st   = new StringTokenizer(line);
                            string          stem = st.NextToken();
                            if (storeorig)
                            {
                                trie.Add(stem, "-a");
                                words++;
                            }
                            while (st.HasMoreTokens())
                            {
                                string token = st.NextToken();
                                if (token.Equals(stem) == false)
                                {
                                    trie.Add(token, diff.Exec(token, stem));
                                    words++;
                                }
                            }
                        }
                        catch (InvalidOperationException /*x*/)
                        {
                            // no base token (stem) on a line
                        }
                    }
                }

                Optimizer  o  = new Optimizer();
                Optimizer2 o2 = new Optimizer2();
                Lift       l  = new Lift(true);
                Lift       e  = new Lift(false);
                Gener      g  = new Gener();

                for (int j = 0; j < optimizer.Length; j++)
                {
                    string prefix;
                    switch (optimizer[j])
                    {
                    case 'G':
                        trie   = trie.Reduce(g);
                        prefix = "G: ";
                        break;

                    case 'L':
                        trie   = trie.Reduce(l);
                        prefix = "L: ";
                        break;

                    case 'E':
                        trie   = trie.Reduce(e);
                        prefix = "E: ";
                        break;

                    case '2':
                        trie   = trie.Reduce(o2);
                        prefix = "2: ";
                        break;

                    case '1':
                        trie   = trie.Reduce(o);
                        prefix = "1: ";
                        break;

                    default:
                        continue;
                    }
                    trie.PrintInfo(System.Console.Out, prefix + " ");
                }

                using (DataOutputStream os = new DataOutputStream(
                           new FileStream(args[i] + ".out", FileMode.OpenOrCreate, FileAccess.Write)))
                {
                    os.WriteUTF(args[0]);
                    trie.Store(os);
                }
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Entry point to the Compile application.
        /// <para/>
        /// This program takes any number of arguments: the first is the name of the
        /// desired stemming algorithm to use (a list is available in the package
        /// description) , all of the rest should be the path or paths to a file or
        /// files containing a stemmer table to compile.
        /// </summary>
        /// <param name="args">the command line arguments</param>
        public static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                return;
            }

            // LUCENENET NOTE: This line does nothing in .NET
            // and also does nothing in Java...what?
            //args[0].ToUpperInvariant();

            // Reads the first char of the first arg
            backward = args[0][0] == '-';
            int  qq        = (backward) ? 1 : 0;
            bool storeorig = false;

            if (args[0][qq] == '0')
            {
                storeorig = true;
                qq++;
            }

            multi = args[0][qq] == 'M';
            if (multi)
            {
                qq++;
            }
            // LUCENENET specific - reformatted with :
            string charset       = SystemProperties.GetProperty("egothor:stemmer:charset", "UTF-8");
            var    stemmerTables = new List <string>();

            // LUCENENET specific
            // command line argument overrides environment variable or default, if supplied
            for (int i = 1; i < args.Length; i++)
            {
                if ("-e".Equals(args[i], StringComparison.Ordinal) || "--encoding".Equals(args[i], StringComparison.Ordinal))
                {
                    charset = args[i];
                }
                else
                {
                    stemmerTables.Add(args[i]);
                }
            }

            char[] optimizer = new char[args[0].Length - qq];
            for (int i = 0; i < optimizer.Length; i++)
            {
                optimizer[i] = args[0][qq + i];
            }

            foreach (var stemmerTable in stemmerTables)
            {
                // System.out.println("[" + args[i] + "]");
                Diff diff = new Diff();
                //int stems = 0; // not used
                int words = 0;


                AllocTrie();

                Console.WriteLine(stemmerTable);
                using (TextReader input = new StreamReader(
                           new FileStream(stemmerTable, FileMode.Open, FileAccess.Read), Encoding.GetEncoding(charset)))
                {
                    string line;
                    while ((line = input.ReadLine()) != null)
                    {
                        try
                        {
                            line = line.ToLowerInvariant();
                            StringTokenizer st = new StringTokenizer(line);
                            st.MoveNext();
                            string stem = st.Current;
                            if (storeorig)
                            {
                                trie.Add(stem, "-a");
                                words++;
                            }
                            while (st.MoveNext())
                            {
                                string token = st.Current;
                                if (token.Equals(stem, StringComparison.Ordinal) == false)
                                {
                                    trie.Add(token, diff.Exec(token, stem));
                                    words++;
                                }
                            }
                        }
                        catch (InvalidOperationException /*x*/)
                        {
                            // no base token (stem) on a line
                        }
                    }
                }

                Optimizer  o  = new Optimizer();
                Optimizer2 o2 = new Optimizer2();
                Lift       l  = new Lift(true);
                Lift       e  = new Lift(false);
                Gener      g  = new Gener();

                for (int j = 0; j < optimizer.Length; j++)
                {
                    string prefix;
                    switch (optimizer[j])
                    {
                    case 'G':
                        trie   = trie.Reduce(g);
                        prefix = "G: ";
                        break;

                    case 'L':
                        trie   = trie.Reduce(l);
                        prefix = "L: ";
                        break;

                    case 'E':
                        trie   = trie.Reduce(e);
                        prefix = "E: ";
                        break;

                    case '2':
                        trie   = trie.Reduce(o2);
                        prefix = "2: ";
                        break;

                    case '1':
                        trie   = trie.Reduce(o);
                        prefix = "1: ";
                        break;

                    default:
                        continue;
                    }
                    trie.PrintInfo(Console.Out, prefix + " ");
                }

                using (DataOutputStream os = new DataOutputStream(
                           new FileStream(stemmerTable + ".out", FileMode.OpenOrCreate, FileAccess.Write)))
                {
                    os.WriteUTF(args[0]);
                    trie.Store(os);
                }
            }
        }
Ejemplo n.º 25
0
 public override void ToOutputStream(DataOutputStream writer)
 {
     //To client
     writer.WriteUTF(ApplicationSettingsManager.Settings.DeviceName);
 }
Ejemplo n.º 26
0
        /// <summary>Computes and returns the value of SVUID.</summary>
        /// <returns>the serial version UID.</returns>
        /// <exception cref="IOException">if an I/O error occurs.</exception>
        protected internal virtual long ComputeSVUID()
        {
            // DontCheck(AbbreviationAsWordInName): can't be renamed (for backward binary compatibility).
            long svuid = 0;

            using (var byteArrayOutputStream = new MemoryStream())
            {
                using (var dataOutputStream = new DataOutputStream(byteArrayOutputStream.ToOutputStream()
                                                                   ))
                {
                    // 1. The class name written using UTF encoding.
                    dataOutputStream.WriteUTF(name.Replace('/', '.'));
                    // 2. The class modifiers written as a 32-bit integer.
                    var mods = access;
                    if (mods.HasFlagFast(AccessFlags.Interface))
                    {
                        mods = svuidMethods.Count == 0
                            ? mods & ~AccessFlags.Abstract
                            : mods
                               | AccessFlags.Abstract;
                    }
                    dataOutputStream.WriteInt((int)(mods & (AccessFlags.Public | AccessFlags.Final |
                                                            AccessFlags.Interface | AccessFlags.Abstract)));
                    // 3. The name of each interface sorted by name written using UTF encoding.
                    Array.Sort(interfaces);
                    foreach (var interfaceName in interfaces)
                    {
                        dataOutputStream.WriteUTF(interfaceName.Replace('/', '.'));
                    }
                    // 4. For each field of the class sorted by field name (except private static and private
                    // transient fields):
                    //   1. The name of the field in UTF encoding.
                    //   2. The modifiers of the field written as a 32-bit integer.
                    //   3. The descriptor of the field in UTF encoding.
                    // Note that field signatures are not dot separated. Method and constructor signatures are dot
                    // separated. Go figure...
                    WriteItems(svuidFields, dataOutputStream, false);
                    // 5. If a class initializer exists, write out the following:
                    //   1. The name of the method, <clinit>, in UTF encoding.
                    //   2. The modifier of the method, ACC_STATIC, written as a 32-bit integer.
                    //   3. The descriptor of the method, ()V, in UTF encoding.
                    if (hasStaticInitializer)
                    {
                        dataOutputStream.WriteUTF(Clinit);
                        dataOutputStream.WriteInt((int)AccessFlags.Static);
                        dataOutputStream.WriteUTF("()V");
                    }

                    // 6. For each non-private constructor sorted by method name and signature:
                    //   1. The name of the method, <init>, in UTF encoding.
                    //   2. The modifiers of the method written as a 32-bit integer.
                    //   3. The descriptor of the method in UTF encoding.
                    WriteItems(svuidConstructors, dataOutputStream, true);
                    // 7. For each non-private method sorted by method name and signature:
                    //   1. The name of the method in UTF encoding.
                    //   2. The modifiers of the method written as a 32-bit integer.
                    //   3. The descriptor of the method in UTF encoding.
                    WriteItems(svuidMethods, dataOutputStream, true);
                    dataOutputStream.Flush();
                    // 8. The SHA-1 algorithm is executed on the stream of bytes produced by DataOutputStream and
                    // produces five 32-bit values sha[0..4].
                    var hashBytes = ComputeSHAdigest(byteArrayOutputStream.ToArray());
                    // 9. The hash value is assembled from the first and second 32-bit values of the SHA-1 message
                    // digest. If the result of the message digest, the five 32-bit words H0 H1 H2 H3 H4, is in an
                    // array of five int values named sha, the hash value would be computed as follows:
                    for (var i = Math.Min(hashBytes.Length, 8) - 1; i >= 0; i--)
                    {
                        svuid = (svuid << 8) | (hashBytes[i] & 0xFF);
                    }
                }
            }

            return(svuid);
        }
 public void FileWriteString(string val)
 {
     OutputStream.WriteUTF(val);
 }
Ejemplo n.º 28
0
 private static void WriteJavaParameter(this DataOutputStream stream, MetadataJavaMethodParameter parameter)
 {
     stream.WriteUTF(parameter.Name);
     stream.WriteUTF(parameter.Type);
 }
Ejemplo n.º 29
0
 private static void WriteJarArchiveClass(this DataOutputStream stream, string name, MetadataJavaClass @class)
 {
     stream.WriteUTF(name);
     stream.WriteJarClass(@class);
 }
Ejemplo n.º 30
0
 /// <exception cref="System.IO.IOException"/>
 protected internal virtual void Save(DataOutputStream f)
 {
     f.WriteInt(num);
     f.WriteUTF(val);
     f.WriteUTF(tag);
 }