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();
}
});
}
}
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;
}
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;
}
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);
}
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;
}
Aggregations