Class IOUtils
This class emulates the new Java 7 "Try-With-Resources" statement. Remove once Lucene is on Java 7.
Inheritance
Namespace: Lucene.Net.Util
Assembly: Lucene.Net.dll
Syntax
public sealed class IOUtils : object
Fields
| Improve this Doc View SourceCHARSET_UTF_8
UTF-8
Declaration
public static readonly Encoding CHARSET_UTF_8
Field Value
Type | Description |
---|---|
Encoding |
UTF_8
UTF-8 charset string.
Where possible, use
Declaration
public static readonly string UTF_8
Field Value
Type | Description |
---|---|
System.String |
Methods
| Improve this Doc View SourceClose(IDisposable[])
Disposes all given null
; they are
ignored. After everything is closed, the method either
throws the first exception it hit while closing, or
completes normally if there were no exceptions.
Declaration
public static void Close(params IDisposable[] objects)
Parameters
Type | Name | Description |
---|---|---|
IDisposable[] | objects | Objects to call |
Close(IEnumerable<IDisposable>)
Disposes all given
Declaration
public static void Close(IEnumerable<IDisposable> objects)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IDisposable> | objects |
See Also
| Improve this Doc View SourceCloseWhileHandlingException(Exception, IDisposable[])
Disposes all given IDisposable
s, suppressing all thrown exceptions. Some of the IDisposable
s
may be null
, they are ignored. After everything is disposed, method either throws priorException
,
if one is supplied, or the first of suppressed exceptions, or completes normally.
Sample usage:
IDisposable resource1 = null, resource2 = null, resource3 = null;
ExpectedException priorE = null;
try
{
resource1 = ...; resource2 = ...; resource3 = ...; // Acquisition may throw ExpectedException
..do..stuff.. // May throw ExpectedException
}
catch (ExpectedException e)
{
priorE = e;
}
finally
{
IOUtils.CloseWhileHandlingException(priorE, resource1, resource2, resource3);
}
Declaration
public static void CloseWhileHandlingException(Exception priorException, params IDisposable[] objects)
Parameters
Type | Name | Description |
---|---|---|
Exception | priorException |
|
IDisposable[] | objects | Objects to call |
CloseWhileHandlingException(Exception, IEnumerable<IDisposable>)
Disposes all given
Declaration
public static void CloseWhileHandlingException(Exception priorException, IEnumerable<IDisposable> objects)
Parameters
Type | Name | Description |
---|---|---|
Exception | priorException | |
IEnumerable<IDisposable> | objects |
See Also
| Improve this Doc View SourceCloseWhileHandlingException(IDisposable[])
Disposes all given null
, they are ignored.
Declaration
public static void CloseWhileHandlingException(params IDisposable[] objects)
Parameters
Type | Name | Description |
---|---|---|
IDisposable[] | objects | Objects to call |
CloseWhileHandlingException(IEnumerable<IDisposable>)
Disposes all given
Declaration
public static void CloseWhileHandlingException(IEnumerable<IDisposable> objects)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IDisposable> | objects |
See Also
Copy(FileInfo, FileInfo)
Copy one file's contents to another file. The target will be overwritten if it exists. The source must exist.
Declaration
public static void Copy(FileInfo source, FileInfo target)
Parameters
Type | Name | Description |
---|---|---|
FileInfo | source | |
FileInfo | target |
DeleteFilesIgnoringExceptions(Directory, String[])
Deletes all given files, suppressing all thrown
Note that the files should not be null
.
Declaration
public static void DeleteFilesIgnoringExceptions(Directory dir, params string[] files)
Parameters
Type | Name | Description |
---|---|---|
Directory | dir | |
System.String[] | files |
Dispose(IDisposable[])
Disposes all given null
; they are
ignored. After everything is closed, the method either
throws the first exception it hit while closing, or
completes normally if there were no exceptions.
Declaration
public static void Dispose(params IDisposable[] objects)
Parameters
Type | Name | Description |
---|---|---|
IDisposable[] | objects | Objects to call |
Dispose(IEnumerable<IDisposable>)
Disposes all given
Declaration
public static void Dispose(IEnumerable<IDisposable> objects)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IDisposable> | objects |
See Also
| Improve this Doc View SourceDisposeWhileHandlingException(Exception, IDisposable[])
Disposes all given IDisposable
s, suppressing all thrown exceptions. Some of the IDisposable
s
may be null
, they are ignored. After everything is disposed, method either throws priorException
,
if one is supplied, or the first of suppressed exceptions, or completes normally.
Sample usage:
IDisposable resource1 = null, resource2 = null, resource3 = null;
ExpectedException priorE = null;
try
{
resource1 = ...; resource2 = ...; resource3 = ...; // Acquisition may throw ExpectedException
..do..stuff.. // May throw ExpectedException
}
catch (ExpectedException e)
{
priorE = e;
}
finally
{
IOUtils.DisposeWhileHandlingException(priorE, resource1, resource2, resource3);
}
Declaration
public static void DisposeWhileHandlingException(Exception priorException, params IDisposable[] objects)
Parameters
Type | Name | Description |
---|---|---|
Exception | priorException |
|
IDisposable[] | objects | Objects to call |
DisposeWhileHandlingException(Exception, IEnumerable<IDisposable>)
Disposes all given
Declaration
public static void DisposeWhileHandlingException(Exception priorException, IEnumerable<IDisposable> objects)
Parameters
Type | Name | Description |
---|---|---|
Exception | priorException | |
IEnumerable<IDisposable> | objects |
See Also
| Improve this Doc View SourceDisposeWhileHandlingException(IDisposable[])
Disposes all given null
, they are ignored.
Declaration
public static void DisposeWhileHandlingException(params IDisposable[] objects)
Parameters
Type | Name | Description |
---|---|---|
IDisposable[] | objects | Objects to call |
DisposeWhileHandlingException(IEnumerable<IDisposable>)
Disposes all given
Declaration
public static void DisposeWhileHandlingException(IEnumerable<IDisposable> objects)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IDisposable> | objects |
See Also
| Improve this Doc View SourceGetDecodingReader(FileInfo, Encoding)
Opens a
Decoding readers are useful to load configuration files, stopword lists or synonym files to detect character set problems. However, its not recommended to use as a common purpose reader.
Declaration
public static TextReader GetDecodingReader(FileInfo file, Encoding charSet)
Parameters
Type | Name | Description |
---|---|---|
FileInfo | file | The file to open a reader on |
Encoding | charSet | The expected charset |
Returns
Type | Description |
---|---|
TextReader | A reader to read the given file |
GetDecodingReader(Stream, Encoding)
Wrapping the given
Decoding readers are useful to load configuration files, stopword lists or synonym files to detect character set problems. However, its not recommended to use as a common purpose reader.
Declaration
public static TextReader GetDecodingReader(Stream stream, Encoding charSet)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The stream to wrap in a reader |
Encoding | charSet | The expected charset |
Returns
Type | Description |
---|---|
TextReader | A wrapping reader |
GetDecodingReader(Type, String, Encoding)
Opens a
Decoding readers are useful to load configuration files, stopword lists or synonym files to detect character set problems. However, its not recommended to use as a common purpose reader.
Declaration
public static TextReader GetDecodingReader(Type clazz, string resource, Encoding charSet)
Parameters
Type | Name | Description |
---|---|---|
Type | clazz | The class used to locate the resource |
System.String | resource | The resource name to load |
Encoding | charSet | The expected charset |
Returns
Type | Description |
---|---|
TextReader | A reader to read the given file |
ReThrow(Exception)
Simple utilty method that takes a previously caught
null
then this method does nothing.
Declaration
public static void ReThrow(Exception th)
Parameters
Type | Name | Description |
---|---|---|
Exception | th |
ReThrowUnchecked(Exception)
Simple utilty method that takes a previously caught
null
then this method does nothing.
Declaration
public static void ReThrowUnchecked(Exception th)
Parameters
Type | Name | Description |
---|---|---|
Exception | th |