Example usage for java.util Stack pop

List of usage examples for java.util Stack pop

Introduction

In this page you can find the example usage for java.util Stack pop.

Prototype

public synchronized E pop() 

Source Link

Document

Removes the object at the top of this stack and returns that object as the value of this function.

Usage

From source file:ar.com.zauber.commons.spring.servlet.mvc.support.ZauberBeanNameBasedClassNameHandlerMapping.java

/**
 * <ul>//  w  w  w  . j a  v a 2  s . c  om
 * <li>ChangePassword -> password/change</li>
 * <li>changePassword -> password/change</li>
 * <li>login -> login</li>
 * </ul>
 * 
 */
protected final String getCompoundPath(final String s) {
    final Stack<String> stack = new Stack<String>();
    final int n = s.length();
    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < n; i++) {
        final char c = s.charAt(i);

        if (Character.isUpperCase(c)) {
            if (sb.length() > 0) {
                stack.push(sb.toString());
                sb = new StringBuilder();
            }
            sb.append(Character.toLowerCase(c));
        } else {
            sb.append(c);
        }
    }

    if (sb.length() > 0) {
        stack.push(sb.toString());
        sb = new StringBuilder();
    }

    while (!stack.isEmpty()) {
        sb.append(stack.pop());
        sb.append('/');
    }

    return sb.toString();
}

From source file:org.apache.synapse.endpoints.AbstractEndpoint.java

private void invokeNextFaultHandler(MessageContext synCtx) {

    Stack faultStack = synCtx.getFaultStack();
    if (!faultStack.isEmpty()) {
        Object faultHandler = faultStack.pop();
        if (faultHandler instanceof Endpoint) {
            // This is the parent . need to inform parent with fault child
            ((Endpoint) faultHandler).onChildEndpointFail(this, synCtx);
        } else {/*from w  w  w .  j a va  2  s  .  c  o m*/
            ((FaultHandler) faultHandler).handleFault(synCtx);
        }
    }
}

From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultTreeView.java

private TreePath getTreePath(TreePath currentPath, ViewState state) {
    String lookingForPath = state.getCurrentMetGroup();
    Stack<DefaultMutableTreeNode> stack = new Stack<DefaultMutableTreeNode>();
    DefaultMutableTreeNode baseNode = (DefaultMutableTreeNode) currentPath.getLastPathComponent();
    for (int i = 0; i < baseNode.getChildCount(); i++) {
        stack.push((DefaultMutableTreeNode) baseNode.getChildAt(i));
    }//w w  w . j  av  a2  s . co  m
    while (!stack.empty()) {
        DefaultMutableTreeNode node = stack.pop();
        if (node.getUserObject().equals("static-metadata")) {
            for (int i = 0; i < node.getChildCount(); i++) {
                stack.push((DefaultMutableTreeNode) node.getChildAt(i));
            }
        } else if (node.getUserObject() instanceof ConcurrentHashMap) {
            String key = (String) ((ConcurrentHashMap<String, String>) node.getUserObject()).keySet().iterator()
                    .next();
            if (lookingForPath.equals(key)) {
                return new TreePath(node.getPath());
            } else if (lookingForPath.startsWith(key + "/")) {
                lookingForPath = lookingForPath.substring(lookingForPath.indexOf("/") + 1);
                stack.clear();
                for (int i = 0; i < node.getChildCount(); i++) {
                    stack.add((DefaultMutableTreeNode) node.getChildAt(i));
                }
            }
        }
    }
    return currentPath;
}

From source file:edu.kit.dama.mdm.dataorganization.impl.jpa.DataOrganizerImpl.java

/**
 * Build a tree for a digital object id from a list of DataOrganizationNode
 * obtained from a data source./*from www.ja v a2 s  .c  o  m*/
 *
 * @param nodes The list of nodes.
 * @param digitalObjectID The digital object id the tree is associated with.
 *
 * @return The tree.
 */
