@Override protected File runPrediction(File tempFile) throws Exception { File prediction = FileUtil.createTempFile("libsvmPrediction", ".libsvm"); prediction.deleteOnExit(); _Prediction predictor = new _Prediction(); BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(tempFile), "utf-8")); DataOutputStream output = new DataOutputStream(new FileOutputStream(prediction)); predictor.predict(r, output, model, 0); output.close(); return prediction; } }
@Override public void initialize(UimaContext context) throws ResourceInitializationException { articleIds = new HashSet<String>(); try { if (articleIdsListFile == null) { filterArticles = false; } else { filterArticles = true; String[] ids = FileUtil.loadListOfStrings(articleIdsListFile); for (String id : ids) { articleIds.add(id); } } parser = new GeniaPosParser(geniaCorpusFile); loadPosTags = loadTokens & loadPosTags; } catch (IOException ioe) { throw new ResourceInitializationException(ioe); } catch (JDOMException je) { throw new ResourceInitializationException(je); } }
/** * Constructor that allows browsing a given unacrhived PEAR package before or after its * installation. * * @param pearPackageDir * The root directory where the PEAR package was unarchived. * @throws IOException if a problem with IO */ public PackageBrowser(File pearPackageDir) throws IOException { _rootDir = pearPackageDir; _archived = false; // add directories and files to the lists _allFiles.addAll(FileUtil.createFileList(_rootDir, true)); _allDirs.addAll(FileUtil.createDirList(_rootDir, true)); }
Collection<File> fileList = createFileList(directory, false); SortedSet<File> sortedFileSet = sortFileListByTime(fileList); if (sortedFileSet.size() > maxLimit) { Iterator<File> list = sortedFileSet.iterator();
Iterator<File> fileList = FileUtil.createFileList(dir, true).iterator(); while (fileList.hasNext()) { File file = fileList.next(); String replacement = FileUtil.localPathToFileUrl(_mainRootPath); FileUtil.replaceStringInFile(file, MAIN_ROOT_URL_REGEX, replacement); FileUtil.replaceStringInFile(file, MAIN_ROOT_REGEX, replacement); String regex = componentIdRootRegExp(compId, DELEGATE_ROOT_REL_SUFFIX_REGEX); try { replacement = FileUtil.computeRelativePath(file.getParentFile(), new File(compRootPath)); if (replacement != null) FileUtil.replaceStringInFile(file, regex, replacement); } catch (Exception e) { String regex = regexList.nextElement(); replacement = _urlSubstitutionTable.get(regex); FileUtil.replaceStringInFile(file, regex, replacement); String regex = regexList.nextElement(); replacement = _pathSubstitutionTable.get(regex); FileUtil.replaceStringInFile(file, regex, replacement);
if (!targetDir.isDirectory()) return; Iterator fileList = FileUtil.createFileList(targetDir, true).iterator(); while (fileList.hasNext()) { File file = (File) fileList.next(); int counter = FileUtil.replaceStringInFile(file, MAIN_ROOT_REGEX, adjMainRoot); if (counter > 0) { String relFilePath = FileUtil.getRelativePath(rootDir, file.getAbsolutePath()); insdObject.addInstallationAction(createFileAction(adjMainRoot + "/" + relFilePath, MAIN_ROOT));
throws IOException { long fileSize = FileUtil.getFileSize(pearFileLocation); String pearFileName = (new File(pearFileUrl.getFile())).getName(); pearFile = new File(targetDir, pearFileName); if (!FileUtil.copyFile(pearFileUrl, pearFile)) throw new IOException("cannot copy " + pearFileUrl + " to file " + pearFile.getAbsolutePath()); long totalBytes = (fileExt == null) ? FileUtil.extractFilesFromJar(jarFile, targetDir) : // all FileUtil.extractFilesWithExtFromJar( // files with extension jarFile, fileExt, targetDir); if (controller != null) // write message to OUT msg queue
if (mainRootPath != null) { String replacement = FileUtil.localPathToFileUrl(mainRootPath); FileUtil.replaceStringInFile(file, InstallationProcessor.MAIN_ROOT_URL_REGEX, replacement); FileUtil.replaceStringInFile(file, InstallationProcessor.MAIN_ROOT_REGEX, replacement); String replacement = FileUtil.computeRelativePath(file.getParentFile(), new File(compRootPath)); FileUtil.replaceStringInFile(file, regExp, replacement); replacement = FileUtil.localPathToFileUrl(compRootPath); FileUtil.replaceStringInFile(file, regExp, replacement); FileUtil.replaceStringInFile(file, regExp, replacement);
String zipEntryName = (referenceDir != null) ? getRelativePath(referenceDir, entry .getAbsolutePath()) : getRelativePath(dir2zip, entry.getAbsolutePath()); ZipEntry zipEntry = new ZipEntry(zipEntryName); zoStream.putNextEntry(zipEntry); zipDirectory(entry, zoStream, referenceDir, excludeFiles);
/** * Loads a given remote text file. * * @param textFileURL * The given text file URL. * @return The content of the text file. * @throws IOException * If any I/O exception occurs. */ public static String loadTextFile(URL textFileURL) throws IOException { URLConnection urlConnection = textFileURL.openConnection(); // See https://issues.apache.org/jira/browse/UIMA-1746 urlConnection.setUseCaches(false); return loadTextFile(urlConnection); }
/** * Deletes all temporary directories and files after the merging operation is completed. * * @throws IOException * If an I/O exception occurred. */ public void cleanUp() throws IOException { logInfoMessage("[" + PEAR_MERGER + "]: " + "deleting temporary files"); FileUtil.deleteDirectory(_outAggRootDir); }
/** * Extracts all files from a given JAR file to a given target directory. * * @param jarFile * The given JAR file. * @param targetDir * The given target directory. * @return Total number of bytes extracted. * @throws IOException * If any I/O exception occurred. */ public static long extractFilesFromJar(JarFile jarFile, File targetDir) throws IOException { return extractFilesFromJar(jarFile, targetDir, null); }
Collection<File> confDirFiles = FileUtil.createFileList(confDir, false); File descDir = new File(_mainRootDir, InstallationController.PACKAGE_DESC_DIR); Collection<File> descDirFiles = FileUtil.createFileList(descDir, false); File[] fileList = new File[confDirFiles.size() + descDirFiles.size()]; int fileCounter = 0; String bakFileName = orgFile.getName().concat(BACKUP_FILE_SUFFIX); File bakFile = new File(orgFile.getParent(), bakFileName); if (FileUtil.copyFile(orgFile, bakFile)) { String bakFileName = orgFile.getName().concat(BACKUP_FILE_SUFFIX); File bakFile = new File(orgFile.getParent(), bakFileName); if (FileUtil.copyFile(orgFile, bakFile)) {
/** * Creates list of files in a given directory, including all its subdirectories. * * @return <code>Collection</code> of <code>File</code> objects in the given directory, * including all its subdirectories. * @param filesDir * The given directory. * * @exception java.io.IOException * If any I/O exception occurs. */ public static Collection<File> createFileList(File filesDir) throws IOException { return createFileList(filesDir, true); }
/** * Zips the contents of a given directory. The output ZIP file, by default, is created in the * given directory, and its name is the given directory name with 'zip' extension. * * @param dir2zip * The given directory to be zipped. * @return The output ZIP file. * @throws IOException * If any I/O exception occurred. */ public static File zipDirectory(File dir2zip) throws IOException { // construct zipped file path String zipFileName = dir2zip.getName() + ".zip"; File zipFile = new File(dir2zip, zipFileName); return zipDirectory(dir2zip, zipFile); }
/** * Constructs a relative path of a given component object, based on its absolute path. * * @param absolutePath * The given absolute path of the object. * @param component * The given component instance. * @return The relative path of the given component object. */ protected static String getRelativePathForComponentObject(String absolutePath, ComponentInfo component) { String path = absolutePath; if (component.rootDirPath != null && path != null) { File rootDir = new File(component.rootDirPath); path = FileUtil.getRelativePath(rootDir, path); } return path; }
/** * Performs a specified 'find_and_replace_path' installation action. * * @param action * The given 'find_and_replace_path' installation action. * @throws IOException * if any I/O exception occurred. */ protected static void findAndReplacePath(InstallationDescriptor.ActionInfo action) throws IOException { // get action parameters String filePath = action.params.getProperty(InstallationDescriptorHandler.FILE_TAG); if (filePath == null) throw new RuntimeException("no " + InstallationDescriptorHandler.FILE_TAG + " defined"); String findString = action.params.getProperty(InstallationDescriptorHandler.FIND_STRING_TAG); if (findString == null) throw new RuntimeException("no " + InstallationDescriptorHandler.FIND_STRING_TAG + " defined"); String replaceWith = action.params.getProperty(InstallationDescriptorHandler.REPLACE_WITH_TAG); if (replaceWith == null) throw new RuntimeException("no " + InstallationDescriptorHandler.REPLACE_WITH_TAG + " defined"); // replace all specified path-strings in specified file File inputFile = new File(filePath); FileUtil.replaceStringInFile(inputFile, StringUtil.toRegExpString(findString), replaceWith); }
private static String getText(File each) { try { return org.apache.uima.pear.util.FileUtil.loadTextFile(each, "UTF-8"); } catch (IOException e) { DLTKCore.error(e.getMessage(), e); } return ""; }
File entry = fileList[i]; if (entry.isDirectory()) done = deleteDirectory(entry); else if (!entry.delete()) { entry.deleteOnExit();
/** * Extracts all specified input PEARs to their corresponding folders inside the output root * folder. Returns the total size (bytes) of extracted files. * * @return The total size of extracted files. * @throws IOException * If any I/O exception occurred during extraction. */ private long extractInputPears() throws IOException { long totalSize = 0; for (int i = 0; i < _inpPearFiles.length; i++) { JarFile pearFile = new JarFile(_inpPearFiles[i]); totalSize += FileUtil.extractFilesFromJar(pearFile, _outDlgRootDirs[i]); } return totalSize; }