Esempio n. 1
0
            /// <exception cref="System.IO.IOException"/>
            private static void ReadContainerLogs(DataInputStream valueStream, TextWriter @out
                                                  , long logUploadedTime)
            {
                byte[] buf           = new byte[65535];
                string fileType      = valueStream.ReadUTF();
                string fileLengthStr = valueStream.ReadUTF();
                long   fileLength    = long.Parse(fileLengthStr);

                @out.Write("LogType:");
                @out.WriteLine(fileType);
                if (logUploadedTime != -1)
                {
                    @out.Write("Log Upload Time:");
                    @out.WriteLine(Times.Format(logUploadedTime));
                }
                @out.Write("LogLength:");
                @out.WriteLine(fileLengthStr);
                @out.WriteLine("Log Contents:");
                long curRead     = 0;
                long pendingRead = fileLength - curRead;
                int  toRead      = pendingRead > buf.Length ? buf.Length : (int)pendingRead;
                int  len         = valueStream.Read(buf, 0, toRead);

                while (len != -1 && curRead < fileLength)
                {
                    @out.Write(buf, 0, len);
                    curRead    += len;
                    pendingRead = fileLength - curRead;
                    toRead      = pendingRead > buf.Length ? buf.Length : (int)pendingRead;
                    len         = valueStream.Read(buf, 0, toRead);
                }
                @out.WriteLine("End of LogType:" + fileType);
                @out.WriteLine(string.Empty);
            }
Esempio n. 2
0
 /// <exception cref="System.IO.IOException"/>
 public virtual string NextLog()
 {
     if (currentLogData != null && currentLogLength > 0)
     {
         do
         {
             // seek to the end of the current log, relying on BoundedInputStream
             // to prevent seeking past the end of the current log
             if (currentLogData.Skip(currentLogLength) < 0)
             {
                 break;
             }
         }while (currentLogData.Read() != -1);
     }
     currentLogType   = null;
     currentLogLength = 0;
     currentLogData   = null;
     currentLogISR    = null;
     try
     {
         string logType      = valueStream.ReadUTF();
         string logLengthStr = valueStream.ReadUTF();
         currentLogLength = long.Parse(logLengthStr);
         currentLogData   = new BoundedInputStream(valueStream, currentLogLength);
         currentLogData.SetPropagateClose(false);
         currentLogISR = new InputStreamReader(currentLogData, Sharpen.Extensions.GetEncoding
                                                   ("UTF-8"));
         currentLogType = logType;
     }
     catch (EOFException)
     {
     }
     return(currentLogType);
 }
Esempio n. 3
0
        public override void FromInputStream(DataInputStream reader)
        {
            string receivedGuid = reader.ReadUTF().ToUpperInvariant();

            DeviceGuid = new Guid(receivedGuid);
            DeviceName = reader.ReadUTF();
        }
