public void TestReadFully() { const string READFULLY_TEST_FILE = "Lucene.Net.Tests.core.Support.ReadFully.txt"; byte[] buffer = new byte[1367]; Stream @in = GetType().Assembly.GetManifestResourceStream(READFULLY_TEST_FILE); DataInputStream dis; using (dis = new DataInputStream(@in)) { // Read once for real dis.ReadFully(buffer, 0, 1366); } // Read past the end of the stream @in = GetType().Assembly.GetManifestResourceStream(READFULLY_TEST_FILE); dis = new DataInputStream(@in); bool caughtException = false; try { dis.ReadFully(buffer, 0, buffer.Length); } #pragma warning disable 168 catch (EndOfStreamException ie) #pragma warning restore 168 { caughtException = true; } finally { dis.Dispose(); if (!caughtException) fail("Test failed"); } // Ensure we get an IndexOutOfRangeException exception when length is negative @in = GetType().Assembly.GetManifestResourceStream(READFULLY_TEST_FILE); dis = new DataInputStream(@in); caughtException = false; try { dis.ReadFully(buffer, 0, -20); } #pragma warning disable 168 catch (IndexOutOfRangeException ie) #pragma warning restore 168 { caughtException = true; } finally { dis.Dispose(); if (!caughtException) fail("Test failed"); } }
/// <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(); } }
public void TestReadFully() { const string READFULLY_TEST_FILE = "Lucene.Net.Tests.core.Support.ReadFully.txt"; byte[] buffer = new byte[1367]; Stream @in = GetType().Assembly.GetManifestResourceStream(READFULLY_TEST_FILE); DataInputStream dis; using (dis = new DataInputStream(@in)) { // Read once for real dis.ReadFully(buffer, 0, 1366); } // Read past the end of the stream @in = GetType().Assembly.GetManifestResourceStream(READFULLY_TEST_FILE); dis = new DataInputStream(@in); bool caughtException = false; try { dis.ReadFully(buffer, 0, buffer.Length); } #pragma warning disable 168 catch (EndOfStreamException ie) #pragma warning restore 168 { caughtException = true; } finally { dis.Dispose(); if (!caughtException) { fail("Test failed"); } } // Ensure we get an IndexOutOfRangeException exception when length is negative @in = GetType().Assembly.GetManifestResourceStream(READFULLY_TEST_FILE); dis = new DataInputStream(@in); caughtException = false; try { dis.ReadFully(buffer, 0, -20); } #pragma warning disable 168 catch (IndexOutOfRangeException ie) #pragma warning restore 168 { caughtException = true; } finally { dis.Dispose(); if (!caughtException) { fail("Test failed"); } } }