Example usage for org.apache.commons.io FileUtils toFile

List of usage examples for org.apache.commons.io FileUtils toFile

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils toFile.

Prototype

public static File toFile(URL url) 

Source Link

Document

Convert from a URL to a File.

Usage

From source file:org.apache.flume.sink.graphstore.neo4j.Neo4jWrapper.java

/**
 * Given a chunk of json parse it using Jackson's streaming API and store
 * the nodes and relationships into appropriate objects
 * //from  ww  w  .jav  a 2 s .  c  o m
 * @return true or false based on whether the json was parsed correctly
 */
public boolean parseJson() {
    try {
        File test = FileUtils.toFile(this.getClass().getResource(this.schemaJsonFile));
        JsonParser jParser = jsonFactory.createJsonParser(test);
        // loop until token equal to "}"
        String fieldName = "";
        while (jParser.nextToken() != JsonToken.END_OBJECT) {
            fieldName = jParser.getCurrentName();
            logger.debug("The field name=" + fieldName + " and value=" + jParser.getText());
        }
        jParser.close();

    } catch (JsonGenerationException e) {
        logger.debug("Neo4jWrapper::parseJson caught a JsonGenerationException with message=" + e.getMessage());
    } catch (JsonMappingException e) {
        logger.debug("Neo4jWrapper::parseJson caught a JsonMappingException with message=" + e.getMessage());
    } catch (IOException e) {
        logger.debug("Neo4jWrapper::parseJson caught a IOException with message=" + e.getMessage());
    }
    return true;
}

From source file:org.apache.fop.apps.FOURIResolver.java

/**
 * Checks if the given base URL is acceptable. It also normalizes the URL.
 * @param base the base URL to check/*from w ww. j  a  v a2 s. c o m*/
 * @return the normalized URL
 * @throws MalformedURLException if there's a problem with a file URL
 */
public String checkBaseURL(String base) throws MalformedURLException {
    // replace back slash with forward slash to ensure windows file:/// URLS are supported
    base = base.replace('\\', '/');
    if (!base.endsWith("/")) {
        // The behavior described by RFC 3986 regarding resolution of relative
        // references may be misleading for normal users:
        // file://path/to/resources + myResource.res -> file://path/to/myResource.res
        // file://path/to/resources/ + myResource.res -> file://path/to/resources/myResource.res
        // We assume that even when the ending slash is missing, users have the second
        // example in mind
        base += "/";
    }
    File dir = new File(base);
    if (dir.isDirectory()) {
        return dir.toURI().toASCIIString();
    } else {
        URI baseURI;
        try {
            baseURI = new URI(base);
            String scheme = baseURI.getScheme();
            boolean directoryExists = true;
            if ("file".equals(scheme)) {
                dir = FileUtils.toFile(baseURI.toURL());
                directoryExists = dir.isDirectory();
            }
            if (scheme == null || !directoryExists) {
                String message = "base " + base + " is not a valid directory";
                if (throwExceptions) {
                    throw new MalformedURLException(message);
                }
                log.error(message);
            }
            return baseURI.toASCIIString();
        } catch (URISyntaxException e) {
            //TODO not ideal: our base URLs are actually base URIs.
            throw new MalformedURLException(e.getMessage());
        }
    }
}

From source file:org.apache.fop.fonts.FontCache.java

/**
 * Tries to identify a File instance from an array of URLs. If there's no
 * file URL in the array, the method returns null.
 *
 * @param urls//w w  w .ja  va2 s . c  om
 *            array of possible font urls
 * @return file font file
 */
public static File getFileFromUrls(String[] urls) {
    for (int i = 0; i < urls.length; i++) {
        String urlStr = urls[i];
        if (urlStr != null) {
            File fontFile = null;
            if (urlStr.startsWith("file:")) {
                try {
                    URL url = new URL(urlStr);
                    fontFile = FileUtils.toFile(url);
                } catch (MalformedURLException mfue) {
                    // do nothing
                }
            }
            if (fontFile == null) {
                fontFile = new File(urlStr);
            }
            if (fontFile.exists() && fontFile.canRead()) {
                return fontFile;
            }
        }
    }
    return null;
}

From source file:org.apache.fop.fonts.FontDetector.java