private FileTree buildTree(List<DataOrganizationNode> nodes, DigitalObjectId digitalObjectID) {

    FileTree tree = null;
    if (!nodes.isEmpty()) {
        Stack<DataOrganizationNode> stack = new Stack<>();
        DataOrganizationNode node = nodes.get(0);
        if (!(node instanceof CollectionNode)) {
            return null;
        }
        tree = new FileTree((CollectionNode) node);
        tree.setDigitalObjectId(digitalObjectID);
        node = tree;
        stack.push(node);
        DataOrganizationNode nextNode;
        for (int i = 1; i < nodes.size(); ++i) {
            nextNode = nodes.get(i);
            while (stack.peek().getStepNoLeaved() < nextNode.getStepNoLeaved()) {
                stack.pop();
            }
            node = stack.peek();
            ((CollectionNode) node).addChild(nextNode);
            stack.push(nextNode);
        }
    }
    return tree;
}

From source file:com.autsia.bracer.BracerParser.java

/**
 * Evaluates once parsed math expression with "var" variable included
 *
 * @param variableValue User-specified <code>Double</code> value
 * @return <code>String</code> representation of the result
 * @throws <code>ParseException</code> if the input expression is not
 *                                     correct
 * @since 3.0/*  w  w  w . j ava  2 s . com*/
 */
public String evaluate(double variableValue) throws ParseException {
    /* check if is there something to evaluate */
    if (stackRPN.empty()) {
        return "";
    }

    /* clean answer stack */
    stackAnswer.clear();

    /* get the clone of the RPN stack for further evaluating */
    @SuppressWarnings("unchecked")
    Stack<String> stackRPN = (Stack<String>) this.stackRPN.clone();

    /* enroll the variable value into expression */
    Collections.replaceAll(stackRPN, VARIABLE, Double.toString(variableValue));

    /* evaluating the RPN expression */
    while (!stackRPN.empty()) {
        String token = stackRPN.pop();
        if (isNumber(token)) {
            stackAnswer.push(token);
        } else if (isOperator(token)) {
            Complex a = complexFormat.parse(stackAnswer.pop());
            Complex b = complexFormat.parse(stackAnswer.pop());
            boolean aBoolean = a.getReal() == 1.0;
            boolean bBoolean = b.getReal() == 1.0;
            switch (token) {
            case "+":
                stackAnswer.push(complexFormat.format(b.add(a)));
                break;
            case "-":
                stackAnswer.push(complexFormat.format(b.subtract(a)));
                break;
            case "*":
                stackAnswer.push(complexFormat.format(b.multiply(a)));
                break;
            case "/":
                stackAnswer.push(complexFormat.format(b.divide(a)));
                break;
            case "|":
                stackAnswer.push(String.valueOf(aBoolean || bBoolean ? "1" : "0"));
                break;
            case "&":
                stackAnswer.push(String.valueOf(aBoolean && bBoolean ? "1" : "0"));
                break;
            }
        } else if (isFunction(token)) {
            Complex a = complexFormat.parse(stackAnswer.pop());
            boolean aBoolean = a.getReal() == 1.0;
            switch (token) {
            case "abs":
                stackAnswer.push(complexFormat.format(a.abs()));
                break;
            case "acos":
                stackAnswer.push(complexFormat.format(a.acos()));
                break;
            case "arg":
                stackAnswer.push(complexFormat.format(a.getArgument()));
                break;
            case "asin":
                stackAnswer.push(complexFormat.format(a.asin()));
                break;
            case "atan":
                stackAnswer.push(complexFormat.format(a.atan()));
                break;
            case "conj":
                stackAnswer.push(complexFormat.format(a.conjugate()));
                break;
            case "cos":
                stackAnswer.push(complexFormat.format(a.cos()));
                break;
            case "cosh":
                stackAnswer.push(complexFormat.format(a.cosh()));
                break;
            case "exp":
                stackAnswer.push(complexFormat.format(a.exp()));
                break;
            case "imag":
                stackAnswer.push(complexFormat.format(a.getImaginary()));
                break;
            case "log":
                stackAnswer.push(complexFormat.format(a.log()));
                break;
            case "neg":
                stackAnswer.push(complexFormat.format(a.negate()));
                break;
            case "real":
                stackAnswer.push(complexFormat.format(a.getReal()));
                break;
            case "sin":
                stackAnswer.push(complexFormat.format(a.sin()));
                break;
            case "sinh":
                stackAnswer.push(complexFormat.format(a.sinh()));
                break;
            case "sqrt":
                stackAnswer.push(complexFormat.format(a.sqrt()));
                break;
            case "tan":
                stackAnswer.push(complexFormat.format(a.tan()));
                break;
            case "tanh":
                stackAnswer.push(complexFormat.format(a.tanh()));
                break;
            case "pow":
                Complex b = complexFormat.parse(stackAnswer.pop());
                stackAnswer.push(complexFormat.format(b.pow(a)));
                break;
            case "not":
                stackAnswer.push(String.valueOf(!aBoolean ? "1" : "0"));
                break;
            }
        }
    }

    if (stackAnswer.size() > 1) {
        throw new ParseException("Some operator is missing", 0);
    }

    return stackAnswer.pop();
}

