Skip to content
Permalink
Browse files
Using try-with-resources to properly close input streams
  • Loading branch information
elecharny committed Dec 24, 2020
1 parent ee02049 commit 75c9ab87625f8330c973c35ed60357bbc83ed7c8
Showing 3 changed files with 136 additions and 110 deletions.
@@ -183,11 +183,14 @@ public List<Entry> loadComparators( Schema... schemas ) throws LdapException, IO
if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) )
{
URL resource = getResource( resourcePath, "comparator LDIF file" );
LdifReader reader = new LdifReader( resource.openStream() );
LdifEntry entry = reader.next();
reader.close();

comparatorList.add( entry.getEntry() );

try ( InputStream in = resource.openStream();
LdifReader reader = new LdifReader( in ) )
{
LdifEntry entry = reader.next();

comparatorList.add( entry.getEntry() );
}
}
}
}
@@ -220,11 +223,13 @@ public List<Entry> loadSyntaxCheckers( Schema... schemas ) throws LdapException,
if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) )
{
URL resource = getResource( resourcePath, "syntaxChecker LDIF file" );
LdifReader reader = new LdifReader( resource.openStream() );
LdifEntry entry = reader.next();
reader.close();

syntaxCheckerList.add( entry.getEntry() );
try ( InputStream in = resource.openStream();
LdifReader reader = new LdifReader( in ) )
{
LdifEntry entry = reader.next();
syntaxCheckerList.add( entry.getEntry() );
}
}
}
}
@@ -257,11 +262,13 @@ public List<Entry> loadNormalizers( Schema... schemas ) throws LdapException, IO
if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) )
{
URL resource = getResource( resourcePath, "normalizer LDIF file" );
LdifReader reader = new LdifReader( resource.openStream() );
LdifEntry entry = reader.next();
reader.close();

normalizerList.add( entry.getEntry() );
try ( InputStream in = resource.openStream();
LdifReader reader = new LdifReader( in ) )
{
LdifEntry entry = reader.next();
normalizerList.add( entry.getEntry() );
}
}
}
}
@@ -294,11 +301,13 @@ public List<Entry> loadMatchingRules( Schema... schemas ) throws LdapException,
if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) )
{
URL resource = getResource( resourcePath, "matchingRules LDIF file" );
LdifReader reader = new LdifReader( resource.openStream() );
LdifEntry entry = reader.next();
reader.close();

matchingRuleList.add( entry.getEntry() );
try ( InputStream in = resource.openStream();
LdifReader reader = new LdifReader( in ) )
{
LdifEntry entry = reader.next();
matchingRuleList.add( entry.getEntry() );
}
}
}
}
@@ -331,11 +340,13 @@ public List<Entry> loadSyntaxes( Schema... schemas ) throws LdapException, IOExc
if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) )
{
URL resource = getResource( resourcePath, "syntax LDIF file" );
LdifReader reader = new LdifReader( resource.openStream() );
LdifEntry entry = reader.next();
reader.close();

syntaxList.add( entry.getEntry() );
try ( InputStream in = resource.openStream();
LdifReader reader = new LdifReader( in ) )
{
LdifEntry entry = reader.next();
syntaxList.add( entry.getEntry() );
}
}
}
}
@@ -370,11 +381,13 @@ public List<Entry> loadAttributeTypes( Schema... schemas ) throws LdapException,
if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) )
{
URL resource = getResource( resourcePath, "attributeType LDIF file" );
LdifReader reader = new LdifReader( resource.openStream() );
LdifEntry entry = reader.next();
reader.close();

attributeTypeList.add( entry.getEntry() );

try ( InputStream in = resource.openStream();
LdifReader reader = new LdifReader( in ) )
{
LdifEntry entry = reader.next();
attributeTypeList.add( entry.getEntry() );
}
}
}
}
@@ -407,11 +420,13 @@ public List<Entry> loadMatchingRuleUses( Schema... schemas ) throws LdapExceptio
if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) )
{
URL resource = getResource( resourcePath, "matchingRuleUse LDIF file" );
LdifReader reader = new LdifReader( resource.openStream() );
LdifEntry entry = reader.next();
reader.close();

matchingRuleUseList.add( entry.getEntry() );
try ( InputStream in = resource.openStream();
LdifReader reader = new LdifReader( in ) )
{
LdifEntry entry = reader.next();
matchingRuleUseList.add( entry.getEntry() );
}
}
}
}
@@ -444,11 +459,13 @@ public List<Entry> loadNameForms( Schema... schemas ) throws LdapException, IOEx
if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) )
{
URL resource = getResource( resourcePath, "nameForm LDIF file" );
LdifReader reader = new LdifReader( resource.openStream() );
LdifEntry entry = reader.next();
reader.close();

nameFormList.add( entry.getEntry() );
try ( InputStream in = resource.openStream();
LdifReader reader = new LdifReader( in ) )
{
LdifEntry entry = reader.next();
nameFormList.add( entry.getEntry() );
}
}
}
}
@@ -481,11 +498,13 @@ public List<Entry> loadDitContentRules( Schema... schemas ) throws LdapException
if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) )
{
URL resource = getResource( resourcePath, "ditContentRule LDIF file" );
LdifReader reader = new LdifReader( resource.openStream() );
LdifEntry entry = reader.next();
reader.close();

ditContentRulesList.add( entry.getEntry() );
try ( InputStream in = resource.openStream();
LdifReader reader = new LdifReader( in ) )
{
LdifEntry entry = reader.next();
ditContentRulesList.add( entry.getEntry() );
}
}
}
}
@@ -518,11 +537,13 @@ public List<Entry> loadDitStructureRules( Schema... schemas ) throws LdapExcepti
if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) )
{
URL resource = getResource( resourcePath, "ditStructureRule LDIF file" );
LdifReader reader = new LdifReader( resource.openStream() );
LdifEntry entry = reader.next();
reader.close();

ditStructureRuleList.add( entry.getEntry() );
try ( InputStream in = resource.openStream();
LdifReader reader = new LdifReader( in ) )
{
LdifEntry entry = reader.next();
ditStructureRuleList.add( entry.getEntry() );
}
}
}
}
@@ -556,11 +577,13 @@ public List<Entry> loadObjectClasses( Schema... schemas ) throws LdapException,
if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) )
{
URL resource = getResource( resourcePath, "objectClass LDIF file" );
LdifReader reader = new LdifReader( resource.openStream() );
LdifEntry entry = reader.next();
reader.close();

objectClassList.add( entry.getEntry() );
try ( InputStream in = resource.openStream();
LdifReader reader = new LdifReader( in ) )
{
LdifEntry entry = reader.next();
objectClassList.add( entry.getEntry() );
}
}
}
}
@@ -205,11 +205,11 @@ public List<Entry> loadComparators( Schema... schemas ) throws LdapException, IO
{
for ( File ldifFile : comparators )
{
LdifReader reader = new LdifReader( ldifFile );
LdifEntry entry = reader.next();
reader.close();

comparatorList.add( entry.getEntry() );
try ( LdifReader reader = new LdifReader( ldifFile ) )
{
LdifEntry entry = reader.next();
comparatorList.add( entry.getEntry() );
}
}
}
}
@@ -246,11 +246,11 @@ public List<Entry> loadSyntaxCheckers( Schema... schemas ) throws LdapException,
{
for ( File ldifFile : syntaxCheckerFiles )
{
LdifReader reader = new LdifReader( ldifFile );
LdifEntry entry = reader.next();
reader.close();

syntaxCheckerList.add( entry.getEntry() );
try ( LdifReader reader = new LdifReader( ldifFile ) )
{
LdifEntry entry = reader.next();
syntaxCheckerList.add( entry.getEntry() );
}
}
}
}
@@ -287,11 +287,11 @@ public List<Entry> loadNormalizers( Schema... schemas ) throws LdapException, IO
{
for ( File ldifFile : normalizerFiles )
{
LdifReader reader = new LdifReader( ldifFile );
LdifEntry entry = reader.next();
reader.close();

normalizerList.add( entry.getEntry() );
try ( LdifReader reader = new LdifReader( ldifFile ) )
{
LdifEntry entry = reader.next();
normalizerList.add( entry.getEntry() );
}
}
}
}
@@ -328,11 +328,11 @@ public List<Entry> loadMatchingRules( Schema... schemas ) throws LdapException,
{
for ( File ldifFile : matchingRuleFiles )
{
LdifReader reader = new LdifReader( ldifFile );
LdifEntry entry = reader.next();
reader.close();

matchingRuleList.add( entry.getEntry() );
try ( LdifReader reader = new LdifReader( ldifFile ) )
{
LdifEntry entry = reader.next();
matchingRuleList.add( entry.getEntry() );
}
}
}
}
@@ -369,11 +369,11 @@ public List<Entry> loadSyntaxes( Schema... schemas ) throws LdapException, IOExc
{
for ( File ldifFile : syntaxFiles )
{
LdifReader reader = new LdifReader( ldifFile );
LdifEntry entry = reader.next();
reader.close();

syntaxList.add( entry.getEntry() );
try ( LdifReader reader = new LdifReader( ldifFile ) )
{
LdifEntry entry = reader.next();
syntaxList.add( entry.getEntry() );
}
}
}
}
@@ -412,11 +412,11 @@ public List<Entry> loadAttributeTypes( Schema... schemas ) throws LdapException,
{
for ( File ldifFile : attributeTypeFiles )
{
LdifReader reader = new LdifReader( ldifFile );
LdifEntry entry = reader.next();
reader.close();

attributeTypeList.add( entry.getEntry() );
try ( LdifReader reader = new LdifReader( ldifFile ) )
{
LdifEntry entry = reader.next();
attributeTypeList.add( entry.getEntry() );
}
}
}
}
@@ -454,11 +454,11 @@ public List<Entry> loadMatchingRuleUses( Schema... schemas ) throws LdapExceptio
{
for ( File ldifFile : matchingRuleUseFiles )
{
LdifReader reader = new LdifReader( ldifFile );
LdifEntry entry = reader.next();
reader.close();

matchingRuleUseList.add( entry.getEntry() );
try ( LdifReader reader = new LdifReader( ldifFile ) )
{
LdifEntry entry = reader.next();
matchingRuleUseList.add( entry.getEntry() );
}
}
}
}
@@ -495,11 +495,11 @@ public List<Entry> loadNameForms( Schema... schemas ) throws LdapException, IOEx
{
for ( File ldifFile : nameFormFiles )
{
LdifReader reader = new LdifReader( ldifFile );
LdifEntry entry = reader.next();
reader.close();

nameFormList.add( entry.getEntry() );
try ( LdifReader reader = new LdifReader( ldifFile ) )
{
LdifEntry entry = reader.next();
nameFormList.add( entry.getEntry() );
}
}
}
}
@@ -537,11 +537,11 @@ public List<Entry> loadDitContentRules( Schema... schemas ) throws LdapException
{
for ( File ldifFile : ditContentRuleFiles )
{
LdifReader reader = new LdifReader( ldifFile );
LdifEntry entry = reader.next();
reader.close();

ditContentRuleList.add( entry.getEntry() );
try ( LdifReader reader = new LdifReader( ldifFile ) )
{
LdifEntry entry = reader.next();
ditContentRuleList.add( entry.getEntry() );
}
}
}
}
@@ -579,11 +579,11 @@ public List<Entry> loadDitStructureRules( Schema... schemas ) throws LdapExcepti
{
for ( File ldifFile : ditStructureRuleFiles )
{
LdifReader reader = new LdifReader( ldifFile );
LdifEntry entry = reader.next();
reader.close();

ditStructureRuleList.add( entry.getEntry() );
try ( LdifReader reader = new LdifReader( ldifFile ) )
{
LdifEntry entry = reader.next();
ditStructureRuleList.add( entry.getEntry() );
}
}
}
}
@@ -622,11 +622,11 @@ public List<Entry> loadObjectClasses( Schema... schemas ) throws LdapException,
{
for ( File ldifFile : objectClassFiles )
{
LdifReader reader = new LdifReader( ldifFile );
LdifEntry entry = reader.next();
reader.close();

objectClassList.add( entry.getEntry() );
try ( LdifReader reader = new LdifReader( ldifFile ) )
{
LdifEntry entry = reader.next();
objectClassList.add( entry.getEntry() );
}
}
}
}

0 comments on commit 75c9ab8

Please sign in to comment.