Search in sources :

Example 36 with Stack

use of java.util.Stack in project jersey by jersey.

the class FilesScanner method processFile.

private void processFile(final File f) {
    if (f.getName().endsWith(".jar") || f.getName().endsWith(".zip")) {
        try {
            compositeResourceFinder.push(new JarFileScanner(new FileInputStream(f), "", true));
        } catch (final IOException e) {
            // logging might be sufficient in this case
            throw new ResourceFinderException(e);
        }
    } else {
        compositeResourceFinder.push(new AbstractResourceFinderAdapter() {

            Stack<File> files = new Stack<File>() {

                {
                    if (f.isDirectory()) {
                        final File[] subDirFiles = f.listFiles();
                        if (subDirFiles != null) {
                            for (final File file : subDirFiles) {
                                push(file);
                            }
                        }
                    } else {
                        push(f);
                    }
                }
            };

            private File current;

            private File next;

            @Override
            public boolean hasNext() {
                while (next == null && !files.empty()) {
                    next = files.pop();
                    if (next.isDirectory()) {
                        if (recursive) {
                            processFile(next);
                        }
                        next = null;
                    } else if (next.getName().endsWith(".jar") || next.getName().endsWith(".zip")) {
                        processFile(next);
                        next = null;
                    }
                }
                return next != null;
            }

            @Override
            public String next() {
                if (next != null || hasNext()) {
                    current = next;
                    next = null;
                    return current.getName();
                }
                throw new NoSuchElementException();
            }

            @Override
            public InputStream open() {
                try {
                    return new FileInputStream(current);
                } catch (final FileNotFoundException e) {
                    throw new ResourceFinderException(e);
                }
            }

            @Override
            public void reset() {
                throw new UnsupportedOperationException();
            }
        });
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) AbstractResourceFinderAdapter(org.glassfish.jersey.server.internal.AbstractResourceFinderAdapter) Stack(java.util.Stack) File(java.io.File) NoSuchElementException(java.util.NoSuchElementException)

Example 37 with Stack

use of java.util.Stack in project Talon-for-Twitter by klinker24.

the class IOUtils method dirSize.

public static long dirSize(File dir) {
    long result = 0;
    Stack<File> dirlist = new Stack<File>();
    dirlist.clear();
    dirlist.push(dir);
    while (!dirlist.isEmpty()) {
        File dirCurrent = dirlist.pop();
        File[] fileList = dirCurrent.listFiles();
        if (fileList != null) {
            for (int i = 0; i < fileList.length; i++) {
                if (fileList[i].isDirectory())
                    dirlist.push(fileList[i]);
                else
                    result += fileList[i].length();
            }
        }
    }
    return result;
}
Also used : File(java.io.File) Stack(java.util.Stack)

Example 38 with Stack

use of java.util.Stack in project k-9 by k9mail.

the class MessageDecryptVerifier method findPgpInlineParts.

public static List<Part> findPgpInlineParts(Part startPart) {
    List<Part> inlineParts = new ArrayList<>();
    Stack<Part> partsToCheck = new Stack<>();
    partsToCheck.push(startPart);
    while (!partsToCheck.isEmpty()) {
        Part part = partsToCheck.pop();
        Body body = part.getBody();
        if (isPartPgpInlineEncryptedOrSigned(part)) {
            inlineParts.add(part);
            continue;
        }
        if (body instanceof Multipart) {
            Multipart multipart = (Multipart) body;
            for (int i = multipart.getCount() - 1; i >= 0; i--) {
                BodyPart bodyPart = multipart.getBodyPart(i);
                partsToCheck.push(bodyPart);
            }
        }
    }
    return inlineParts;
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Multipart(com.fsck.k9.mail.Multipart) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) ArrayList(java.util.ArrayList) Body(com.fsck.k9.mail.Body) Stack(java.util.Stack)

Example 39 with Stack

use of java.util.Stack in project k-9 by k9mail.

the class AttachmentResolver method buildCidToAttachmentUriMap.

@VisibleForTesting
static Map<String, Uri> buildCidToAttachmentUriMap(AttachmentInfoExtractor attachmentInfoExtractor, Part rootPart) {
    HashMap<String, Uri> result = new HashMap<>();
    Stack<Part> partsToCheck = new Stack<>();
    partsToCheck.push(rootPart);
    while (!partsToCheck.isEmpty()) {
        Part part = partsToCheck.pop();
        Body body = part.getBody();
        if (body instanceof Multipart) {
            Multipart multipart = (Multipart) body;
            for (Part bodyPart : multipart.getBodyParts()) {
                partsToCheck.push(bodyPart);
            }
        } else {
            try {
                String contentId = part.getContentId();
                if (contentId != null) {
                    AttachmentViewInfo attachmentInfo = attachmentInfoExtractor.extractAttachmentInfo(part);
                    result.put(contentId, attachmentInfo.internalUri);
                }
            } catch (MessagingException e) {
                Timber.e(e, "Error extracting attachment info");
            }
        }
    }
    return Collections.unmodifiableMap(result);
}
Also used : Multipart(com.fsck.k9.mail.Multipart) HashMap(java.util.HashMap) MessagingException(com.fsck.k9.mail.MessagingException) Part(com.fsck.k9.mail.Part) Uri(android.net.Uri) Body(com.fsck.k9.mail.Body) Stack(java.util.Stack) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 40 with Stack

use of java.util.Stack in project jop by jop-devel.

the class Segment method buildSegment.

/**
	 * Collect all supergraph edges which are part of the segment.
	 * As segments are allowed to be interprocedural, we require that
	 * control flow graphs have return edges, and that return edges
	 * are in the exit set if they are not part of the segment.
	 */
private Set<SuperGraphEdge> buildSegment() {
    nodes = new HashMap<SuperGraph.ContextCFG, List<SuperGraphNode>>();
    edges = new HashSet<SuperGraphEdge>();
    otherEntries = new HashSet<SuperGraphEdge>();
    HashSet<SuperGraphEdge> actualExits = new HashSet<SuperGraphEdge>();
    Stack<SuperGraphEdge> worklist = new Stack<SuperGraphEdge>();
    /* push all targets of entry edges on the worklist */
    worklist.addAll(entries);
    while (!worklist.isEmpty()) {
        SuperGraphEdge current = worklist.pop();
        if (edges.contains(current))
            continue;
        /* continue if marked black */
        edges.add(current);
        /* If this is an exit egde, remember that it has been visited, and continue */
        if (exits.contains(current)) {
            actualExits.add(current);
            continue;
        }
        /* Otherwise add the target node and push all successors on the worklist */
        SuperGraphNode target = current.getTarget();
        MiscUtils.addToList(nodes, target.getContextCFG(), target);
        Iterators.addAll(worklist, sg.getSuccessorEdges(current));
    }
    exits = actualExits;
    for (SuperGraphNode node : getNodes()) {
        for (SuperGraphEdge edge : sg.incomingEdgesOf(node)) {
            if (!edges.contains(edge)) {
                otherEntries.add(edge);
            }
        }
    }
    /* for all nodes find entries which are not part of the segment; this are "otherEntries" */
    return edges;
}
Also used : ContextCFG(com.jopdesign.common.code.SuperGraph.ContextCFG) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) SuperGraphNode(com.jopdesign.common.code.SuperGraph.SuperGraphNode) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) Stack(java.util.Stack)

Aggregations

Stack (java.util.Stack)245 HashSet (java.util.HashSet)42 ArrayList (java.util.ArrayList)37 File (java.io.File)23 IOException (java.io.IOException)22 View (android.view.View)18 Test (org.junit.Test)18 ViewGroup (android.view.ViewGroup)14 HashMap (java.util.HashMap)14 Set (java.util.Set)12 LinkedList (java.util.LinkedList)11 List (java.util.List)11 ImageView (android.widget.ImageView)10 Map (java.util.Map)10 Document (org.w3c.dom.Document)10 TestInputHandler (org.apache.maven.plugins.repository.testutil.TestInputHandler)9 PostfixMathCommandI (org.nfunk.jep.function.PostfixMathCommandI)9 DocumentBuilder (javax.xml.parsers.DocumentBuilder)8 NotificationPanelView (com.android.systemui.statusbar.phone.NotificationPanelView)7 TreeSet (java.util.TreeSet)7