Issue #2267 Remove java.nio.file dependencies from the SbnSimulator. Fixed handler setting for UFStatus in test env.
Change-Id: I8245eef53573b6596546e17a7900a1538455cee2 Former-commit-id:a80362eeec
[formerly250730c308
] [formerlyac8136bd82
] [formerlyac8136bd82
[formerlyf1480cfc62
]] [formerlya80362eeec
[formerly250730c308
] [formerlyac8136bd82
] [formerlyac8136bd82
[formerlyf1480cfc62
]] [formerly6bc585aaf6
[formerlyac8136bd82
[formerlyf1480cfc62
] [formerly6bc585aaf6
[formerly 6b8ff162be029543c8b9a7fcb3f8a359962aa6d7]]]]] Former-commit-id:6bc585aaf6
Former-commit-id:72b6d2f365
[formerlybf1d2cb85a
] [formerly47690ea8d0
] [formerly 43fec69cf98fd472331ba332d87f20bfec6e2f72 [formerly 3ebdb55d0083b9e2bf2524a8b3b7cd9acaf899a2] [formerly47690ea8d0
[formerlyaeccaa2329
]]] Former-commit-id: 6d3d87d4392888e742f5701460996a0507f4e25b [formerly 9142f489480470f702fc2b3671eb72d8c6bfc6e1] [formerlyaf7e9dd4ef
[formerly3b2127c103
]] Former-commit-id:af7e9dd4ef
Former-commit-id:2c902ab8e7
This commit is contained in:
parent
8d02f9b060
commit
f0affba60a
4 changed files with 97 additions and 71 deletions
|
@ -23,8 +23,6 @@ import java.util.Iterator;
|
|||
import java.util.ServiceLoader;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
|
||||
/**
|
||||
* The principal mechanism for representing the outcome of an operation. <BR>
|
||||
*
|
||||
|
@ -103,23 +101,22 @@ public class UFStatus {
|
|||
protected final String message;
|
||||
|
||||
/** handler factory */
|
||||
private static AtomicReference<IUFStatusHandlerFactory> handlerFactoryRef = createHandlerFactory();
|
||||
private static AtomicReference<IUFStatusHandlerFactory> handlerFactoryRef = new AtomicReference<IUFStatusHandlerFactory>();
|
||||
|
||||
private static final AtomicReference<IUFStatusHandlerFactory> createHandlerFactory() {
|
||||
static {
|
||||
ServiceLoader<IUFStatusHandlerFactory> loader = ServiceLoader.load(
|
||||
IUFStatusHandlerFactory.class,
|
||||
IUFStatusHandlerFactory.class.getClassLoader());
|
||||
Iterator<IUFStatusHandlerFactory> handlerIterator = loader.iterator();
|
||||
IUFStatusHandlerFactory factory = null;
|
||||
|
||||
if (handlerIterator.hasNext()) {
|
||||
factory = handlerIterator.next();
|
||||
UFStatus.setHandlerFactory(handlerIterator.next());
|
||||
} else {
|
||||
factory = new DefaultStatusHandlerFactory();
|
||||
UFStatus.setHandlerFactory(new DefaultStatusHandlerFactory());
|
||||
Exception e = new RuntimeException("No "
|
||||
+ IUFStatusHandlerFactory.class.getName()
|
||||
+ " found.\nUsing default handler.");
|
||||
factory.getInstance()
|
||||
UFStatus.getHandler()
|
||||
.handle(Priority.CRITICAL,
|
||||
e.getLocalizedMessage()
|
||||
+ "\nPlease ignore if you are in a unit test environment\n");
|
||||
|
@ -130,7 +127,6 @@ public class UFStatus {
|
|||
+ IUFStatusHandlerFactory.class.getName()
|
||||
+ " handlers defined");
|
||||
}
|
||||
return new AtomicReference<IUFStatusHandlerFactory>(factory);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,13 +31,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
@ -932,36 +926,37 @@ public class FileUtil {
|
|||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* List files/directories that match a FileFilter.
|
||||
*
|
||||
* @param directory
|
||||
* @param filter
|
||||
* @param recurse
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static List<Path> listPaths(File directory,
|
||||
DirectoryStream.Filter<? super Path> filter, boolean recurse)
|
||||
throws IOException {
|
||||
// List of files / directories
|
||||
List<Path> files = new LinkedList<Path>();
|
||||
|
||||
// Get files / directories in the directory accepted by the filter.
|
||||
Path dirPath = FileSystems.getDefault().getPath(
|
||||
directory.getAbsolutePath());
|
||||
DirectoryStream<Path> stream = null;
|
||||
try {
|
||||
stream = Files.newDirectoryStream(dirPath, filter);
|
||||
for (final Iterator<Path> it = stream.iterator(); it.hasNext();) {
|
||||
files.add(it.next());
|
||||
}
|
||||
} finally {
|
||||
if (stream != null) {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
// TODO Java 1.7 potential code
|
||||
// /**
|
||||
// * List files/directories that match a FileFilter.
|
||||
// *
|
||||
// * @param directory
|
||||
// * @param filter
|
||||
// * @param recurse
|
||||
// * @return
|
||||
// * @throws IOException
|
||||
// */
|
||||
// public static List<Path> listPaths(File directory,
|
||||
// DirectoryStream.Filter<? super Path> filter, boolean recurse)
|
||||
// throws IOException {
|
||||
// // List of files / directories
|
||||
// List<Path> files = new LinkedList<Path>();
|
||||
//
|
||||
// // Get files / directories in the directory accepted by the filter.
|
||||
// Path dirPath = FileSystems.getDefault().getPath(
|
||||
// directory.getAbsolutePath());
|
||||
// DirectoryStream<Path> stream = null;
|
||||
// try {
|
||||
// stream = Files.newDirectoryStream(dirPath, filter);
|
||||
// for (final Iterator<Path> it = stream.iterator(); it.hasNext();) {
|
||||
// files.add(it.next());
|
||||
// }
|
||||
// } finally {
|
||||
// if (stream != null) {
|
||||
// stream.close();
|
||||
// }
|
||||
// }
|
||||
// return files;
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -21,9 +21,6 @@ package com.raytheon.uf.edex.datadelivery.bandwidth.sbn;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
@ -95,6 +92,8 @@ public class SbnSimulator {
|
|||
|
||||
private final IFileProcessor fileProcessor;
|
||||
|
||||
private String site;
|
||||
|
||||
/**
|
||||
* Private constructor.
|
||||
*/
|
||||
|
@ -115,6 +114,7 @@ public class SbnSimulator {
|
|||
this.sitesDirectory = new File(directoryToScan, "sbnSimulator");
|
||||
this.localSiteDirectory = new File(sitesDirectory, site);
|
||||
this.localSiteDirectory.mkdirs();
|
||||
this.site = site;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,8 +126,8 @@ public class SbnSimulator {
|
|||
final List<File> files = FileUtil.listFiles(localSiteDirectory,
|
||||
FilenameFilters.ACCEPT_VISIBLE_FILES, false);
|
||||
|
||||
statusHandler.info("Found [" + files.size() + "] files for "
|
||||
+ SiteUtil.getSite() + " from the SBN...");
|
||||
statusHandler.info("Found [" + files.size() + "] files for " + site
|
||||
+ " from the SBN...");
|
||||
|
||||
for (File file : files) {
|
||||
|
||||
|
@ -150,36 +150,73 @@ public class SbnSimulator {
|
|||
* @throws IOException
|
||||
*/
|
||||
public void distributeToSiteDirs() throws IOException {
|
||||
final List<Path> undistributedFiles = FileUtil.listPaths(
|
||||
final List<File> undistributedFiles = FileUtil.listFiles(
|
||||
directoryToScan,
|
||||
FilenameFilters.ACCEPT_PATH_FILES, false);
|
||||
FilenameFilters.ACCEPT_FILES, false);
|
||||
// get list of site dirs
|
||||
final List<Path> sites = FileUtil.listPaths(sitesDirectory,
|
||||
FilenameFilters.ACCEPT_PATH_DIRECTORIES, false);
|
||||
final List<File> sites = FileUtil.listFiles(sitesDirectory,
|
||||
FilenameFilters.ACCEPT_DIRECTORIES, false);
|
||||
|
||||
statusHandler.info("Found [" + undistributedFiles.size() + "] files to distribute...");
|
||||
|
||||
// distribute to site specific directories
|
||||
for (Path file : undistributedFiles) {
|
||||
for (File file : undistributedFiles) {
|
||||
statusHandler.info("Distributing file [" + file + "]");
|
||||
for (Path siteDir : sites) {
|
||||
Path dest = FileSystems.getDefault().getPath(
|
||||
siteDir.toString(), file.getFileName().toString());
|
||||
Path hiddenDest = FileSystems.getDefault()
|
||||
.getPath(siteDir.toString(),
|
||||
"." + file.getFileName().toString());
|
||||
for (File siteDir : sites) {
|
||||
File dest = new File(siteDir, file.getName().toString());
|
||||
File hiddenDest = new File(siteDir, "."
|
||||
+ file.getName().toString());
|
||||
|
||||
// move to site sbn directory as hidden
|
||||
java.nio.file.Files.copy(file, hiddenDest,
|
||||
StandardCopyOption.REPLACE_EXISTING);
|
||||
FileUtil.copyFile(file, hiddenDest);
|
||||
// rename dest to un-hidden
|
||||
java.nio.file.Files.move(hiddenDest, dest,
|
||||
StandardCopyOption.ATOMIC_MOVE);
|
||||
hiddenDest.renameTo(dest);
|
||||
statusHandler.info("===> to file [" + dest + "]");
|
||||
}
|
||||
// delete source file
|
||||
java.nio.file.Files.delete(file);
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Java 1.7 version of the distributeToSiteDirs() method
|
||||
// /**
|
||||
// * Distribute to the site directories. Enables all site client registries
|
||||
// * to ingest shared data.
|
||||
// *
|
||||
// * @throws IOException
|
||||
// */
|
||||
// public void distributeToSiteDirs() throws IOException {
|
||||
// final List<Path> undistributedFiles = FileUtil.listPaths(
|
||||
// directoryToScan,
|
||||
// FilenameFilters.ACCEPT_PATH_FILES, false);
|
||||
// // get list of site dirs
|
||||
// final List<Path> sites = FileUtil.listPaths(sitesDirectory,
|
||||
// FilenameFilters.ACCEPT_PATH_DIRECTORIES, false);
|
||||
//
|
||||
// statusHandler.info("Found [" + undistributedFiles.size() +
|
||||
// "] files to distribute...");
|
||||
//
|
||||
// // distribute to site specific directories
|
||||
// for (Path file : undistributedFiles) {
|
||||
// statusHandler.info("Distributing file [" + file + "]");
|
||||
// for (Path siteDir : sites) {
|
||||
// Path dest = FileSystems.getDefault().getPath(
|
||||
// siteDir.toString(), file.getFileName().toString());
|
||||
// Path hiddenDest = FileSystems.getDefault()
|
||||
// .getPath(siteDir.toString(),
|
||||
// "." + file.getFileName().toString());
|
||||
//
|
||||
// // move to site sbn directory as hidden
|
||||
// java.nio.file.Files.copy(file, hiddenDest,
|
||||
// StandardCopyOption.REPLACE_EXISTING);
|
||||
// // rename dest to un-hidden
|
||||
// java.nio.file.Files.move(hiddenDest, dest,
|
||||
// StandardCopyOption.ATOMIC_MOVE);
|
||||
// statusHandler.info("===> to file [" + dest + "]");
|
||||
// }
|
||||
// // delete source file
|
||||
// java.nio.file.Files.delete(file);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -117,10 +117,8 @@ public class SbnSimulatorTest {
|
|||
|
||||
@Test
|
||||
public void errorOnOneFileDoesNotStopTheOthers() throws IOException {
|
||||
File fileOneExpectedResult = createTestFileGetExpected(testDir,
|
||||
"fileOne.txt", "AA1");
|
||||
File fileTwoExpectedResult = createTestFileGetExpected(testDir,
|
||||
"fileTwo.txt", "AA2");
|
||||
createTestFileGetExpected(testDir, "fileOne.txt", "AA1");
|
||||
createTestFileGetExpected(testDir, "fileTwo.txt", "AA2");
|
||||
|
||||
doThrow(new IOException()).when(fileProcessor).processFile(
|
||||
any(File.class));
|
||||
|
|
Loading…
Add table
Reference in a new issue