/**
 * Detect installed fonts on the system/*from  w  ww  .ja  v  a2  s . co m*/
 * @param fontInfoList a list of fontinfo to populate
 * @throws FOPException thrown if a problem occurred during detection
 */
public void detect(List<EmbedFontInfo> fontInfoList) throws FOPException {
    // search in font base if it is defined and
    // is a directory but don't recurse
    FontFileFinder fontFileFinder = new FontFileFinder(eventListener);
    String fontBaseURL = fontManager.getFontBaseURL();
    if (fontBaseURL != null) {
        try {
            File fontBase = FileUtils.toFile(new URL(fontBaseURL));
            if (fontBase != null) {
                List<URL> fontURLList = fontFileFinder.find(fontBase.getAbsolutePath());
                fontAdder.add(fontURLList, fontInfoList);

                //Can only use the font base URL if it's a file URL
            }
        } catch (IOException e) {
            LogUtil.handleException(log, e, strict);
        }
    }

    // native o/s font directory finding
    List<URL> systemFontList;
    try {
        systemFontList = fontFileFinder.find();
        fontAdder.add(systemFontList, fontInfoList);
    } catch (IOException e) {
        LogUtil.handleException(log, e, strict);
    }

    // classpath font finding
    ClasspathResource resource = ClasspathResource.getInstance();
    for (int i = 0; i < FONT_MIMETYPES.length; i++) {
        fontAdder.add(resource.listResourcesOfMimeType(FONT_MIMETYPES[i]), fontInfoList);
    }
}

From source file:org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler.java

/** {@inheritDoc} */
public void setResult(Result result) throws IFException {
    if (result instanceof StreamResult) {
        StreamResult streamResult = (StreamResult) result;
        OutputStream out = streamResult.getOutputStream();
        if (out == null) {
            if (streamResult.getWriter() != null) {
                throw new IllegalArgumentException("FOP cannot use a Writer. Please supply an OutputStream!");
            }// w  w  w  . j a  va  2  s .  c  o  m
            try {
                URL url = new URL(streamResult.getSystemId());
                File f = FileUtils.toFile(url);
                if (f != null) {
                    out = new java.io.FileOutputStream(f);
                } else {
                    out = url.openConnection().getOutputStream();
                }
            } catch (IOException ioe) {
                throw new IFException("I/O error while opening output stream", ioe);
            }
            out = new java.io.BufferedOutputStream(out);
            this.ownOutputStream = true;
        }
        if (out == null) {
            throw new IllegalArgumentException("Need a StreamResult with an OutputStream");
        }
        this.outputStream = out;
    } else {
        throw new UnsupportedOperationException("Unsupported Result subclass: " + result.getClass().getName());
    }
}

From source file:org.apache.mahout.freqtermsets.FPGrowthDriver.java

/**
 * Run TopK FPGrowth given the input file,
 *//*  www  .jav  a 2  s  .com*/
