public override void close() { _fileMutex.WaitOne(); try { _indexInput.close(); _indexInput = null; _azureDirectory = null; _blobContainer = null; _blob = null; GC.SuppressFinalize(this); } finally { _fileMutex.ReleaseMutex(); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: @Override public void close() throws java.io.IOException public override void close() { data.close(); }
public static void Main(string[] args) { string filename = null; bool extract = false; string dirImpl = null; int j = 0; while (j < args.Length) { string arg = args[j]; if ("-extract".Equals(arg)) { extract = true; } else if ("-dir-impl".Equals(arg)) { if (j == args.Length - 1) { Console.WriteLine("ERROR: missing value for -dir-impl option"); Environment.Exit(1); } j++; dirImpl = args[j]; } else if (filename == null) { filename = arg; } j++; } if (filename == null) { Console.WriteLine("Usage: org.apache.lucene.index.CompoundFileExtractor [-extract] [-dir-impl X] <cfsfile>"); return; } Directory dir = null; CompoundFileDirectory cfr = null; IOContext context = IOContext.READ; try { File file = new File(filename); string dirname = file.AbsoluteFile.Parent; filename = file.Name; if (dirImpl == null) { dir = FSDirectory.open(new File(dirname)); } else { dir = CommandLineUtil.newFSDirectory(dirImpl, new File(dirname)); } cfr = new CompoundFileDirectory(dir, filename, IOContext.DEFAULT, false); string[] files = cfr.listAll(); ArrayUtil.timSort(files); // sort the array of filename so that the output is more readable for (int i = 0; i < files.Length; ++i) { long len = cfr.fileLength(files[i]); if (extract) { Console.WriteLine("extract " + files[i] + " with " + len + " bytes to local directory..."); IndexInput ii = cfr.openInput(files[i], context); FileOutputStream f = new FileOutputStream(files[i]); // read and write with a small buffer, which is more effective than reading byte by byte sbyte[] buffer = new sbyte[1024]; int chunk = buffer.Length; while (len > 0) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int bufLen = (int) Math.min(chunk, len); int bufLen = (int)Math.Min(chunk, len); ii.readBytes(buffer, 0, bufLen); f.write(buffer, 0, bufLen); len -= bufLen; } f.close(); ii.close(); } else { Console.WriteLine(files[i] + ": " + len + " bytes"); } } } catch (IOException ioe) { Console.WriteLine(ioe.ToString()); Console.Write(ioe.StackTrace); } finally { try { if (dir != null) { dir.close(); } if (cfr != null) { cfr.close(); } } catch (IOException ioe) { Console.WriteLine(ioe.ToString()); Console.Write(ioe.StackTrace); } } }