From source file:com.calc.BracerParser.java

/**
 * Evaluates once parsed math expression with "var" variable included
 *
 * @param variableValue User-specified <code>Double</code> value
 * @return <code>String</code> representation of the result
 * @throws <code>ParseException</code> if the input expression is not
 *                                     correct
 * @since 3.0//from ww  w.  j  av  a2  s .  c  o  m
 */
public String evaluate(double variableValue) throws ParseException {
    /* check if is there something to evaluate */
    if (stackRPN.empty()) {
        return "";
    }

    /* clean answer stack */
    stackAnswer.clear();

    /* get the clone of the RPN stack for further evaluating */
    @SuppressWarnings("unchecked")
    Stack<String> stackRPN = (Stack<String>) this.stackRPN.clone();

    /* enroll the variable value into expression */
    Collections.replaceAll(stackRPN, VARIABLE, Double.toString(variableValue));

    /* evaluating the RPN expression */
    while (!stackRPN.empty()) {
        String token = stackRPN.pop();
        if (isNumber(token)) {
            stackAnswer.push(token);
        } else if (isOperator(token)) {
            Complex a = complexFormat.parse(stackAnswer.pop());
            Complex b = complexFormat.parse(stackAnswer.pop());
            boolean aBoolean = a.getReal() == 1.0;
            boolean bBoolean = b.getReal() == 1.0;
            switch (token) {
            case "+":
                stackAnswer.push(complexFormat.format(b.add(a)));
                break;
            case "-":
                stackAnswer.push(complexFormat.format(b.subtract(a)));
                break;
            case "*":
                stackAnswer.push(complexFormat.format(b.multiply(a)));
                break;
            case "/":
                stackAnswer.push(complexFormat.format(b.divide(a)));
                break;
            case "|":
                stackAnswer.push(String.valueOf(aBoolean || bBoolean ? "1" : "0"));
                break;
            case "&":
                stackAnswer.push(String.valueOf(aBoolean && bBoolean ? "1" : "0"));
                break;
            }
        } else if (isFunction(token)) {
            Complex a = complexFormat.parse(stackAnswer.pop());
            boolean aBoolean = a.getReal() == 1.0;
            switch (token) {
            case "fat":
                stackAnswer.push(complexFormat.format(a.abs()));
                break;
            case "fib":
                stackAnswer.push(complexFormat.format(a.acos()));
                break;
            case "arg":
                stackAnswer.push(complexFormat.format(a.getArgument()));
                break;
            case "asin":
                stackAnswer.push(complexFormat.format(a.asin()));
                break;
            case "atan":
                stackAnswer.push(complexFormat.format(a.atan()));
                break;
            case "conj":
                stackAnswer.push(complexFormat.format(a.conjugate()));
                break;
            case "cos":
                stackAnswer.push(complexFormat.format(a.cos()));
                break;
            case "cosh":
                stackAnswer.push(complexFormat.format(a.cosh()));
                break;
            case "exp":
                stackAnswer.push(complexFormat.format(a.exp()));
                break;
            case "imag":
                stackAnswer.push(complexFormat.format(a.getImaginary()));
                break;
            case "log":
                stackAnswer.push(complexFormat.format(a.log()));
                break;
            case "neg":
                stackAnswer.push(complexFormat.format(a.negate()));
                break;
            case "real":
                stackAnswer.push(complexFormat.format(a.getReal()));
                break;
            case "sin":
                stackAnswer.push(complexFormat.format(a.sin()));
                break;
            case "sinh":
                stackAnswer.push(complexFormat.format(a.sinh()));
                break;
            case "sqrt":
                stackAnswer.push(complexFormat.format(a.sqrt()));
                break;
            case "tan":
                stackAnswer.push(complexFormat.format(a.tan()));
                break;
            case "tanh":
                stackAnswer.push(complexFormat.format(a.tanh()));
                break;
            case "pow":
                Complex b = complexFormat.parse(stackAnswer.pop());
                stackAnswer.push(complexFormat.format(b.pow(a)));
                break;
            case "not":
                stackAnswer.push(String.valueOf(!aBoolean ? "1" : "0"));
                break;
            }
        }
    }

    if (stackAnswer.size() > 1) {
        throw new ParseException("Some operator is missing", 0);
    }

    return stackAnswer.pop();
}

