import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
throws IOException
{
- try (FileInputStream fis = new FileInputStream( referenceFile ))
+ try (InputStream fis = Files.newInputStream( referenceFile.toPath() ) )
{
Checksum checksum = new Checksum( checksumAlgorithm );
checksum.update( fis );
public boolean isValidChecksums( ChecksumAlgorithm algorithms[] )
{
- try (FileInputStream fis = new FileInputStream( referenceFile ))
+ try (InputStream fis = Files.newInputStream( referenceFile.toPath() ))
{
List<Checksum> checksums = new ArrayList<>( algorithms.length );
// Create checksum object for each algorithm.
}
- try (FileInputStream fis = new FileInputStream( referenceFile ))
+ try (InputStream fis = Files.newInputStream( referenceFile.toPath() ))
{
// Parse file once, for all checksums.
Checksum.update( checksums, fis );
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.nio.file.Files;
import java.util.List;
import java.util.Map;
final StreamWagon wagon = (StreamWagon) wagonFactory.getWagon(
new WagonFactoryRequest( wagonProtocol, this.remoteRepository.getExtraHeaders() ).networkProxy(
- this.networkProxy ) );
+ this.networkProxy )
+ );
// FIXME olamy having 2 config values
wagon.setReadTimeout( remoteRepository.getRemoteDownloadTimeout() * 1000 );
wagon.setTimeout( remoteRepository.getTimeout() * 1000 );
{
log.info( "index update retrieve file, name:{}", name );
File file = new File( tempIndexDirectory, name );
- if ( file.exists() )
- {
- file.delete();
- }
+ Files.deleteIfExists( file.toPath() );
file.deleteOnExit();
wagon.get( addParameters( name, this.remoteRepository ), file );
- return new FileInputStream( file );
+ return Files.newInputStream( file.toPath() );
}
catch ( AuthorizationException e )
{
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
* ArchivaIndexingTaskExecutorTest
*/
-@RunWith (ArchivaSpringJUnit4ClassRunner.class)
-@ContextConfiguration (locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" })
+@RunWith( ArchivaSpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
public class ArchivaIndexingTaskExecutorTest
extends TestCase
{
new File( repositoryConfig.getLocation() ),
new File( repositoryConfig.getLocation(),
".indexer" ), null, null,
- mavenIndexerUtils.getAllIndexCreators() );
+ mavenIndexerUtils.getAllIndexCreators()
+ );
context.setSearchable( true );
}
q.add( indexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( "org.apache.archiva" ) ),
Occur.SHOULD );
q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID,
- new SourcedSearchExpression( "archiva-index-methods-jar-test" ) ),
- Occur.SHOULD );
+ new SourcedSearchExpression( "archiva-index-methods-jar-test" ) ), Occur.SHOULD
+ );
assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
assertFalse( new File( repositoryConfig.getLocation(), ".index" ).exists() );
{
final int buff = 2048;
- new File( destDir ).mkdirs();
-
- BufferedOutputStream out = null;
- FileInputStream fin = new FileInputStream( new File( indexDir, "nexus-maven-repository-index.zip" ) );
- ZipInputStream in = new ZipInputStream( new BufferedInputStream( fin ) );
- ZipEntry entry;
+ Files.createDirectories( Paths.get( destDir ) );
- while ( ( entry = in.getNextEntry() ) != null )
+ try (InputStream fin = Files.newInputStream( Paths.get( indexDir, "nexus-maven-repository-index.zip" ) ))
{
- int count;
- byte data[] = new byte[buff];
- FileOutputStream fout = new FileOutputStream( new File( destDir, entry.getName() ) );
- out = new BufferedOutputStream( fout, buff );
+ ZipInputStream in = new ZipInputStream( new BufferedInputStream( fin ) );
+ ZipEntry entry;
- while ( ( count = in.read( data, 0, buff ) ) != -1 )
+ while ( ( entry = in.getNextEntry() ) != null )
{
- out.write( data, 0, count );
+ int count;
+ byte data[] = new byte[buff];
+ try (OutputStream fout = Files.newOutputStream( Paths.get( destDir, entry.getName() ) ))
+ {
+ try (BufferedOutputStream out = new BufferedOutputStream( fout, buff ))
+ {
+
+ while ( ( count = in.read( data, 0, buff ) ) != -1 )
+ {
+ out.write( data, 0, count );
+ }
+ }
+ }
}
- out.flush();
- out.close();
- }
- in.close();
+ }
}
}