Permalink
Browse files

close -> dispose on steams

  • Loading branch information...
1 parent a6a02b4 commit de25238cf9d7bc0cefeb9fa8994a4562a82302e6 @richorama richorama committed Nov 26, 2013
Showing with 19 additions and 43 deletions.
  1. +6 −11 AzureDirectory/StreamInput.cs
  2. +3 −8 AzureDirectory/StreamOutput.cs
  3. +10 −24 TestApp/Program.cs
@@ -1,10 +1,5 @@
-// License: Microsoft Public License (Ms-PL)
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+using System;
using System.IO;
-using Lucene.Net.Store;
namespace Lucene.Net.Store.Azure
{
@@ -34,10 +29,10 @@ public override long Position
public override int Read(byte[] buffer, int offset, int count)
{
- long pos = Input.FilePointer;
+ var pos = Input.FilePointer;
try
{
- long len = Input.Length();
+ var len = Input.Length();
if (count > (len - pos))
count = (int)(len - pos);
Input.ReadBytes(buffer, offset, count);
@@ -64,17 +59,17 @@ public override long Seek(long offset, SeekOrigin origin)
public override void SetLength(long value)
{
- throw new System.NotImplementedException();
+ throw new NotImplementedException();
}
public override void Write(byte[] buffer, int offset, int count)
{
- throw new System.NotImplementedException();
+ throw new NotImplementedException();
}
public override void Close()
{
- Input.Close();
+ Input.Dispose();
base.Close();
}
}
@@ -1,10 +1,5 @@
-// License: Microsoft Public License (Ms-PL)
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+using System;
using System.IO;
-using Lucene.Net.Store;
namespace Lucene.Net.Store.Azure
{
@@ -73,7 +68,7 @@ public override long Seek(long offset, SeekOrigin origin)
Output.Seek(Output.FilePointer + offset);
break;
case SeekOrigin.End:
- throw new System.NotImplementedException();
+ throw new NotImplementedException();
}
return Output.FilePointer;
}
@@ -91,7 +86,7 @@ public override void Write(byte[] buffer, int offset, int count)
public override void Close()
{
Output.Flush();
- Output.Close();
+ Output.Dispose();
base.Close();
}
}
View
@@ -1,22 +1,13 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading;
-using Microsoft.WindowsAzure;
-using Lucene.Net;
-using Lucene.Net.Store;
-using Lucene.Net.Index;
+using Lucene.Net.Analysis.Standard;
using Lucene.Net.Documents;
-using Lucene.Net.Util;
-using Lucene.Net.Analysis;
-using Lucene.Net.Analysis.Standard;
+using Lucene.Net.Index;
using Lucene.Net.Search;
-using Lucene.Net.QueryParsers;
-using System.Diagnostics;
-using System.ComponentModel;
+using Lucene.Net.Store;
using Lucene.Net.Store.Azure;
using Microsoft.WindowsAzure.Storage;
+using System;
+using System.Diagnostics;
+using System.Text;
namespace TestApp
{
@@ -28,8 +19,8 @@ static void Main(string[] args)
{
// default AzureDirectory stores cache in local temp folder
- AzureDirectory azureDirectory = new AzureDirectory(CloudStorageAccount.DevelopmentStorageAccount, "TestCatalog6");
- bool findexExists = IndexReader.IndexExists(azureDirectory);
+ var azureDirectory = new AzureDirectory(CloudStorageAccount.DevelopmentStorageAccount, "TestCatalog6");
+ var findexExists = IndexReader.IndexExists(azureDirectory);
IndexWriter indexWriter = null;
while (indexWriter == null)
@@ -55,7 +46,7 @@ static void Main(string[] args)
{
if (iDoc % 10 == 0)
Console.WriteLine(iDoc);
- Document doc = new Document();
+ var doc = new Document();
doc.Add(new Field("id", DateTime.Now.ToFileTimeUtc().ToString(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO));
doc.Add(new Field("Title", GeneratePhrase(10), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO));
doc.Add(new Field("Body", GeneratePhrase(40), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO));
@@ -85,9 +76,7 @@ static void SearchForPhrase(IndexSearcher searcher, string phrase)
var hits = searcher.Search(query, 100);
Console.WriteLine("Found {0} results for {1}", hits.TotalHits, phrase);
- int max = hits.TotalHits;
- if (max > 100)
- max = 100;
+ int max = Math.Min(hits.TotalHits,100);
for (int i = 0; i < max; i++)
{
Console.WriteLine(hits.ScoreDocs[i].Doc);
@@ -126,8 +115,6 @@ public AutoStopWatch(string message)
_stopwatch = Stopwatch.StartNew();
}
-
- #region IDisposable Members
public void Dispose()
{
@@ -136,7 +123,6 @@ public void Dispose()
Debug.WriteLine(String.Format("{0} Finished {1} ms", _message, ms));
}
- #endregion
}

0 comments on commit de25238

Please sign in to comment.