From source file:gdt.jgui.entity.folder.JFolderPanel.java

/**
 * Execute the response locator.//from  www . j  a v a  2s  .  c o m
 * @param console the main console.
 * @param locator$ the locator string.
 */
@Override
public void response(JMainConsole console, String locator$) {
    try {
        //         System.out.println("FolderPanel:response:locator="+locator$);
        Properties locator = Locator.toProperties(locator$);
        String action$ = locator.getProperty(JRequester.REQUESTER_ACTION);
        if (ACTION_CREATE_FILE.equals(action$)) {
            String entihome$ = locator.getProperty(Entigrator.ENTIHOME);
            String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
            String text$ = locator.getProperty(JTextEditor.TEXT);
            File file = new File(entihome$ + "/" + entityKey$ + "/" + text$);
            if (!file.exists())
                file.createNewFile();
            locator$ = Locator.remove(locator$, JRequester.REQUESTER_ACTION);
            JConsoleHandler.execute(console, locator$);
        }
        if (ACTION_EDIT_FILE.equals(action$)) {
            String filePath$ = locator.getProperty(FILE_PATH);
            String text$ = locator.getProperty(JTextEditor.TEXT);
            File file = new File(filePath$);
            if (!file.exists())
                file.createNewFile();
            FileOutputStream fos = new FileOutputStream(file, false);
            Writer writer = new OutputStreamWriter(fos, "UTF-8");
            writer.write(text$);
            writer.close();
            fos.close();
            locator$ = Locator.remove(locator$, JRequester.REQUESTER_ACTION);
            JConsoleHandler.execute(console, locator$);
        }
        if (ACTION_CREATE_FOLDER.equals(action$)) {
            String entihome$ = locator.getProperty(Entigrator.ENTIHOME);
            String text$ = locator.getProperty(JTextEditor.TEXT);
            Entigrator entigrator = console.getEntigrator(entihome$);
            Sack folder = entigrator.ent_new("folder", text$);
            folder = entigrator.ent_assignProperty(folder, "folder", folder.getProperty("label"));
            folder.putAttribute(new Core(null, "icon", "folder.png"));
            entigrator.save(folder);
            entigrator.saveHandlerIcon(JFolderPanel.class, "folder.png");
            entityKey$ = folder.getKey();
            File folderHome = new File(entihome$ + "/" + entityKey$);
            if (!folderHome.exists())
                folderHome.mkdir();
            JFolderPanel fp = new JFolderPanel();
            String fLocator$ = fp.getLocator();
            fLocator$ = Locator.append(fLocator$, Entigrator.ENTIHOME, entihome$);
            fLocator$ = Locator.append(fLocator$, EntityHandler.ENTITY_KEY, entityKey$);

            JEntityPrimaryMenu.reindexEntity(console, fLocator$);
            Stack<String> s = console.getTrack();
            s.pop();
            console.setTrack(s);
            JConsoleHandler.execute(console, fLocator$);
        }

    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }

}

