Show / Hide Table of Contents

    Class IOUtils

    This class emulates the new Java 7 "Try-With-Resources" statement. Remove once Lucene is on Java 7.

    This is a Lucene.NET INTERNAL API, use at your own risk
    Inheritance
    System.Object
    IOUtils
    Namespace: Lucene.Net.Util
    Assembly: Lucene.Net.dll
    Syntax
    public sealed class IOUtils : object

    Fields

    | Improve this Doc View Source

    CHARSET_UTF_8

    UTF-8 instance to prevent repeated lookups

    Declaration
    public static readonly Encoding CHARSET_UTF_8
    Field Value
    Type Description
    Encoding
    | Improve this Doc View Source

    UTF_8

    UTF-8 charset string.

    Where possible, use instead, as using the constant may slow things down.

    Declaration
    public static readonly string UTF_8
    Field Value
    Type Description
    System.String

    Methods

    | Improve this Doc View Source

    Close(IDisposable[])

    Disposes all given s. Some of the s may be 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 on

    | Improve this Doc View Source

    Close(IEnumerable<IDisposable>)

    Disposes all given s.

    Declaration
    public static void Close(IEnumerable<IDisposable> objects)
    Parameters
    Type Name Description
    IEnumerable<IDisposable> objects
    See Also
    Dispose(IDisposable[])
    | Improve this Doc View Source

    CloseWhileHandlingException(Exception, IDisposable[])

    Disposes all given IDisposables, suppressing all thrown exceptions. Some of the IDisposables 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

    null or an exception that will be rethrown after method completion.

    IDisposable[] objects

    Objects to call on.

    | Improve this Doc View Source

    CloseWhileHandlingException(Exception, IEnumerable<IDisposable>)

    Disposes all given s, suppressing all thrown exceptions.

    Declaration
    public static void CloseWhileHandlingException(Exception priorException, IEnumerable<IDisposable> objects)
    Parameters
    Type Name Description
    Exception priorException
    IEnumerable<IDisposable> objects
    See Also
    DisposeWhileHandlingException(Exception, IDisposable[])
    | Improve this Doc View Source

    CloseWhileHandlingException(IDisposable[])

    Disposes all given s, suppressing all thrown exceptions. Some of the s may be null, they are ignored.

    Declaration
    public static void CloseWhileHandlingException(params IDisposable[] objects)
    Parameters
    Type Name Description
    IDisposable[] objects

    Objects to call on

    | Improve this Doc View Source

    CloseWhileHandlingException(IEnumerable<IDisposable>)

    Disposes all given s, suppressing all thrown exceptions.

    Declaration
    public static void CloseWhileHandlingException(IEnumerable<IDisposable> objects)
    Parameters
    Type Name Description
    IEnumerable<IDisposable> objects
    See Also
    DisposeWhileHandlingException(IEnumerable<IDisposable>)
    DisposeWhileHandlingException(IDisposable[])
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    DeleteFilesIgnoringExceptions(Directory, String[])

    Deletes all given files, suppressing all thrown s.

    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
    | Improve this Doc View Source

    Dispose(IDisposable[])

    Disposes all given s. Some of the s may be 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 on

    | Improve this Doc View Source

    Dispose(IEnumerable<IDisposable>)

    Disposes all given s.

    Declaration
    public static void Dispose(IEnumerable<IDisposable> objects)
    Parameters
    Type Name Description
    IEnumerable<IDisposable> objects
    See Also
    Dispose(IDisposable[])
    | Improve this Doc View Source

    DisposeWhileHandlingException(Exception, IDisposable[])

    Disposes all given IDisposables, suppressing all thrown exceptions. Some of the IDisposables 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

    null or an exception that will be rethrown after method completion.

    IDisposable[] objects

    Objects to call on.

    | Improve this Doc View Source

    DisposeWhileHandlingException(Exception, IEnumerable<IDisposable>)

    Disposes all given s, suppressing all thrown exceptions.

    Declaration
    public static void DisposeWhileHandlingException(Exception priorException, IEnumerable<IDisposable> objects)
    Parameters
    Type Name Description
    Exception priorException
    IEnumerable<IDisposable> objects
    See Also
    DisposeWhileHandlingException(Exception, IDisposable[])
    | Improve this Doc View Source

    DisposeWhileHandlingException(IDisposable[])

    Disposes all given s, suppressing all thrown exceptions. Some of the s may be null, they are ignored.

    Declaration
    public static void DisposeWhileHandlingException(params IDisposable[] objects)
    Parameters
    Type Name Description
    IDisposable[] objects

    Objects to call on

    | Improve this Doc View Source

    DisposeWhileHandlingException(IEnumerable<IDisposable>)

    Disposes all given s, suppressing all thrown exceptions.

    Declaration
    public static void DisposeWhileHandlingException(IEnumerable<IDisposable> objects)
    Parameters
    Type Name Description
    IEnumerable<IDisposable> objects
    See Also
    DisposeWhileHandlingException(IDisposable[])
    | Improve this Doc View Source

    GetDecodingReader(FileInfo, Encoding)

    Opens a for the given using a . Unlike Java's defaults this reader will throw an exception if your it detects the read charset doesn't match the expected .

    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

    | Improve this Doc View Source

    GetDecodingReader(Stream, Encoding)

    Wrapping the given in a reader using a . Unlike Java's defaults this reader will throw an exception if your it detects the read charset doesn't match the expected .

    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

    | Improve this Doc View Source

    GetDecodingReader(Type, String, Encoding)

    Opens a for the given resource using a . Unlike Java's defaults this reader will throw an exception if your it detects the read charset doesn't match the expected .

    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

    | Improve this Doc View Source

    ReThrow(Exception)

    Simple utilty method that takes a previously caught and rethrows either or an unchecked exception. If the argument is null then this method does nothing.

    Declaration
    public static void ReThrow(Exception th)
    Parameters
    Type Name Description
    Exception th
    | Improve this Doc View Source

    ReThrowUnchecked(Exception)

    Simple utilty method that takes a previously caught and rethrows it as an unchecked exception. If the argument is null then this method does nothing.

    Declaration
    public static void ReThrowUnchecked(Exception th)
    Parameters
    Type Name Description
    Exception th
    • Improve this Doc
    • View Source
    Back to top Copyright © 2020 Licensed to the Apache Software Foundation (ASF)