@Override
public int run(String[] args) throws Exception {
    addInputOption();
    addOutputOption();

    addOption("minSupport", "s",
            "(Optional) The minimum number of times a co-occurrence must be present." + " Default Value: 3",
            "3");
    addOption("maxHeapSize", "k",
            "(Optional) Maximum Heap Size k, to denote the requirement to mine top K items."
                    + " Default value: 50",
            "50");
    addOption(PFPGrowth.NUM_GROUPS, "g",
            "(Optional) Number of groups the features should be divided in the map-reduce version."
                    + " Doesn't work in sequential version Default Value:" + PFPGrowth.NUM_GROUPS_DEFAULT,
            Integer.toString(PFPGrowth.NUM_GROUPS_DEFAULT));
    // addOption("splitterPattern", "regex",
    // "Regular Expression pattern used to split given string transaction into"
    // + " itemsets. Default value splits comma separated itemsets.  Default Value:"
    // + " \"[ ,\\t]*[,|\\t][ ,\\t]*\" ", "[ ,\t]*[,|\t][ ,\t]*");
    addOption("numTreeCacheEntries", "tc", "(Optional) Number of entries in the tree cache to prevent duplicate"
            + " tree building. (Warning) a first level conditional FP-Tree might consume a lot of memory, "
            + "so keep this value small, but big enough to prevent duplicate tree building. "
            + "Default Value:5 Recommended Values: [5-10]", "5");
    // addOption("method", "method", "Method of processing: sequential|mapreduce", "mapreduce");
    // //"sequential");
    addOption("encoding", "e", "(Optional) The file encoding.  Default value: UTF-8", "UTF-8");
    // addFlag("useFPG2", "2", "Use an alternate FPG implementation");
    addOption(PFPGrowth.COUNT_IN, "cnt",
            "(Optional) In case of mapreduce, if this is set parallel counting will be skipped and counts will be read from the path specified");
    // addFlag(PFPGrowth.PSEUDO, "ps",
    // "Running on a Pseudo-Cluster (one machine). Uses hardcoded configurations for each job.");
    addOption(PFPGrowth.GROUP_FIS_IN, "gfis",
            "(Optional) In case of mapreduce, if this is set execution will start from the aggregation phase, and group dependent frequent itemsets will be read from the path specified");
    addFlag(AggregatorReducer.MUTUAL_INFO_FLAG, "mi",
            "Set to selec the top K patterns based on the Normalized Mutual Information rather than frequency of pattern");
    addOption(ParallelFPGrowthReducer.MIN_WORDS_FOR_LANG_ID, "lid",
            "The mimun length of a pattern that would be used for language identification");
    addOption(PFPGrowth.MIN_FREQ, "mf",
            "The minimum frequency of a token. Any token with less frequency will be pruned from the begining.");
    addOption(PFPGrowth.PRUNE_PCTILE, "pct",
            "The percentile of frequencies that will be considered; any token with a higher frequency will be pruned");
    //    addFlag("shift", "shift", "If set (and window must be set) it shifts the window by half");
    addFlag(TokenIterator.PARAM_REPEAT_HASHTAG, "rht",
            "If set, each hashtag is repeated, removing the # sign from the second token returned for the same hashtag");
    addOption(PFPGrowth.PARAM_INTERVAL_START, "st",
            "The start time of interval to be mined.. defaults to first known tweet time");
    addOption(PFPGrowth.PARAM_INTERVAL_END, "et",
            "The end time of interval to be mined.. defaults to long.maxvalue");
    addOption(PFPGrowth.PARAM_WINDOW_SIZE, "ws",
            "The duration of windows that will be mined.. defaults to end - start");
    addOption(PFPGrowth.PARAM_STEP_SIZE, "ss",
            "The step by which the window will be advanced.. defaults to windowSize");

    addOption(PARAM_NUM_THREADS, "j",
            "The number of PFP jobs, because in case of intervals resources are under utilized");

    // addOption(PFPGrowth.INDEX_OUT,
    // "ix",
    // "The local folder to which the frequent itemset index will be written");

    if (parseArguments(args) == null) {
        return -1;
    }

    Parameters params = new Parameters();

    if (hasOption("minSupport")) {
        String minSupportString = getOption("minSupport");
        params.set("minSupport", minSupportString);
    }
    if (hasOption("maxHeapSize")) {
        String maxHeapSizeString = getOption("maxHeapSize");
        params.set("maxHeapSize", maxHeapSizeString);
    }
    if (hasOption(PFPGrowth.NUM_GROUPS)) {
        String numGroupsString = getOption(PFPGrowth.NUM_GROUPS);
        params.set(PFPGrowth.NUM_GROUPS, numGroupsString);
    }

    if (hasOption("numTreeCacheEntries")) {
        String numTreeCacheString = getOption("numTreeCacheEntries");
        params.set("treeCacheSize", numTreeCacheString);
    }

    // if (hasOption("splitterPattern")) {
    // String patternString = getOption("splitterPattern");
    // params.set("splitPattern", patternString);
    // }

    String encoding = "UTF-8";
    if (hasOption("encoding")) {
        encoding = getOption("encoding");
    }
    params.set("encoding", encoding);

    // if (hasOption("useFPG2")) {
    // params.set(PFPGrowth.USE_FPG2, "true");
    // }

    // if (hasOption(PFPGrowth.COUNT_IN)) {
    // params.set(PFPGrowth.COUNT_IN, getOption(PFPGrowth.COUNT_IN));
    // }

    // if(hasOption(PFPGrowth.PSEUDO)){
    // params.set(PFPGrowth.PSEUDO, "true");
    // }

    // if (hasOption(PFPGrowth.GROUP_FIS_IN)) {
    // params.set(PFPGrowth.GROUP_FIS_IN, getOption(PFPGrowth.GROUP_FIS_IN));
    // }

    if (hasOption(AggregatorReducer.MUTUAL_INFO_FLAG)) {
        params.set(AggregatorReducer.MUTUAL_INFO_FLAG, "true");
    } else {
        params.set(AggregatorReducer.MUTUAL_INFO_FLAG, "false");
    }

    if (hasOption(ParallelFPGrowthReducer.MIN_WORDS_FOR_LANG_ID)) {
        params.set(ParallelFPGrowthReducer.MIN_WORDS_FOR_LANG_ID,
                getOption(ParallelFPGrowthReducer.MIN_WORDS_FOR_LANG_ID));
    }

    if (hasOption(PFPGrowth.MIN_FREQ)) {
        params.set(PFPGrowth.MIN_FREQ, getOption(PFPGrowth.MIN_FREQ));
    }

    if (hasOption(PFPGrowth.PRUNE_PCTILE)) {
        params.set(PFPGrowth.PRUNE_PCTILE, getOption(PFPGrowth.PRUNE_PCTILE));
    }

    // if (hasOption(PFPGrowth.PARAM_INTERVAL_END)) {
    params.set(PFPGrowth.PARAM_INTERVAL_END,
            getOption(PFPGrowth.PARAM_INTERVAL_END, Long.toString(Long.MAX_VALUE)));
    // }

    if (hasOption(PFPGrowth.PARAM_WINDOW_SIZE)) {
        params.set(PFPGrowth.PARAM_WINDOW_SIZE, getOption(PFPGrowth.PARAM_WINDOW_SIZE));
    }

    if (hasOption(PFPGrowth.PARAM_STEP_SIZE)) {
        params.set(PFPGrowth.PARAM_STEP_SIZE, getOption(PFPGrowth.PARAM_STEP_SIZE));
    }

    // if (hasOption(PFPGrowth.PARAM_INTERVAL_START)) {
    // params.set(PFPGrowth.PARAM_INTERVAL_START, getOption(PFPGrowth.PARAM_INTERVAL_START));
    // }

    // if (hasOption(PFPGrowth.INDEX_OUT)) {
    // params.set(PFPGrowth.INDEX_OUT, getOption(PFPGrowth.INDEX_OUT));
    // }

    if (hasOption(TokenIterator.PARAM_REPEAT_HASHTAG)) {
        params.set(TokenIterator.PARAM_REPEAT_HASHTAG, "true");
    }

    //    boolean shiftedWindow = hasOption("shift");

    Path inputDir = getInputPath();
    Path outputDir = getOutputPath();

    params.set(PFPGrowth.INPUT, inputDir.toString());
    params.set(PFPGrowth.OUTROOT, outputDir.toString());

    Configuration conf = new Configuration();
    //    HadoopUtil.delete(conf, outputDir);
    FileSystem fs = FileSystem.get(conf);
    if (fs.exists(outputDir)) {
        throw new IllegalArgumentException(
                "Output path already exists.. please delete it yourself: " + outputDir);
    }

    int nThreads = Integer.parseInt(getOption(PARAM_NUM_THREADS, DEFAULT_NUM_THREADS));
    if (!PFPGrowth.runMode.equals(RunningMode.Batch) && nThreads != 1) {
        throw new UnsupportedOperationException("We use mining results from earlier windows. j must be 1");
    }
    ExecutorService exec = Executors.newFixedThreadPool(nThreads);
    Future<Void> lastFuture = null;

    String startTimeStr = getOption(PFPGrowth.PARAM_INTERVAL_START);
    // params.get(PFPGrowth.PARAM_INTERVAL_START);
    if (startTimeStr == null) {
        // FIXME: Will fail if not running locally.. like many things now
        // FileSystem fs = FileSystem.getLocal(conf);
        // startTimeStr = fs.listStatus(inputDir)[0].getPath().getName();
        File[] startFolders = FileUtils.toFile(inputDir.toUri().toURL()).listFiles();
        Arrays.sort(startFolders);
        startTimeStr = startFolders[0].getName();
    }
    long startTime = Long.parseLong(startTimeStr);
    // Long.toString(PFPGrowth.TREC2011_MIN_TIMESTAMP)));// GMT23JAN2011)));
    long endTime = Long.parseLong(params.get(PFPGrowth.PARAM_INTERVAL_END));
    // Long.toString(Long.MAX_VALUE)));
    long windowSize = Long
            .parseLong(params.get(PFPGrowth.PARAM_WINDOW_SIZE, Long.toString(endTime - startTime)));
    long stepSize = Long.parseLong(params.get(PFPGrowth.PARAM_STEP_SIZE, Long.toString(windowSize)));

    // int numJobs = 0;
    while (startTime < endTime) {
        // if(++numJobs % 100 == 0){
        // Thread.sleep(60000);
        // }
        long shift = 0;
        //      if(shiftedWindow){
        //        shift = (long)Math.floor(windowSize / 2.0f);
        //      }
        params.set(PFPGrowth.PARAM_INTERVAL_START, Long.toString(startTime + shift));

        if (hasOption(PFPGrowth.GROUP_FIS_IN)) {
            String gfisIn = getOption(PFPGrowth.GROUP_FIS_IN);
            gfisIn = FilenameUtils.concat(gfisIn, Long.toString(startTime + shift));
            gfisIn = FilenameUtils.concat(gfisIn,
                    Long.toString(Math.min(endTime, startTime + windowSize) + shift));
            params.set(PFPGrowth.GROUP_FIS_IN, gfisIn);
        }

        if (hasOption(PFPGrowth.COUNT_IN)) {
            String countIn = getOption(PFPGrowth.COUNT_IN);
            //        countIn = FilenameUtils.concat(countIn, Long.toString(startTime + shift));
            //        countIn = FilenameUtils.concat(countIn,
            //            Long.toString(Math.min(endTime, startTime + windowSize) + shift));
            params.set(PFPGrowth.COUNT_IN, countIn);
        }

        String outPathStr = FilenameUtils.concat(outputDir.toString(), Long.toString(startTime + shift));
        outPathStr = FilenameUtils.concat(outPathStr,
                Long.toString(Math.min(endTime, startTime + windowSize) + shift));
        params.set(PFPGrowth.OUTPUT, outPathStr);

        // PFPGrowth.runPFPGrowth(params);
        lastFuture = exec.submit(new PFPGrowth(params));

        //      startTime += windowSize;
        startTime += stepSize;

        //      Thread.sleep(10000);
    }

    lastFuture.get();
    exec.shutdown();

    while (!exec.isTerminated()) {
        Thread.sleep(1000);
    }

    return 0;
}