From source file:org.apache.hadoop.tools.DistCpV1.java

/**
 * Initialize DFSCopyFileMapper specific job-configuration.
 * @param conf : The dfs/mapred configuration.
 * @param jobConf : The handle to the jobConf object to be initialized.
 * @param args Arguments//  w w  w . j  a v a  2 s  .co  m
 * @return true if it is necessary to launch a job.
 */
static boolean setup(Configuration conf, JobConf jobConf, final Arguments args) throws IOException {
    jobConf.set(DST_DIR_LABEL, args.dst.toUri().toString());

    //set boolean values
    final boolean update = args.flags.contains(Options.UPDATE);
    final boolean skipCRCCheck = args.flags.contains(Options.SKIPCRC);
    final boolean overwrite = !update && args.flags.contains(Options.OVERWRITE) && !args.dryrun;
    jobConf.setBoolean(Options.UPDATE.propertyname, update);
    jobConf.setBoolean(Options.SKIPCRC.propertyname, skipCRCCheck);
    jobConf.setBoolean(Options.OVERWRITE.propertyname, overwrite);
    jobConf.setBoolean(Options.IGNORE_READ_FAILURES.propertyname,
            args.flags.contains(Options.IGNORE_READ_FAILURES));
    jobConf.setBoolean(Options.PRESERVE_STATUS.propertyname, args.flags.contains(Options.PRESERVE_STATUS));

    final String randomId = getRandomId();
    JobClient jClient = new JobClient(jobConf);
    Path stagingArea;
    try {
        stagingArea = JobSubmissionFiles.getStagingDir(jClient.getClusterHandle(), conf);
    } catch (InterruptedException ie) {
        throw new IOException(ie);
    }

    Path jobDirectory = new Path(stagingArea + NAME + "_" + randomId);
    FsPermission mapredSysPerms = new FsPermission(JobSubmissionFiles.JOB_DIR_PERMISSION);
    FileSystem.mkdirs(jClient.getFs(), jobDirectory, mapredSysPerms);
    jobConf.set(JOB_DIR_LABEL, jobDirectory.toString());

    long maxBytesPerMap = conf.getLong(BYTES_PER_MAP_LABEL, BYTES_PER_MAP);

    FileSystem dstfs = args.dst.getFileSystem(conf);

    // get tokens for all the required FileSystems..
    TokenCache.obtainTokensForNamenodes(jobConf.getCredentials(), new Path[] { args.dst }, conf);

    boolean dstExists = dstfs.exists(args.dst);
    boolean dstIsDir = false;
    if (dstExists) {
        dstIsDir = dstfs.getFileStatus(args.dst).isDirectory();
    }

    // default logPath
    Path logPath = args.log;
    if (logPath == null) {
        String filename = "_distcp_logs_" + randomId;
        if (!dstExists || !dstIsDir) {
            Path parent = args.dst.getParent();
            if (null == parent) {
                // If dst is '/' on S3, it might not exist yet, but dst.getParent()
                // will return null. In this case, use '/' as its own parent to prevent
                // NPE errors below.
                parent = args.dst;
            }
            if (!dstfs.exists(parent)) {
                dstfs.mkdirs(parent);
            }
            logPath = new Path(parent, filename);
        } else {
            logPath = new Path(args.dst, filename);
        }
    }
    FileOutputFormat.setOutputPath(jobConf, logPath);

    // create src list, dst list
    FileSystem jobfs = jobDirectory.getFileSystem(jobConf);

    Path srcfilelist = new Path(jobDirectory, "_distcp_src_files");
    Path dstfilelist = new Path(jobDirectory, "_distcp_dst_files");
    Path dstdirlist = new Path(jobDirectory, "_distcp_dst_dirs");
    jobConf.set(SRC_LIST_LABEL, srcfilelist.toString());
    jobConf.set(DST_DIR_LIST_LABEL, dstdirlist.toString());
    int srcCount = 0, cnsyncf = 0, dirsyn = 0;
    long fileCount = 0L, dirCount = 0L, byteCount = 0L, cbsyncs = 0L, skipFileCount = 0L, skipByteCount = 0L;
    try (SequenceFile.Writer src_writer = SequenceFile.createWriter(jobConf, Writer.file(srcfilelist),
            Writer.keyClass(LongWritable.class), Writer.valueClass(FilePair.class),
            Writer.compression(SequenceFile.CompressionType.NONE));
            SequenceFile.Writer dst_writer = SequenceFile.createWriter(jobConf, Writer.file(dstfilelist),
                    Writer.keyClass(Text.class), Writer.valueClass(Text.class),
                    Writer.compression(SequenceFile.CompressionType.NONE));
            SequenceFile.Writer dir_writer = SequenceFile.createWriter(jobConf, Writer.file(dstdirlist),
                    Writer.keyClass(Text.class), Writer.valueClass(FilePair.class),
                    Writer.compression(SequenceFile.CompressionType.NONE));) {
        // handle the case where the destination directory doesn't exist
        // and we've only a single src directory OR we're updating/overwriting
        // the contents of the destination directory.
        final boolean special = (args.srcs.size() == 1 && !dstExists) || update || overwrite;

        Path basedir = null;
        HashSet<Path> parentDirsToCopy = new HashSet<Path>();
        if (args.basedir != null) {
            FileSystem basefs = args.basedir.getFileSystem(conf);
            basedir = args.basedir.makeQualified(basefs.getUri(), basefs.getWorkingDirectory());
            if (!basefs.isDirectory(basedir)) {
                throw new IOException("Basedir " + basedir + " is not a directory.");
            }
        }

        for (Iterator<Path> srcItr = args.srcs.iterator(); srcItr.hasNext();) {
            final Path src = srcItr.next();
            FileSystem srcfs = src.getFileSystem(conf);
            FileStatus srcfilestat = srcfs.getFileStatus(src);
            Path root = special && srcfilestat.isDirectory() ? src : src.getParent();
            if (dstExists && !dstIsDir && (args.srcs.size() > 1 || srcfilestat.isDirectory())) {
                // destination should not be a file
                throw new IOException("Destination " + args.dst + " should be a dir"
                        + " if multiple source paths are there OR if" + " the source path is a dir");
            }

            if (basedir != null) {
                root = basedir;
                Path parent = src.getParent().makeQualified(srcfs.getUri(), srcfs.getWorkingDirectory());
                while (parent != null && !parent.equals(basedir)) {
                    if (!parentDirsToCopy.contains(parent)) {
                        parentDirsToCopy.add(parent);
                        String dst = makeRelative(root, parent);
                        FileStatus pst = srcfs.getFileStatus(parent);
                        src_writer.append(new LongWritable(0), new FilePair(pst, dst));
                        dst_writer.append(new Text(dst), new Text(parent.toString()));
                        dir_writer.append(new Text(dst), new FilePair(pst, dst));
                        if (++dirsyn > SYNC_FILE_MAX) {
                            dirsyn = 0;
                            dir_writer.sync();
                        }
                    }
                    parent = parent.getParent();
                }

                if (parent == null) {
                    throw new IOException("Basedir " + basedir + " is not a prefix of source path " + src);
                }
            }

            if (srcfilestat.isDirectory()) {
                ++srcCount;
                final String dst = makeRelative(root, src);
                if (!update || !dirExists(conf, new Path(args.dst, dst))) {
                    ++dirCount;
                    src_writer.append(new LongWritable(0), new FilePair(srcfilestat, dst));
                }
                dst_writer.append(new Text(dst), new Text(src.toString()));
            }

            Stack<FileStatus> pathstack = new Stack<FileStatus>();
            for (pathstack.push(srcfilestat); !pathstack.empty();) {
                FileStatus cur = pathstack.pop();
                FileStatus[] children = srcfs.listStatus(cur.getPath());
                for (int i = 0; i < children.length; i++) {
                    boolean skipPath = false;
                    final FileStatus child = children[i];
                    final String dst = makeRelative(root, child.getPath());
                    ++srcCount;

                    if (child.isDirectory()) {
                        pathstack.push(child);
                        if (!update || !dirExists(conf, new Path(args.dst, dst))) {
                            ++dirCount;
                        } else {
                            skipPath = true; // skip creating dir at destination
                        }
                    } else {
                        Path destPath = new Path(args.dst, dst);
                        if (cur.isFile() && (args.srcs.size() == 1)) {
                            // Copying a single file; use dst path provided by user as
                            // destination file rather than destination directory
                            Path dstparent = destPath.getParent();
                            FileSystem destFileSys = destPath.getFileSystem(jobConf);
                            if (!(destFileSys.exists(dstparent)
                                    && destFileSys.getFileStatus(dstparent).isDirectory())) {
                                destPath = dstparent;
                            }
                        }
                        //skip path if the src and the dst files are the same.
                        skipPath = update && sameFile(srcfs, child, dstfs, destPath, skipCRCCheck);
                        //skip path if it exceed file limit or size limit
                        skipPath |= fileCount == args.filelimit || byteCount + child.getLen() > args.sizelimit;

                        if (!skipPath) {
                            ++fileCount;
                            byteCount += child.getLen();

                            if (LOG.isTraceEnabled()) {
                                LOG.trace("adding file " + child.getPath());
                            }

                            ++cnsyncf;
                            cbsyncs += child.getLen();
                            if (cnsyncf > SYNC_FILE_MAX || cbsyncs > maxBytesPerMap) {
                                src_writer.sync();
                                dst_writer.sync();
                                cnsyncf = 0;
                                cbsyncs = 0L;
                            }
                        } else {
                            ++skipFileCount;
                            skipByteCount += child.getLen();
                            if (LOG.isTraceEnabled()) {
                                LOG.trace("skipping file " + child.getPath());
                            }
                        }
                    }

                    if (!skipPath) {
                        src_writer.append(new LongWritable(child.isDirectory() ? 0 : child.getLen()),
                                new FilePair(child, dst));
                    }

                    dst_writer.append(new Text(dst), new Text(child.getPath().toString()));
                }

                if (cur.isDirectory()) {
                    String dst = makeRelative(root, cur.getPath());
                    dir_writer.append(new Text(dst), new FilePair(cur, dst));
                    if (++dirsyn > SYNC_FILE_MAX) {
                        dirsyn = 0;
                        dir_writer.sync();
                    }
                }
            }
        }
    }
    LOG.info("sourcePathsCount(files+directories)=" + srcCount);
    LOG.info("filesToCopyCount=" + fileCount);
    LOG.info("bytesToCopyCount=" + TraditionalBinaryPrefix.long2String(byteCount, "", 1));
    if (update) {
        LOG.info("filesToSkipCopyCount=" + skipFileCount);
        LOG.info("bytesToSkipCopyCount=" + TraditionalBinaryPrefix.long2String(skipByteCount, "", 1));
    }
    if (args.dryrun) {
        return false;
    }
    int mapCount = setMapCount(byteCount, jobConf);
    // Increase the replication of _distcp_src_files, if needed
    setReplication(conf, jobConf, srcfilelist, mapCount);

    FileStatus dststatus = null;
    try {
        dststatus = dstfs.getFileStatus(args.dst);
    } catch (FileNotFoundException fnfe) {
        LOG.info(args.dst + " does not exist.");
    }

    // create dest path dir if copying > 1 file
    if (dststatus == null) {
        if (srcCount > 1 && !dstfs.mkdirs(args.dst)) {
            throw new IOException("Failed to create" + args.dst);
        }
    }

    final Path sorted = new Path(jobDirectory, "_distcp_sorted");
    checkDuplication(jobfs, dstfilelist, sorted, conf);

    if (dststatus != null && args.flags.contains(Options.DELETE)) {
        long deletedPathsCount = deleteNonexisting(dstfs, dststatus, sorted, jobfs, jobDirectory, jobConf,
                conf);
        LOG.info("deletedPathsFromDestCount(files+directories)=" + deletedPathsCount);
    }

    Path tmpDir = new Path(
            (dstExists && !dstIsDir) || (!dstExists && srcCount == 1) ? args.dst.getParent() : args.dst,
            "_distcp_tmp_" + randomId);
    jobConf.set(TMP_DIR_LABEL, tmpDir.toUri().toString());

    // Explicitly create the tmpDir to ensure that it can be cleaned
    // up by fullyDelete() later.
    tmpDir.getFileSystem(conf).mkdirs(tmpDir);

    LOG.info("sourcePathsCount=" + srcCount);
    LOG.info("filesToCopyCount=" + fileCount);
    LOG.info("bytesToCopyCount=" + TraditionalBinaryPrefix.long2String(byteCount, "", 1));
    jobConf.setInt(SRC_COUNT_LABEL, srcCount);
    jobConf.setLong(TOTAL_SIZE_LABEL, byteCount);

    return (fileCount + dirCount) > 0;
}

