ReadUTF() публичный Метод

public ReadUTF ( ) : string
Результат string
Пример #1
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();
     }
 }
        private static void WriteAndReadAString()
        {
            // Write out a string whose UTF-8 encoding is quite possibly
            // longer than 65535 bytes
            int           length     = Random().nextInt(A_NUMBER_NEAR_65535) + 1;
            MemoryStream  baos       = new MemoryStream();
            StringBuilder testBuffer = new StringBuilder();

            for (int i = 0; i < length; i++)
            {
                testBuffer.append((char)Random().Next());
            }
            string           testString = testBuffer.toString();
            DataOutputStream dos        = new DataOutputStream(baos);

            dos.WriteUTF(testString);

            // Corrupt the data to produce malformed characters
            byte[] testBytes   = baos.ToArray();
            int    dataLength  = testBytes.Length;
            int    corruptions = Random().nextInt(MAX_CORRUPTIONS_PER_CYCLE);

            for (int i = 0; i < corruptions; i++)
            {
                int index = Random().nextInt(dataLength);
                testBytes[index] = (byte)Random().Next();
            }

            // Pay special attention to mangling the end to produce
            // partial characters at end
            testBytes[dataLength - 1] = (byte)Random().Next();
            testBytes[dataLength - 2] = (byte)Random().Next();

            // Attempt to decode the bytes back into a String
            MemoryStream    bais = new MemoryStream(testBytes);
            DataInputStream dis  = new DataInputStream(bais);

            dis.ReadUTF();
        }
        private static void WriteAndReadAString()
        {
            // Write out a string whose UTF-8 encoding is quite possibly
            // longer than 65535 bytes
            int length = Random().nextInt(A_NUMBER_NEAR_65535) + 1;
            MemoryStream baos = new MemoryStream();
            StringBuilder testBuffer = new StringBuilder();
            for (int i = 0; i < length; i++)
                testBuffer.append((char)Random().Next());
            string testString = testBuffer.toString();
            DataOutputStream dos = new DataOutputStream(baos);
            dos.WriteUTF(testString);

            // Corrupt the data to produce malformed characters
            byte[] testBytes = baos.ToArray();
            int dataLength = testBytes.Length;
            int corruptions = Random().nextInt(MAX_CORRUPTIONS_PER_CYCLE);
            for (int i = 0; i < corruptions; i++)
            {
                int index = Random().nextInt(dataLength);
                testBytes[index] = (byte)Random().Next();
            }

            // Pay special attention to mangling the end to produce
            // partial characters at end
            testBytes[dataLength - 1] = (byte)Random().Next();
            testBytes[dataLength - 2] = (byte)Random().Next();

            // Attempt to decode the bytes back into a String
            MemoryStream bais = new MemoryStream(testBytes);
            DataInputStream dis = new DataInputStream(bais);
            dis.ReadUTF();
        }
Пример #4
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;
 }