From source file:org.apache.mahout.freqtermsets.ParallelFPStreamReducer.java

@Override
protected void setup(Context context) throws IOException, InterruptedException {

    super.setup(context);
    Configuration conf = context.getConfiguration();
    Parameters params = new Parameters(conf.get(PFPGrowth.PFP_PARAMETERS, ""));

    intervalStart = Long.parseLong(params.get(PFPGrowth.PARAM_INTERVAL_START));
    intervalEnd = Long.parseLong(params.get(PFPGrowth.PARAM_INTERVAL_END));
    windowSize = Long// ww  w  .ja v  a  2s.co m
            .parseLong(params.get(PFPGrowth.PARAM_WINDOW_SIZE, Long.toString(intervalEnd - intervalStart)));
    endTimestamp = Math.min(intervalEnd, intervalStart + windowSize - 1);

    PFPGrowth.loadEarlierFHashMaps(context, params, intervalStart, idStringMap, stringIdMap);

    maxHeapSize = Integer.valueOf(params.get(PFPGrowth.MAX_HEAPSIZE, "50"));
    minSupport = Integer.valueOf(params.get(PFPGrowth.MIN_SUPPORT, "3"));

    numGroups = params.getInt(PFPGrowth.NUM_GROUPS, PFPGrowth.NUM_GROUPS_DEFAULT);

    minWordsForLangDetection = params.getInt(MIN_WORDS_FOR_LANG_ID, MIN_WORDS_FOR_LANG_ID_DEFAULT);
    repeatHashTag = Boolean.parseBoolean(params.get(TokenIterator.PARAM_REPEAT_HASHTAG, "false"));

    long maxPatternLoadLag = Long.parseLong(
            params.get(PFPGrowth.PARAM_MAX_PATTERN_LOAD_LAG, PFPGrowth.DEFAULT_MAX_PATTERN_LOAD_LAG));

    Path mostRecentPath = null;
    Path outPath = new Path(params.get(PFPGrowth.OUTPUT));
    Path timeRoot = outPath.getParent().getParent();
    FileSystem fs = FileSystem.get(conf);
    FileStatus[] otherWindows = fs.listStatus(timeRoot);
    //    List<IndexReader> earlierIndexes = Lists
    //        .<IndexReader> newArrayListWithCapacity(otherWindows.length - 1);
    for (int f = otherWindows.length - 1; f >= 0; --f) {
        Path p = otherWindows[f].getPath();
        long pathStartTime = Long.parseLong(p.getName());
        // should have used end time, but it doesn't make a difference,
        // AS LONG AS windows don't overlap
        //      long timeDifference = intervalStart - pathStartTime;
        //      if (timeDifference > 0 && timeDifference <= maxPatternLoadLag) {
        if (pathStartTime < intervalStart && pathStartTime > mostRecentTime) {
            p = fs.listStatus(p)[0].getPath();
            p = new Path(p, "index");
            if (fs.exists(p)) {
                mostRecentTime = pathStartTime;
                mostRecentPath = p;
                //          File indexDir = FileUtils.toFile(p.toUri().toURL());
                //          // FIXME: this will work only on local filesystem.. like many other parts of the code
                //          Directory fisdir = new MMapDirectory(indexDir);
                //          IndexReader fisIxReader = IndexReader.open(fisdir);
                //          earlierIndexes.add(fisIxReader);
            }
        }
    }
    if (mostRecentPath != null) {
        //    if(!earlierIndexes.isEmpty()) {
        //      fisIxMultiReader = new MultiReader(earlierIndexes.toArray(new IndexReader[0]));
        Directory fisdir = new MMapDirectory(FileUtils.toFile(mostRecentPath.toUri().toURL()));
        fisIxReader = IndexReader.open(fisdir);
        //      fisSearcher = new IndexSearcher(fisIxMultiReader);
        fisSearcher = new IndexSearcher(fisIxReader);
        fisSimilarity = new ItemSetSimilarity();
        fisSearcher.setSimilarity(fisSimilarity);

        fisQparser = new QueryParser(Version.LUCENE_36, ItemSetIndexBuilder.AssocField.ITEMSET.name, ANALYZER);
        fisQparser.setDefaultOperator(Operator.AND);

        timeWeigth = TimeWeightFunction.getDefault(params);
    }
}