From source file:com.glaf.dts.transform.MxTransformManager.java

protected QueryDefinition fill(String queryId, String currentSql) {
    Stack<QueryDefinition> stack = queryDefinitionService.getQueryDefinitionStack(queryId);
    QueryDefinition query = queryDefinitionService.getQueryDefinition(queryId);
    List<Map<String, Object>> resultList = null;
    if (stack != null && stack.size() > 0) {
        while (stack.size() > 0) {
            query = stack.pop();
            if (StringUtils.isNotEmpty(currentSql) && StringUtils.equals(queryId, query.getId())) {
                currentSql = QueryUtils.replaceSQLVars(currentSql);
                query.setSql(currentSql);
                logger.debug("##currentSql:" + currentSql);
            }// w w  w  . j a v  a 2s  .c  om
            logger.debug("------------------------------------------------");
            logger.debug("####title:" + query.getTitle());
            logger.debug("####parentId:" + query.getParentId());
            if (query.getParentId() != null) {
                /***
                 * ???
                 */
                if (resultList != null && !resultList.isEmpty()) {
                    /**
                     * ??
                     */
                    logger.debug("###########get result list###########");

                    if (query.getChild() != null) {
                        resultList = this.prepare(query, resultList);
                    } else {
                        resultList = this.prepare(query, resultList.get(0));
                    }
                }
            } else {
                /**
                 * ??
                 */
                logger.debug("--------get result list---------");
                resultList = this.prepare(query);
            }
        }
    }
    return query;
}

