Skip to content

Commit

Permalink
close -> dispose on steams
Browse files Browse the repository at this point in the history
  • Loading branch information
richorama committed Nov 26, 2013
1 parent a6a02b4 commit de25238
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 43 deletions.
17 changes: 6 additions & 11 deletions AzureDirectory/StreamInput.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}
}
Expand Down
11 changes: 3 additions & 8 deletions AzureDirectory/StreamOutput.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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;
}
Expand All @@ -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();
}
}
Expand Down
34 changes: 10 additions & 24 deletions TestApp/Program.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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)
Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -126,8 +115,6 @@ public AutoStopWatch(string message)
_stopwatch = Stopwatch.StartNew();
}


#region IDisposable Members
public void Dispose()
{

Expand All @@ -136,7 +123,6 @@ public void Dispose()

Debug.WriteLine(String.Format("{0} Finished {1} ms", _message, ms));
}
#endregion
}


Expand Down

0 comments on commit de25238

Please sign in to comment.