From source file:org.apache.mahout.freqtermsets.PFPGrowth.java

/**
 * /*from   ww w .jav  a  2s.  co m*/
 * @param params
 *          params should contain input and output locations as a string value, the additional
 *          parameters include minSupport(3), maxHeapSize(50), numGroups(1000)
 * @throws NoSuchAlgorithmException
 * @throws ParseException
 */
public static void runPFPGrowth(Parameters params) throws IOException, InterruptedException,
        ClassNotFoundException, NoSuchAlgorithmException, ParseException {
    Configuration conf = new Configuration();
    conf.set("io.serializations", "org.apache.hadoop.io.serializer.JavaSerialization,"
            + "org.apache.hadoop.io.serializer.WritableSerialization");

    long startTime = Long.parseLong(params.get(PFPGrowth.PARAM_INTERVAL_START));
    long endTime = Long.parseLong(params.get(PFPGrowth.PARAM_INTERVAL_END));
    long windowSize = Long
            .parseLong(params.get(PFPGrowth.PARAM_WINDOW_SIZE, Long.toString(endTime - startTime)));
    long stepSize = Long.parseLong(params.get(PFPGrowth.PARAM_STEP_SIZE, Long.toString(windowSize)));
    endTime = Math.min(endTime, startTime + windowSize);

    int minSupport = Integer.valueOf(params.get(MIN_SUPPORT, "3"));
    String countIn = params.get(COUNT_IN);
    if (countIn == null) {
        countIn = params.get(OUTROOT); // PUT);
    }
    int minFr = params.getInt(MIN_FREQ, MIN_FREQ_DEFAULT);
    int prunePct = params.getInt(PRUNE_PCTILE, PRUNE_PCTILE_DEFAULT);

    if (params.get(COUNT_IN) == null) {
        startParallelCounting(params, conf);
    }

    if (params.get(GROUP_FIS_IN) == null) {
        // save feature list to dcache
        // List<Pair<String, Long>> fList = readFList(params);
        // saveFList(fList, params, conf);

        int fListSize = cacheFList(params, conf, countIn, minSupport, minFr, prunePct);

        if (runMode.equals(RunningMode.BlockUpdate)) {
            fListSize = -1;
            Path timeRoot = new Path(countIn).getParent().getParent();
            FileSystem fs = FileSystem.getLocal(conf);
            final long currStartTime = startTime;
            for (FileStatus earlierWindow : fs.listStatus(timeRoot, new PathFilter() {
                @Override
                public boolean accept(Path p) {
                    // should have used end time, but it doesn't make a difference,
                    // AS LONG AS windows don't overlap
                    return Long.parseLong(p.getName()) < currStartTime;
                }
            })) {
                // TODO: At such low frequency and support, does pruning out items with less frequency
                // than minFreq cause loosing itemsets that are frequent but through a longer time frame
                cacheFList(params, conf, fs.listStatus(earlierWindow.getPath())[0].getPath().toString(),
                        minSupport, minFr, prunePct);
            }
        } else {
            // set param to control group size in MR jobs
            int numGroups = params.getInt(PFPGrowth.NUM_GROUPS, PFPGrowth.NUM_GROUPS_DEFAULT);
            int maxPerGroup = fListSize / numGroups;
            if (fListSize % numGroups != 0)
                maxPerGroup++;
            params.set(MAX_PER_GROUP, Integer.toString(maxPerGroup));
        }
        // fList = null;

        startParallelFPGrowth(params, conf);
    } else {
        cacheFList(params, conf, countIn, minSupport, minFr, prunePct);
    }
    startAggregating(params, conf);

    if (runMode.equals(RunningMode.BlockUpdate)) {
        String indexDirStr;// = params.get(INDEX_OUT);
        // if (indexDirStr == null || indexDirStr.isEmpty()) {
        indexDirStr = FilenameUtils.concat(params.get(OUTPUT), "index");
        // } else {
        // indexDirStr = FilenameUtils.concat(indexDirStr, startTime);
        // indexDirStr = FilenameUtils.concat(indexDirStr, endTime);
        // }
        File indexDir = FileUtils.toFile(new URL(indexDirStr));

        // clean up
        FileUtils.deleteQuietly(indexDir);

        Path seqPath = new Path(params.get(OUTPUT), FREQUENT_PATTERNS);
        Directory earlierIndex = null;

        Path timeRoot = new Path(params.get(OUTPUT)).getParent().getParent();
        FileSystem fs = FileSystem.getLocal(conf);

        long mostRecent = Long.MIN_VALUE;
        Path mostRecentPath = null;
        for (FileStatus earlierWindow : fs.listStatus(timeRoot)) {
            long earlierStart = Long.parseLong(earlierWindow.getPath().getName());
            // should have used end time, but it doesn't make a difference,
            // AS LONG AS windows don't overlap
            if (earlierStart < startTime && earlierStart > mostRecent) {
                mostRecentPath = earlierWindow.getPath();
                mostRecent = earlierStart;
            }
        }
        if (mostRecentPath != null) {
            mostRecentPath = fs.listStatus(mostRecentPath)[0].getPath();
            mostRecentPath = new Path(mostRecentPath, "index");
            // earlierIndex = new Directory[1];
            // FIXME: as with anything that involves lucene.. won't work except on a local machine
            earlierIndex = new MMapDirectory(FileUtils.toFile(mostRecentPath.toUri().toURL()));
        }
    }
    // FIXME: When we want to stream, we have to build the index of earlier window
    // ItemSetIndexBuilder.buildIndex(seqPath, indexDir,
    // startTime, Math.min(endTime, startTime + windowSize), earlierIndex);
}