From source file:alluxio.underfs.hdfs.HdfsUnderFileSystem.java

@Override
public boolean mkdirs(String path, MkdirsOptions options) throws IOException {
    IOException te = null;/*from  w  w w  .jav  a  2  s .c om*/
    RetryPolicy retryPolicy = new CountingRetry(MAX_TRY);
    while (retryPolicy.attemptRetry()) {
        try {
            Path hdfsPath = new Path(path);
            if (mFileSystem.exists(hdfsPath)) {
                LOG.debug("Trying to create existing directory at {}", path);
                return false;
            }
            // Create directories one by one with explicit permissions to ensure no umask is applied,
            // using mkdirs will apply the permission only to the last directory
            Stack<Path> dirsToMake = new Stack<>();
            dirsToMake.push(hdfsPath);
            Path parent = hdfsPath.getParent();
            while (!mFileSystem.exists(parent)) {
                dirsToMake.push(parent);
                parent = parent.getParent();
            }
            while (!dirsToMake.empty()) {
                Path dirToMake = dirsToMake.pop();
                if (!FileSystem.mkdirs(mFileSystem, dirToMake, new FsPermission(options.getMode().toShort()))) {
                    return false;
                }
                // Set the owner to the Alluxio client user to achieve permission delegation.
                // Alluxio server-side user is required to be a HDFS superuser. If it fails to set owner,
                // proceeds with mkdirs and print out an warning message.
                try {
                    setOwner(dirToMake.toString(), options.getOwner(), options.getGroup());
                } catch (IOException e) {
                    LOG.warn("Failed to update the ufs dir ownership, default values will be used. " + e);
                }
            }
            return true;
        } catch (IOException e) {
            LOG.warn("{} try to make directory for {} : {}", retryPolicy.getRetryCount(), path, e.getMessage());
            te = e;
        }
    }
    throw te;
}