Skip to content
Permalink
Browse files
Close the InputStream properly
  • Loading branch information
elecharny committed Dec 24, 2020
1 parent 75c9ab8 commit f7944a823e6abf6116b2c6be5b6439c29afb5842
Showing 2 changed files with 11 additions and 1 deletion.
@@ -158,6 +158,7 @@ public class LdifAttributesReader extends LdifReader
*/
public LdifAttributesReader()
{
super();
lines = new ArrayList<String>();
position = 0;
version = DEFAULT_VERSION;
@@ -216,6 +216,9 @@ public class LdifReader implements Iterable<LdifEntry>, Closeable

/** The ldif Reader */
protected Reader reader;

/** The internal inputStream */
private InputStream is;

/** A flag set if the ldif contains entries */
protected boolean containsEntries;
@@ -351,7 +354,7 @@ public LdifReader( File file, SchemaManager schemaManager ) throws LdapLdifExcep

try
{
InputStream is = Files.newInputStream( Paths.get( file.getPath() ) );
is = Files.newInputStream( Paths.get( file.getPath() ) );
initReader(
new BufferedReader( new InputStreamReader( is, Charset.defaultCharset() ) ) );
}
@@ -2232,6 +2235,12 @@ public void close() throws IOException
offset = 0;
entryOffset = 0;
lineNumber = 0;

// Close the inner inputStream if needed
if ( is != null )
{
is.close();
}
}
}
}

0 comments on commit f7944a8

Please sign in to comment.