Esempio n. 4
0
 /// <exception cref="System.IO.IOException"/>
 protected internal virtual void Read(DataInputStream inf)
 {
     num = inf.ReadInt();
     // mg2008: slight speedup:
     val = inf.ReadUTF();
     // intern the tag strings as they are read, since there are few of them. This saves tons of memory.
     tag      = inf.ReadUTF();
     hashCode = 0;
 }
 public virtual void Read(DataInputStream @in)
 {
     try
     {
         word = @in.ReadUTF();
         tag  = @in.ReadUTF();
     }
     catch (Exception e)
     {
         Sharpen.Runtime.PrintStackTrace(e);
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Loads the rules from a DateInputStream, often in a jar file.
        /// </summary>
        /// <param name="dis">  the DateInputStream to load, not null </param>
        /// <exception cref="Exception"> if an error occurs </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void load(java.io.DataInputStream dis) throws Exception
        private void Load(DataInputStream dis)
        {
            if (dis.ReadByte() != 1)
            {
                throw new StreamCorruptedException("File format not recognised");
            }
            // group
            String groupId = dis.ReadUTF();

            if ("TZDB".Equals(groupId) == false)
            {
                throw new StreamCorruptedException("File format not recognised");
            }
            // versions
            int versionCount = dis.ReadShort();

            for (int i = 0; i < versionCount; i++)
            {
                VersionId = dis.ReadUTF();
            }
            // regions
            int regionCount = dis.ReadShort();

            String[] regionArray = new String[regionCount];
            for (int i = 0; i < regionCount; i++)
            {
                regionArray[i] = dis.ReadUTF();
            }
            RegionIds = Arrays.AsList(regionArray);
            // rules
            int ruleCount = dis.ReadShort();

            Object[] ruleArray = new Object[ruleCount];
            for (int i = 0; i < ruleCount; i++)
            {
                sbyte[] bytes = new sbyte[dis.ReadShort()];
                dis.ReadFully(bytes);
                ruleArray[i] = bytes;
            }
            // link version-region-rules
            for (int i = 0; i < versionCount; i++)
            {
                int versionRegionCount = dis.ReadShort();
                RegionToRules.Clear();
                for (int j = 0; j < versionRegionCount; j++)
                {
                    String region = regionArray[dis.ReadShort()];
                    Object rule   = ruleArray[dis.ReadShort() & 0xffff];
                    RegionToRules[region] = rule;
                }
            }
        }
Esempio n. 7
0
 /*
  * Reads the information from the index and data files.
  *
  * @param index holds the sprite indices
  * @param data  holds the sprite data per index
  * @throws IOException
  */
 public void readValues(DataInputStream index, DataInputStream data)
 {
     do
     {
         int opCode = data.ReadByte();
         if (opCode == 0)
         {
             break;
         }
         if (opCode == 1)
         {
             id = data.ReadShort();
         }
         else if (opCode == 2)
         {
             name = data.ReadUTF();
         }
         else if (opCode == 3)
         {
             drawOffsetX = data.ReadShort();
         }
         else if (opCode == 4)
         {
             drawOffsetY = data.ReadShort();
         }
         else if (opCode == 5)
         {
             int    indexLength = index.ReadInt();
             byte[] dataread    = new byte[indexLength];
             data.Read(dataread, 0, indexLength);
             spriteData = dataread;
         }
     } while (true);
 }
Esempio n. 8
0
 /// <summary>A TagCount object's fields are read from the file.</summary>
 /// <remarks>
 /// A TagCount object's fields are read from the file. They are read from
 /// the current position and the file is not closed afterwards.
 /// </remarks>
 public static Edu.Stanford.Nlp.Tagger.Maxent.TagCount ReadTagCount(DataInputStream rf)
 {
     try
     {
         Edu.Stanford.Nlp.Tagger.Maxent.TagCount tc = new Edu.Stanford.Nlp.Tagger.Maxent.TagCount();
         int numTags = rf.ReadInt();
         tc.map = Generics.NewHashMap(numTags);
         for (int i = 0; i < numTags; i++)
         {
             string tag   = rf.ReadUTF();
             int    count = rf.ReadInt();
             if (tag.Equals(NullSymbol))
             {
                 tag = null;
             }
             tc.map[tag] = count;
         }
         tc.getTagsCache = Sharpen.Collections.ToArray(tc.map.Keys, new string[tc.map.Keys.Count]);
         tc.sumCache     = tc.CalculateSumCache();
         return(tc);
     }
     catch (IOException e)
     {
         throw new RuntimeIOException(e);
     }
 }
Esempio n. 9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static String[] readStringArray(java.io.DataInputStream dis, int count) throws java.io.IOException
        private static String[] ReadStringArray(DataInputStream dis, int count)
        {
            String[] ret = new String[count];
            for (int i = 0; i < count; i++)
            {
                ret[i] = dis.ReadUTF();
            }

            return(ret);
        }
Esempio n. 10
0
            /// <summary>Returns ACLs for the application.</summary>
            /// <remarks>
            /// Returns ACLs for the application. An empty map is returned if no ACLs are
            /// found.
            /// </remarks>
            /// <returns>a map of the Application ACLs.</returns>
            /// <exception cref="System.IO.IOException"/>
            public virtual IDictionary <ApplicationAccessType, string> GetApplicationAcls()
            {
                // TODO Seek directly to the key once a comparator is specified.
                TFile.Reader.Scanner       aclScanner            = reader.CreateScanner();
                AggregatedLogFormat.LogKey key                   = new AggregatedLogFormat.LogKey();
                IDictionary <ApplicationAccessType, string> acls = new Dictionary <ApplicationAccessType
                                                                                   , string>();

                while (!aclScanner.AtEnd())
                {
                    TFile.Reader.Scanner.Entry entry = aclScanner.Entry();
                    key.ReadFields(entry.GetKeyStream());
                    if (key.ToString().Equals(ApplicationAclKey.ToString()))
                    {
                        DataInputStream valueStream = entry.GetValueStream();
                        while (true)
                        {
                            string appAccessOp = null;
                            string aclString   = null;
                            try
                            {
                                appAccessOp = valueStream.ReadUTF();
                            }
                            catch (EOFException)
                            {
                                // Valid end of stream.
                                break;
                            }
                            try
                            {
                                aclString = valueStream.ReadUTF();
                            }
                            catch (EOFException e)
                            {
                                throw new YarnRuntimeException("Error reading ACLs", e);
                            }
                            acls[ApplicationAccessType.ValueOf(appAccessOp)] = aclString;
                        }
                    }
                    aclScanner.Advance();
                }
                return(acls);
            }
Esempio n. 11
0
 public override void FromInputStream(DataInputStream reader)
 {
     ProtocolVersion = reader.ReadInt();
     HasDeviceGuid   = reader.ReadBoolean();
     if (HasDeviceGuid)
     {
         //We have a device GUID
         DeviceGuid = Guid.Parse(reader.ReadUTF().ToUpper());
     }
 }
Esempio n. 12
0
        /// <exception cref="System.IO.IOException"/>
        private string ReadModifiedUTF(byte[] bytes)
        {
            short      lengthBytes = (short)2;
            ByteBuffer bb          = ByteBuffer.Allocate(bytes.Length + lengthBytes);

            bb.PutShort((short)bytes.Length).Put(bytes);
            ByteArrayInputStream bis = new ByteArrayInputStream(((byte[])bb.Array()));
            DataInputStream      dis = new DataInputStream(bis);

            return(dis.ReadUTF());
        }
Esempio n. 13
0
 /// <summary>Returns the owner of the application.</summary>
 /// <returns>the application owner.</returns>
 /// <exception cref="System.IO.IOException"/>
 public virtual string GetApplicationOwner()
 {
     TFile.Reader.Scanner       ownerScanner = reader.CreateScanner();
     AggregatedLogFormat.LogKey key          = new AggregatedLogFormat.LogKey();
     while (!ownerScanner.AtEnd())
     {
         TFile.Reader.Scanner.Entry entry = ownerScanner.Entry();
         key.ReadFields(entry.GetKeyStream());
         if (key.ToString().Equals(ApplicationOwnerKey.ToString()))
         {
             DataInputStream valueStream = entry.GetValueStream();
             return(valueStream.ReadUTF());
         }
         ownerScanner.Advance();
     }
     return(null);
 }
Esempio n. 14
0
        /// <exception cref="System.IO.IOException"/>
        private void ReadTags(DataInputStream rf)
        {
            // Object[] arr=dict.keySet().toArray();
            int maxNumTags = 0;
            int len        = rf.ReadInt();

            for (int i = 0; i < len; i++)
            {
                string   word    = rf.ReadUTF();
                TagCount count   = TagCount.ReadTagCount(rf);
                int      numTags = count.NumTags();
                if (numTags > maxNumTags)
                {
                    maxNumTags = numTags;
                }
                this.dict[word] = count;
            }
        }
Esempio n. 15
0
        internal static Trie LoadTrie(string path)
        {
            Trie trie;

            using (DataInputStream @is = new DataInputStream(
                       new FileStream(path, FileMode.Open, FileAccess.Read)))
            {
                string method = @is.ReadUTF().ToUpperInvariant();
                if (method.IndexOf('M') < 0)
                {
                    trie = new Trie(@is);
                }
                else
                {
                    trie = new MultiTrie(@is);
                }
            }
            return(trie);
        }
Esempio n. 16
0
 protected internal virtual void Read(DataInputStream file)
 {
     try
     {
         int size = file.ReadInt();
         index = new HashIndex <string>();
         for (int i = 0; i < size; i++)
         {
             string tag      = file.ReadUTF();
             bool   inClosed = file.ReadBoolean();
             index.Add(tag);
             if (inClosed)
             {
                 closed.Add(tag);
             }
         }
     }
     catch (IOException e)
     {
         Sharpen.Runtime.PrintStackTrace(e);
     }
 }
Esempio n. 17
0
        /// <summary>
        /// Load a stemmer table from an inputstream.
        /// </summary>
        public static Trie Load(Stream stemmerTable)
        {
            DataInputStream @in = null;

            try
            {
                @in = new DataInputStream(stemmerTable);
                string method = @in.ReadUTF().ToUpperInvariant();
                if (method.IndexOf('M') < 0)
                {
                    return(new Trie(@in));
                }
                else
                {
                    return(new MultiTrie2(@in));
                }
            }
            finally
            {
                @in.Dispose();
            }
        }
Esempio n. 18
0
        private void ReadFromDisk(System.IO.IsolatedStorage.IsolatedStorageFile iso, string storeFile)
        {
            DataInputStream dis = FileUtils.ReadIsolatedStorageFileToDataInput(iso, storeFile);

            try
            {
                string header = dis.ReadUTF();
                if (!header.Equals(HEADER))
                {
                    throw new RecordStoreException("Store file header mismatch: " + header);
                }
                nextRecordId = dis.ReadInt();
                int size = dis.ReadInt();
                records.Clear();
                for (int i = 0; i < size; i++)
                {
                    long   pSize  = dis.ReadLong();
                    int    pId    = dis.ReadInt();
                    byte[] buffer = new byte[pSize];
                    dis.Read(buffer);
                    RecordItem ri = new RecordItem(pId, buffer);
                    records.Add(ri);
                }
            }
            catch (Exception e)
            {
                throw new RecordStoreException("ERROR reading store from disk (" + storeFile + "): " + e.StackTrace);
            }
            finally
            {
                if (dis != null)
                {
                    dis.Close();
                    dis = null;
                }
            }
        }
 public string FileReadString()
 {
     return(InputStream.ReadUTF());
 }
Esempio n. 20
0
 public static string ReadUtfAndIntern(this DataInputStream stream)
 {
     return(string.Intern(stream.ReadUTF()));
 }
Esempio n. 21
0
        /// <exception cref="IOException"/>
        public ConstantPool(DataInputStream @in)
        {
            int size = @in.ReadUnsignedShort();

            pool = new List <PooledConstant>(size);
            BitSet[] nextPass = new BitSet[] { new BitSet(size), new BitSet(size), new BitSet
                                                   (size) };
            // first dummy constant
            pool.Add(null);
            // first pass: read the elements
            for (int i = 1; i < size; i++)
            {
                byte tag = unchecked ((byte)@in.ReadUnsignedByte());
                switch (tag)
                {
                case ICodeConstants.CONSTANT_Utf8:
                {
                    pool.Add(new PrimitiveConstant(ICodeConstants.CONSTANT_Utf8, @in.ReadUTF()));
                    break;
                }

                case ICodeConstants.CONSTANT_Integer:
                {
                    pool.Add(new PrimitiveConstant(ICodeConstants.CONSTANT_Integer, (@in.ReadInt
                                                                                         ())));
                    break;
                }

                case ICodeConstants.CONSTANT_Float:
                {
                    pool.Add(new PrimitiveConstant(ICodeConstants.CONSTANT_Float, @in.ReadFloat()));
                    break;
                }

                case ICodeConstants.CONSTANT_Long:
                {
                    pool.Add(new PrimitiveConstant(ICodeConstants.CONSTANT_Long, @in.ReadLong()));
                    pool.Add(null);
                    i++;
                    break;
                }

                case ICodeConstants.CONSTANT_Double:
                {
                    pool.Add(new PrimitiveConstant(ICodeConstants.CONSTANT_Double, @in.ReadDouble()));
                    pool.Add(null);
                    i++;
                    break;
                }

                case ICodeConstants.CONSTANT_Class:
                case ICodeConstants.CONSTANT_String:
                case ICodeConstants.CONSTANT_MethodType:
                {
                    pool.Add(new PrimitiveConstant(tag, @in.ReadUnsignedShort()));
                    nextPass[0].Set(i);
                    break;
                }

                case ICodeConstants.CONSTANT_NameAndType:
                {
                    pool.Add(new LinkConstant(tag, @in.ReadUnsignedShort(), @in.ReadUnsignedShort()));
                    nextPass[0].Set(i);
                    break;
                }

                case ICodeConstants.CONSTANT_Fieldref:
                case ICodeConstants.CONSTANT_Methodref:
                case ICodeConstants.CONSTANT_InterfaceMethodref:
                case ICodeConstants.CONSTANT_InvokeDynamic:
                {
                    pool.Add(new LinkConstant(tag, @in.ReadUnsignedShort(), @in.ReadUnsignedShort()));
                    nextPass[1].Set(i);
                    break;
                }

                case ICodeConstants.CONSTANT_MethodHandle:
                {
                    pool.Add(new LinkConstant(tag, @in.ReadUnsignedByte(), @in.ReadUnsignedShort()));
                    nextPass[2].Set(i);
                    break;
                }
                }
            }
            // resolving complex pool elements
            foreach (BitSet pass in nextPass)
            {
                int idx = 0;
                while ((idx = pass.NextSetBit(idx + 1)) > 0)
                {
                    pool[idx].ResolveConstant(this);
                }
            }
            // get global constant pool interceptor instance, if any available
            interceptor = DecompilerContext.GetPoolInterceptor();
        }