From source file:org.apache.struts2.jasper.compiler.TldLocationsCache.java

/**
 * Returns a list of absolute paths of the locations in the cache
 *///  ww w  . j  a  v  a  2 s.c  om
public Set<String> getAbsolutePathsOfLocations() {
    Set<String> paths = new HashSet<String>(mappings.size());
    for (Object value : mappings.values()) {
        String[] location = (String[]) value;

        try {
            File file = FileUtils.toFile(new URL(location[0]));
            paths.add(file.getAbsolutePath());
        } catch (Exception e) {
            //ignore
        }
    }
    return paths;
}

From source file:org.apache.struts2.JSPLoader.java

/**
 * Compiles the given source code into java bytecode
 *///from  ww w.  ja  v a 2 s .c  o  m
private void compileJava(String className, final String source, Set<String> extraClassPath) throws IOException {
    if (LOG.isTraceEnabled())
        LOG.trace("Compiling [#0], source: [#1]", className, source);

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

    DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();

    //the generated bytecode is fed to the class loader
    JavaFileManager jfm = new ForwardingJavaFileManager<StandardJavaFileManager>(
            compiler.getStandardFileManager(diagnostics, null, null)) {

        @Override
        public JavaFileObject getJavaFileForOutput(Location location, String name, JavaFileObject.Kind kind,
                FileObject sibling) throws IOException {
            MemoryJavaFileObject fileObject = new MemoryJavaFileObject(name, kind);
            classLoader.addMemoryJavaFileObject(name, fileObject);
            return fileObject;
        }
    };

    //read java source code from memory
    String fileName = className.replace('.', '/') + ".java";
    SimpleJavaFileObject sourceCodeObject = new SimpleJavaFileObject(toURI(fileName),
            JavaFileObject.Kind.SOURCE) {
        @Override
        public CharSequence getCharContent(boolean ignoreEncodingErrors)
                throws IOException, IllegalStateException, UnsupportedOperationException {
            return source;
        }

    };

    //build classpath
    //some entries will be added multiple times, hence the set
    List<String> optionList = new ArrayList<String>();
    Set<String> classPath = new HashSet<String>();

    FileManager fileManager = ServletActionContext.getContext().getInstance(FileManagerFactory.class)
            .getFileManager();

    //find available jars
    ClassLoaderInterface classLoaderInterface = getClassLoaderInterface();
    UrlSet urlSet = new UrlSet(classLoaderInterface);

    //find jars
    List<URL> urls = urlSet.getUrls();

    for (URL url : urls) {
        URL normalizedUrl = fileManager.normalizeToFileProtocol(url);
        File file = FileUtils.toFile(ObjectUtils.defaultIfNull(normalizedUrl, url));
        if (file.exists())
            classPath.add(file.getAbsolutePath());
    }

    //these should be in the list already, but I am feeling paranoid
    //this jar
    classPath.add(getJarUrl(EmbeddedJSPResult.class));
    //servlet api
    classPath.add(getJarUrl(Servlet.class));
    //jsp api
    classPath.add(getJarUrl(JspPage.class));

    try {
        Class annotationsProcessor = Class.forName("org.apache.AnnotationProcessor");
        classPath.add(getJarUrl(annotationsProcessor));
    } catch (ClassNotFoundException e) {
        //ok ignore
    }

    //add extra classpath entries (jars where tlds were found will be here)
    for (Iterator<String> iterator = extraClassPath.iterator(); iterator.hasNext();) {
        String entry = iterator.next();
        classPath.add(entry);
    }

    String classPathString = StringUtils.join(classPath, File.pathSeparator);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Compiling [#0] with classpath [#1]", className, classPathString);
    }

    optionList.addAll(Arrays.asList("-classpath", classPathString));

    //compile
    JavaCompiler.CompilationTask task = compiler.getTask(null, jfm, diagnostics, optionList, null,
            Arrays.asList(sourceCodeObject));

    if (!task.call()) {
        throw new StrutsException("Compilation failed:" + diagnostics.getDiagnostics().get(0).toString());
    }
}