You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2017/07/24 03:48:36 UTC
[3/6] maven-indexer git commit: use some java 7
use some java 7
Signed-off-by: olivier lamy <ol...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/maven-indexer/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-indexer/commit/a49cfdc3
Tree: http://git-wip-us.apache.org/repos/asf/maven-indexer/tree/a49cfdc3
Diff: http://git-wip-us.apache.org/repos/asf/maven-indexer/diff/a49cfdc3
Branch: refs/heads/master
Commit: a49cfdc39a8fa0a33a388e768101b917aca5cf19
Parents: 8f5417f
Author: olivier lamy <ol...@apache.org>
Authored: Mon Jul 17 18:40:27 2017 +1000
Committer: olivier lamy <ol...@apache.org>
Committed: Mon Jul 17 18:40:27 2017 +1000
----------------------------------------------------------------------
.../apache/maven/index/DefaultNexusIndexer.java | 1 +
.../index/context/DefaultIndexingContext.java | 1 +
.../index/context/MergedIndexingContext.java | 1 +
.../index/DefaultIndexNexusIndexerTest.java | 6 +-
.../maven/index/FullIndexNexusIndexerTest.java | 6 +-
.../maven/index/Nexus13NexusIndexerTest.java | 6 +-
.../apache/maven/index/NexusIndexerTest.java | 6 +-
.../updater/DefaultIndexUpdaterEmbeddingIT.java | 32 +-
.../index/updater/FullBootProofOfConcept.java | 1 +
.../apache/maven/index/reader/TestSupport.java | 298 ++++++++++---------
10 files changed, 188 insertions(+), 170 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a49cfdc3/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java b/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java
index 5453caa..3530edd 100644
--- a/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java
+++ b/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java
@@ -270,6 +270,7 @@ public class DefaultNexusIndexer
// always use temporary context when reindexing
final File tmpFile = File.createTempFile( context.getId() + "-tmp", "" );
+ tmpFile.deleteOnExit();
final File tmpDir = new File( tmpFile.getParentFile(), tmpFile.getName() + ".dir" );
if ( !tmpDir.mkdirs() )
{
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a49cfdc3/indexer-core/src/main/java/org/apache/maven/index/context/DefaultIndexingContext.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/main/java/org/apache/maven/index/context/DefaultIndexingContext.java b/indexer-core/src/main/java/org/apache/maven/index/context/DefaultIndexingContext.java
index c7ede33..9a01d4c 100644
--- a/indexer-core/src/main/java/org/apache/maven/index/context/DefaultIndexingContext.java
+++ b/indexer-core/src/main/java/org/apache/maven/index/context/DefaultIndexingContext.java
@@ -213,6 +213,7 @@ public class DefaultIndexingContext
{
// best effort, to have a directory thru the life of a ctx
File tmpFile = File.createTempFile( "mindexer-ctx" + id, "tmp" );
+ tmpFile.deleteOnExit();
tmpFile.delete();
tmpFile.mkdirs();
this.indexDirectoryFile = tmpFile;
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a49cfdc3/indexer-core/src/main/java/org/apache/maven/index/context/MergedIndexingContext.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/main/java/org/apache/maven/index/context/MergedIndexingContext.java b/indexer-core/src/main/java/org/apache/maven/index/context/MergedIndexingContext.java
index 45d93c7..82cb3ab 100644
--- a/indexer-core/src/main/java/org/apache/maven/index/context/MergedIndexingContext.java
+++ b/indexer-core/src/main/java/org/apache/maven/index/context/MergedIndexingContext.java
@@ -308,6 +308,7 @@ public class MergedIndexingContext
{
// best effort, to have a directory thru the life of a ctx
File tmpFile = File.createTempFile( "mindexer-ctx" + id, "tmp" );
+ tmpFile.deleteOnExit();
tmpFile.delete();
tmpFile.mkdirs();
this.directoryFile = tmpFile;
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a49cfdc3/indexer-core/src/test/java/org/apache/maven/index/DefaultIndexNexusIndexerTest.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/test/java/org/apache/maven/index/DefaultIndexNexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/DefaultIndexNexusIndexerTest.java
index 195b472..e049496 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/DefaultIndexNexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/DefaultIndexNexusIndexerTest.java
@@ -20,6 +20,7 @@ package org.apache.maven.index;
*/
import java.io.File;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
@@ -160,9 +161,8 @@ public class DefaultIndexNexusIndexerTest
public void testIndexTimestamp()
throws Exception
{
- final File targetDir = File.createTempFile( "testIndexTimestamp", "ut-tmp" );
- targetDir.delete();
- targetDir.mkdirs();
+ final File targetDir = Files.createTempDirectory( "testIndexTimestamp").toFile();
+ targetDir.deleteOnExit();
final IndexPacker indexPacker = lookup( IndexPacker.class );
final IndexSearcher indexSearcher = context.acquireIndexSearcher();
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a49cfdc3/indexer-core/src/test/java/org/apache/maven/index/FullIndexNexusIndexerTest.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/test/java/org/apache/maven/index/FullIndexNexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/FullIndexNexusIndexerTest.java
index b745237..0c5e140 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/FullIndexNexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/FullIndexNexusIndexerTest.java
@@ -22,6 +22,7 @@ package org.apache.maven.index;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
@@ -335,9 +336,8 @@ public class FullIndexNexusIndexerTest
public void testIndexTimestamp()
throws Exception
{
- final File targetDir = File.createTempFile( "testIndexTimestamp", "ut-tmp" );
- targetDir.delete();
- targetDir.mkdirs();
+ final File targetDir = Files.createTempDirectory("testIndexTimestamp" ).toFile();
+ targetDir.deleteOnExit();
final IndexPacker indexPacker = lookup( IndexPacker.class );
final IndexSearcher indexSearcher = context.acquireIndexSearcher();
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a49cfdc3/indexer-core/src/test/java/org/apache/maven/index/Nexus13NexusIndexerTest.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/test/java/org/apache/maven/index/Nexus13NexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/Nexus13NexusIndexerTest.java
index c93e9f5..f520a9e 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/Nexus13NexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/Nexus13NexusIndexerTest.java
@@ -22,6 +22,7 @@ package org.apache.maven.index;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -111,9 +112,8 @@ public class Nexus13NexusIndexerTest
public void testIndexTimestamp()
throws Exception
{
- final File targetDir = File.createTempFile( "testIndexTimestamp", "ut-tmp" );
- targetDir.delete();
- targetDir.mkdirs();
+ final File targetDir = Files.createTempDirectory( "testIndexTimestamp" ).toFile();
+ targetDir.deleteOnExit();
final IndexPacker indexPacker = lookup( IndexPacker.class );
final IndexSearcher indexSearcher = context.acquireIndexSearcher();
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a49cfdc3/indexer-core/src/test/java/org/apache/maven/index/NexusIndexerTest.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/test/java/org/apache/maven/index/NexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/NexusIndexerTest.java
index 52736a7..21d1f92 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/NexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/NexusIndexerTest.java
@@ -27,6 +27,7 @@ import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -567,9 +568,8 @@ public class NexusIndexerTest
List<IndexCreator> indexCreators = context.getIndexCreators();
// Directory directory = context.getIndexDirectory();
- final File targetDir = File.createTempFile( "testIndexTimestamp", "ut-tmp" );
- targetDir.delete();
- targetDir.mkdirs();
+ final File targetDir = Files.createTempDirectory("testIndexTimestamp" ).toFile();
+ targetDir.deleteOnExit();
final IndexPacker indexPacker = lookup( IndexPacker.class );
final IndexSearcher indexSearcher = context.acquireIndexSearcher();
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a49cfdc3/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterEmbeddingIT.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterEmbeddingIT.java b/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterEmbeddingIT.java
index c9e948c..83f719d 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterEmbeddingIT.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterEmbeddingIT.java
@@ -22,6 +22,7 @@ package org.apache.maven.index.updater;
import java.io.File;
import java.io.IOException;
import java.net.ServerSocket;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
@@ -90,7 +91,7 @@ public class DefaultIndexUpdaterEmbeddingIT
public void testBasicIndexRetrieval()
throws IOException, UnsupportedExistingLuceneIndexException, ComponentLookupException
{
- File basedir = File.createTempFile( "nexus-indexer.", ".dir" );
+ File basedir = Files.createTempDirectory( "nexus-indexer." ).toFile();
basedir.delete();
basedir.mkdirs();
@@ -121,9 +122,7 @@ public class DefaultIndexUpdaterEmbeddingIT
public void testBasicAuthenticatedIndexRetrieval()
throws IOException, UnsupportedExistingLuceneIndexException, ComponentLookupException
{
- File basedir = File.createTempFile( "nexus-indexer.", ".dir" );
- basedir.delete();
- basedir.mkdirs();
+ File basedir = Files.createTempDirectory( "nexus-indexer." ).toFile();
try
{
@@ -160,9 +159,8 @@ public class DefaultIndexUpdaterEmbeddingIT
public void testAuthenticatedIndexRetrieval_LongAuthorizationHeader()
throws IOException, UnsupportedExistingLuceneIndexException, ComponentLookupException
{
- File basedir = File.createTempFile( "nexus-indexer.", ".dir" );
- basedir.delete();
- basedir.mkdirs();
+ File basedir = Files.createTempDirectory( "nexus-indexer." ).toFile();
+
try
{
@@ -199,9 +197,7 @@ public class DefaultIndexUpdaterEmbeddingIT
public void testBasicHighLatencyIndexRetrieval()
throws IOException, UnsupportedExistingLuceneIndexException, ComponentLookupException
{
- File basedir = File.createTempFile( "nexus-indexer.", ".dir" );
- basedir.delete();
- basedir.mkdirs();
+ File basedir = Files.createTempDirectory( "nexus-indexer." ).toFile();
try
{
@@ -239,9 +235,7 @@ public class DefaultIndexUpdaterEmbeddingIT
public void OFFtestHighLatencyIndexRetrieval_LowConnectionTimeout()
throws IOException, UnsupportedExistingLuceneIndexException, ComponentLookupException
{
- File basedir = File.createTempFile( "nexus-indexer.", ".dir" );
- basedir.delete();
- basedir.mkdirs();
+ File basedir = Files.createTempDirectory( "nexus-indexer." ).toFile();
try
{
@@ -296,9 +290,7 @@ public class DefaultIndexUpdaterEmbeddingIT
public void OFFtestHighLatencyIndexRetrieval_LowTransactionTimeout()
throws IOException, UnsupportedExistingLuceneIndexException, ComponentLookupException
{
- File basedir = File.createTempFile( "nexus-indexer.", ".dir" );
- basedir.delete();
- basedir.mkdirs();
+ File basedir = Files.createTempDirectory( "nexus-indexer." ).toFile();
try
{
@@ -352,9 +344,7 @@ public class DefaultIndexUpdaterEmbeddingIT
public void testIndexRetrieval_InfiniteRedirection()
throws IOException, UnsupportedExistingLuceneIndexException, ComponentLookupException
{
- File basedir = File.createTempFile( "nexus-indexer.", ".dir" );
- basedir.delete();
- basedir.mkdirs();
+ File basedir = Files.createTempDirectory( "nexus-indexer." ).toFile();
try
{
@@ -396,9 +386,7 @@ public class DefaultIndexUpdaterEmbeddingIT
public void testIndexRetrieval_BadHostname()
throws IOException, UnsupportedExistingLuceneIndexException, ComponentLookupException
{
- File basedir = File.createTempFile( "nexus-indexer.", ".dir" );
- basedir.delete();
- basedir.mkdirs();
+ File basedir = Files.createTempDirectory( "nexus-indexer." ).toFile();
try
{
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a49cfdc3/indexer-core/src/test/java/org/apache/maven/index/updater/FullBootProofOfConcept.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/test/java/org/apache/maven/index/updater/FullBootProofOfConcept.java b/indexer-core/src/test/java/org/apache/maven/index/updater/FullBootProofOfConcept.java
index aa32a26..8b55b24 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/updater/FullBootProofOfConcept.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/updater/FullBootProofOfConcept.java
@@ -49,6 +49,7 @@ public class FullBootProofOfConcept
for ( int i = 0; i < 1; i++ )
{
File basedir = File.createTempFile( "nexus-indexer.", ".dir" );
+ basedir.deleteOnExit();
try
{
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a49cfdc3/indexer-reader/src/test/java/org/apache/maven/index/reader/TestSupport.java
----------------------------------------------------------------------
diff --git a/indexer-reader/src/test/java/org/apache/maven/index/reader/TestSupport.java b/indexer-reader/src/test/java/org/apache/maven/index/reader/TestSupport.java
index 8edfbb7..957bf58 100644
--- a/indexer-reader/src/test/java/org/apache/maven/index/reader/TestSupport.java
+++ b/indexer-reader/src/test/java/org/apache/maven/index/reader/TestSupport.java
@@ -19,6 +19,12 @@ package org.apache.maven.index.reader;
* under the License.
*/
+import org.apache.maven.index.reader.Record.Type;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.rules.TestName;
+
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -26,12 +32,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.maven.index.reader.Record.Type;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.rules.TestName;
-
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
@@ -40,145 +40,171 @@ import static org.junit.Assert.assertThat;
*/
public class TestSupport
{
- @Rule
- public TestName testName = new TestName();
-
- private File tempDir;
-
- private List<DirectoryResourceHandler> directoryResourceHandlers;
-
- /**
- * Creates the temp directory and list for resource handlers.
- */
- @Before
- public void setup() throws IOException {
- this.tempDir = new File("target/tmp-" + getClass().getSimpleName());
- this.tempDir.delete();
- this.tempDir.mkdirs();
- this.directoryResourceHandlers = new ArrayList<>();
- }
-
- /**
- * Closes all the registered resources handlers and deletes the temp directory.
- */
- @After
- public void cleanup() throws IOException {
- for (DirectoryResourceHandler directoryResourceHandler : directoryResourceHandlers) {
- directoryResourceHandler.close();
+ @Rule
+ public TestName testName = new TestName();
+
+ private File tempDir;
+
+ private List<DirectoryResourceHandler> directoryResourceHandlers;
+
+ /**
+ * Creates the temp directory and list for resource handlers.
+ */
+ @Before
+ public void setup()
+ throws IOException
+ {
+ this.tempDir = new File( "target/tmp-" + getClass().getSimpleName() );
+ this.tempDir.delete();
+ this.tempDir.mkdirs();
+ this.directoryResourceHandlers = new ArrayList<>();
}
- // delete(tempDir);
- }
-
- /**
- * Creates a temp file within {@link #tempDir}.
- */
- protected File createTempFile() throws IOException {
- return File.createTempFile(testName.getMethodName() + "-file", "", tempDir);
- }
-
-
- /**
- * Creates a temp file within {@link #tempDir} with given name.
- */
- protected File createTempFile(final String name) throws IOException {
- return new File(tempDir, name);
- }
-
- /**
- * Creates a temp directory within {@link #tempDir}.
- */
- protected File createTempDirectory() throws IOException {
- File result = File.createTempFile(testName.getMethodName() + "-dir", "", tempDir);
- result.delete();
- result.mkdirs();
- return result;
- }
-
- /**
- * Creates an empty {@link DirectoryResourceHandler}.
- */
- protected WritableResourceHandler createWritableResourceHandler() throws IOException {
- DirectoryResourceHandler result = new DirectoryResourceHandler(createTempDirectory());
- directoryResourceHandlers.add(result);
- return result;
- }
-
- /**
- * Creates a "test" {@link ResourceHandler} that contains predefined files, is mapped to test resources under given
- * name.
- */
- protected ResourceHandler testResourceHandler(final String name) throws IOException {
- DirectoryResourceHandler result = new DirectoryResourceHandler(new File("src/test/resources/" + name));
- directoryResourceHandlers.add(result);
- return result;
- }
-
- /**
- * Consumes {@link ChunkReader} and creates a map "by type" with records.
- */
- protected Map<Type, List<Record>> loadRecordsByType(final ChunkReader chunkReader) throws IOException {
- HashMap<Type, List<Record>> stat = new HashMap<Type, List<Record>>();
- try {
- assertThat(chunkReader.getVersion(), equalTo(1));
- final RecordExpander recordExpander = new RecordExpander();
- for (Map<String, String> rec : chunkReader) {
- final Record record = recordExpander.apply(rec);
- if (!stat.containsKey(record.getType())) {
- stat.put(record.getType(), new ArrayList<Record>());
+
+ /**
+ * Closes all the registered resources handlers and deletes the temp directory.
+ */
+ @After
+ public void cleanup()
+ throws IOException
+ {
+ for ( DirectoryResourceHandler directoryResourceHandler : directoryResourceHandlers )
+ {
+ directoryResourceHandler.close();
}
- stat.get(record.getType()).add(record);
- }
+ // delete(tempDir);
}
- finally {
- chunkReader.close();
+
+ /**
+ * Creates a temp file within {@link #tempDir} with given name.
+ */
+ protected File createTempFile( final String name )
+ throws IOException
+ {
+ File file = new File( tempDir, name );
+ file.deleteOnExit();
+ return file;
}
- return stat;
- }
-
-
- /**
- * Consumes {@link ChunkReader} and creates a map "by type" with record type counts.
- */
- protected Map<Type, Integer> countRecordsByType(final ChunkReader chunkReader) throws IOException {
- HashMap<Type, Integer> stat = new HashMap<Type, Integer>();
- try {
- assertThat(chunkReader.getVersion(), equalTo(1));
- final RecordExpander recordExpander = new RecordExpander();
- for (Map<String, String> rec : chunkReader) {
- final Record record = recordExpander.apply(rec);
- if (!stat.containsKey(record.getType())) {
- stat.put(record.getType(), 0);
- }
- stat.put(record.getType(), stat.get(record.getType()) + 1);
- }
+
+ /**
+ * Creates a temp directory within {@link #tempDir}.
+ */
+ protected File createTempDirectory()
+ throws IOException
+ {
+ File result = File.createTempFile( testName.getMethodName() + "-dir", "", tempDir );
+ result.delete();
+ result.mkdirs();
+ return result;
+ }
+
+ /**
+ * Creates an empty {@link DirectoryResourceHandler}.
+ */
+ protected WritableResourceHandler createWritableResourceHandler()
+ throws IOException
+ {
+ DirectoryResourceHandler result = new DirectoryResourceHandler( createTempDirectory() );
+ directoryResourceHandlers.add( result );
+ return result;
}
- finally {
- chunkReader.close();
+
+ /**
+ * Creates a "test" {@link ResourceHandler} that contains predefined files, is mapped to test resources under given
+ * name.
+ */
+ protected ResourceHandler testResourceHandler( final String name )
+ throws IOException
+ {
+ DirectoryResourceHandler result = new DirectoryResourceHandler( new File( "src/test/resources/" + name ) );
+ directoryResourceHandlers.add( result );
+ return result;
}
- return stat;
- }
-
- /**
- * Delete recursively.
- */
- private static boolean delete(final File file) {
- if (file == null) {
- return false;
+
+ /**
+ * Consumes {@link ChunkReader} and creates a map "by type" with records.
+ */
+ protected Map<Type, List<Record>> loadRecordsByType( final ChunkReader chunkReader )
+ throws IOException
+ {
+ HashMap<Type, List<Record>> stat = new HashMap<Type, List<Record>>();
+ try
+ {
+ assertThat( chunkReader.getVersion(), equalTo( 1 ) );
+ final RecordExpander recordExpander = new RecordExpander();
+ for ( Map<String, String> rec : chunkReader )
+ {
+ final Record record = recordExpander.apply( rec );
+ if ( !stat.containsKey( record.getType() ) )
+ {
+ stat.put( record.getType(), new ArrayList<Record>() );
+ }
+ stat.get( record.getType() ).add( record );
+ }
+ }
+ finally
+ {
+ chunkReader.close();
+ }
+ return stat;
}
- if (!file.exists()) {
- return true;
+
+
+ /**
+ * Consumes {@link ChunkReader} and creates a map "by type" with record type counts.
+ */
+ protected Map<Type, Integer> countRecordsByType( final ChunkReader chunkReader )
+ throws IOException
+ {
+ HashMap<Type, Integer> stat = new HashMap<Type, Integer>();
+ try
+ {
+ assertThat( chunkReader.getVersion(), equalTo( 1 ) );
+ final RecordExpander recordExpander = new RecordExpander();
+ for ( Map<String, String> rec : chunkReader )
+ {
+ final Record record = recordExpander.apply( rec );
+ if ( !stat.containsKey( record.getType() ) )
+ {
+ stat.put( record.getType(), 0 );
+ }
+ stat.put( record.getType(), stat.get( record.getType() ) + 1 );
+ }
+ }
+ finally
+ {
+ chunkReader.close();
+ }
+ return stat;
}
- if (file.isDirectory()) {
- String[] list = file.list();
- if (list != null) {
- for (int i = 0; i < list.length; i++) {
- File entry = new File(file, list[i]);
- if (!delete(entry)) {
+
+ /**
+ * Delete recursively.
+ */
+ private static boolean delete( final File file )
+ {
+ if ( file == null )
+ {
return false;
- }
}
- }
+ if ( !file.exists() )
+ {
+ return true;
+ }
+ if ( file.isDirectory() )
+ {
+ String[] list = file.list();
+ if ( list != null )
+ {
+ for ( int i = 0; i < list.length; i++ )
+ {
+ File entry = new File( file, list[i] );
+ if ( !delete( entry ) )
+ {
+ return false;
+ }
+ }
+ }
+ }
+ return file.delete();
}
- return file.delete();
- }
}