use of com.att.aro.core.fileio.IFileManager in project VideoOptimzer by attdevsupport.
the class Validator method validate.
public ErrorCode validate(Commands cmd, ApplicationContext context) {
if (cmd.getAnalyze() != null) {
if (cmd.getFormat().equals("json") && cmd.getFormat().equals("html")) {
return ErrorCodeRegistry.getUnsupportedFormat();
}
if (cmd.getOutput() == null) {
return ErrorCodeRegistry.getOutputRequired();
}
IFileManager filemg = context.getBean(IFileManager.class);
if (filemg.fileExist(cmd.getOutput())) {
if ("yes".equals(cmd.getOverwrite())) {
filemg.deleteFile(cmd.getOutput());
} else {
return ErrorCodeRegistry.getFileExist();
}
}
} else {
if (cmd.getStartcollector() != null) {
String colname = cmd.getStartcollector();
if (!"rooted_android".equals(colname) && !"vpn_android".equals(colname) && !"ios".equals(colname)) {
return ErrorCodeRegistry.getUnsupportedCollector();
}
if (cmd.getOutput() == null) {
return ErrorCodeRegistry.getOutputRequired();
}
}
if (cmd.getVideo() != null && !cmd.getVideo().equals("yes") && !cmd.getVideo().equals("no") && !cmd.getVideo().equals("hd") && !cmd.getVideo().equals("sd") && !cmd.getVideo().equals("slow")) {
return ErrorCodeRegistry.getInvalidVideoOption();
}
ErrorCode uplinkErrorCode = validateUplink(cmd);
if (uplinkErrorCode != null) {
return uplinkErrorCode;
}
ErrorCode downlinkErrorCode = validateDownlink(cmd);
if (downlinkErrorCode != null) {
return downlinkErrorCode;
}
}
return null;
}
use of com.att.aro.core.fileio.IFileManager in project VideoOptimzer by attdevsupport.
the class CpuActivityReaderImplTest method readData_IOException.
@Test
public void readData_IOException() throws IOException {
reader = (CpuActivityReaderImpl) context.getBean(ICpuActivityReader.class);
IFileManager filereader = Mockito.mock(IFileManager.class);
Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true);
Mockito.when(filereader.readAllLine(Mockito.anyString())).thenThrow(new IOException("test exception"));
reader.setFileReader(filereader);
CpuActivityList info = reader.readData("/", 0.0);
assertTrue(info.getCpuActivities().size() == 0);
}
use of com.att.aro.core.fileio.IFileManager in project VideoOptimzer by attdevsupport.
the class LoadManifestDialog method loadManifest.
/**
* Copy a file, files or a folder of files into tracepath/downloads/ Will traverse folders within a folder
*/
protected void loadManifest(AnalysisFilter analysisfilter) {
if (aroView.getTracePath() != null) {
// Open filechooser
JFileChooser fileChooser = new JFileChooser(aroView.getTracePath());
fileChooser.setMultiSelectionEnabled(true);
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("mpd, m3u8 or json", "mpd", "m3u8", "json"));
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setAcceptAllFileFilterUsed(false);
int result = fileChooser.showOpenDialog(this);
if (result == JFileChooser.APPROVE_OPTION) {
if (checkBoxCSI.isSelected() && analysisfilter != null) {
String folderNameForCSIStuff = aroView.getTracePath() + File.separator + "CSI";
String expectedManifestFileName = folderNameForCSIStuff + File.separator + fileChooser.getSelectedFile().getName();
File expectedManifestFile = new File(expectedManifestFileName);
try {
if (!fileChooser.getSelectedFile().getPath().equals(expectedManifestFileName) && !expectedManifestFile.exists()) {
IFileManager fileManager = new FileManagerImpl();
if (fileManager.directoryExistAndNotEmpty(expectedManifestFile.getParentFile().getPath())) {
if (folderExistsDialog() == JOptionPane.YES_OPTION) {
FileUtils.deleteDirectory(expectedManifestFile.getParentFile());
}
}
if (!Files.exists(expectedManifestFile.getParentFile().toPath())) {
Files.createDirectory(expectedManifestFile.getParentFile().toPath());
}
if (fileChooser.getSelectedFile().getParent().equals(aroView.getTracePath())) {
Files.move(fileChooser.getSelectedFile().toPath(), expectedManifestFile.toPath());
} else {
Files.copy(fileChooser.getSelectedFile().toPath(), expectedManifestFile.toPath());
}
}
} catch (IOException ioe) {
expectedManifestFileName = fileChooser.getSelectedFile().getPath();
}
analysisfilter.setCSI(true);
analysisfilter.setManifestFilePath(expectedManifestFileName);
((MainFrame) aroView).updateFilter(analysisfilter);
} else {
// save selected file/files inside downloads folder
fileChooser.getSelectedFile().getPath();
String downloadsPath = aroView.getTracePath() + Util.FILE_SEPARATOR + "downloads";
try {
File[] files = fileChooser.getSelectedFiles();
if (!files[0].toString().equals(downloadsPath)) {
// expand out of folder
if (fileChooser.getSelectedFile().isDirectory()) {
files = files[0].listFiles();
}
if (null == files) {
return;
}
for (File file : files) {
if (file.isFile()) {
FileCopyUtils.copy(file, new File(downloadsPath, file.getName()));
}
}
} else {
LOG.error("user error :Chose downloads folder, will ignore");
}
} catch (IOException e1) {
LOG.error("IOException :" + e1.getMessage());
}
// refresh analyzer
aroView.updateTracePath(new File(aroView.getTracePath()));
}
}
}
}
use of com.att.aro.core.fileio.IFileManager in project VideoOptimzer by attdevsupport.
the class FileManagerTest method findFiles.
@Test
public void findFiles() throws Exception {
String[] foundFiles;
VideoStreamConstructor videoStreamConstructor = context.getBean(VideoStreamConstructor.class);
IFileManager filemanager = context.getBean(IFileManager.class);
File tempFolder = Files.createTempDir();
filemanager.createFile(tempFolder.toString(), "file1");
String pathName1 = filemanager.createFile(tempFolder.toString(), "file1").toString();
String pathName1exten = filemanager.createFile(tempFolder.toString(), "file1.xyz").toString();
byte[] content = "dummy data".getBytes();
videoStreamConstructor.savePayload(content, pathName1);
videoStreamConstructor.savePayload(content, pathName1exten);
foundFiles = fileManager.findFiles(tempFolder.toString(), ".xyz");
assertThat(foundFiles).hasSize(1);
assertThat(foundFiles).contains("file1.xyz");
foundFiles = fileManager.findFiles(tempFolder.toString(), "child.xyz");
assertThat(foundFiles).isEmpty();
foundFiles = fileManager.findFiles(tempFolder.toString(), ".sh");
assertThat(foundFiles).isEmpty();
filemanager.directoryDeleteInnerFiles(tempFolder.toString());
filemanager.deleteFile(tempFolder.toString());
}
use of com.att.aro.core.fileio.IFileManager in project VideoOptimzer by attdevsupport.
the class AROController method startCollector.
/**
* Start the collector on device
*
* @param deviceId
* @param traceFolderName
* @param videoOption
* @param secure
*/
public StatusResult startCollector(IAroDevice device, String traceFolderName, Hashtable<String, Object> extraParams) {
StatusResult result = null;
LOG.info("starting collector:" + traceFolderName + " " + extraParams);
getAvailableCollectors();
collector = device.getCollector();
if (collector == null) {
collector = loadCollector(device);
}
traceFolderPath = getTraceFolderPath(device, traceFolderName);
IFileManager fileManager = context.getBean(IFileManager.class);
if (!fileManager.directoryExistAndNotEmpty(traceFolderPath)) {
result = collector.startCollector(false, traceFolderPath, null, true, device.getId(), extraParams, collector.getPassword());
traceStartTime = new Date();
if (result.isSuccess()) {
LOG.info("Result : traffic capture launched successfully");
traceDuration = 0;
} else {
LOG.error("Result trace success:" + result.isSuccess() + ", Name :" + result.getError().getName() + ", Description :" + result.getError().getDescription());
LOG.error("device logcat:");
}
} else {
LOG.info("Illegal path:" + traceFolderPath);
result = new StatusResult();
result.setError(ErrorCodeRegistry.getTraceFolderNotFound());
return result;
}
return result;
}
Aggregations