← Back to team overview

openjdk team mailing list archive

Bug#649245: openjdk-6-jdk: Java tries to treat files as folders and vice versa

 

Package: openjdk-6-jdk
Version: 6b23~pre11-1
Severity: important
Tags: upstream

I am working on a recursive directory crawler for a homework assignment. it is
treating files as directories and directories as files. here is the crawling
code (attatched).

-- System Information:
Debian Release: wheezy/sid
  APT prefers testing
  APT policy: (990, 'testing')
Architecture: amd64 (x86_64)

Kernel: Linux 3.1.0-1.dmz.2-liquorix-amd64 (SMP w/4 CPU cores; PREEMPT)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages openjdk-6-jdk depends on:
ii  libc6          2.13-21
ii  libx11-6       2:1.4.4-2
ii  openjdk-6-jre  6b23~pre11-1
ii  zlib1g         1:1.2.3.4.dfsg-3

Versions of packages openjdk-6-jdk recommends:
ii  libxt-dev  1:1.1.1-2

Versions of packages openjdk-6-jdk suggests:
pn  openjdk-6-demo    <none>
pn  openjdk-6-source  <none>
pn  visualvm          <none>
import java.io.*;
import java.util.*;

public class DodrillSAssgn6File {
	private static String sDir, sDate, sGrep;
	private static String sFileName[] = new String[2]; 
	private static Date dFindingDate;
	private static boolean bDate = false;

	@SuppressWarnings("deprecation")
	public static void main(String[] args) {
		sDir = prompt("Working directory: ");
		sDir = !isNullString(sDir) ? sDir : System.getProperty("user.dir");
		sFileName[0] = prompt("Enter File name: ");
		sFileName[1] = prompt("Enter file extension: ");
		sGrep = prompt("Stuff to search for in the files: ");
		sDate = prompt("Last modification date? (mm/dd/yy): ");
		
		try {
			String[] tempDate = sDate.split("/");
			dFindingDate = new Date
				(Integer.parseInt(tempDate[0]), Integer.parseInt(tempDate[1]), Integer.parseInt(tempDate[2]));
			bDate = true;
				//I know this is deprecated, it's just easier
		} catch (NumberFormatException e) {
			System.out.println("Not doing date");
		}
		
		try {
			processFilesInDirectory(new File(sDir));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static String prompt(String sPrompt) {
		System.out.print(sPrompt);
		return new Scanner(System.in).nextLine();
	}
	
	public static void processFilesInDirectory(File dir) throws FileNotFoundException {
		 File[] files = dir.listFiles();
		 	if (files != null) {
		 		for (File f : files) {
		 			if (f.isDirectory()) {
		 				System.out.printf("%s\n", f.getAbsolutePath());
		 				processFilesInDirectory(f);
		 			} else {
		 				if (f.isDirectory()) {
			 				System.out.printf("%s\n", f.getAbsolutePath());
			 				processFilesInDirectory(f);
			 			} if(!isNullString(sFileName[1]) && f.getName().endsWith(sFileName[1])) {
		 					System.out.println(f.getAbsolutePath());
		 				} else if(!isNullString(sFileName[0]) && f.getName().contains(sFileName[0])) {
		 					System.out.println(f.getAbsolutePath());
		 				} else if(!isNullString(new Scanner(f).findInLine(sGrep))) {
		 					System.out.println(f.getAbsolutePath());
		 				} else if(bDate && matchesDate(f)) {
		 					System.out.println(f.getAbsolutePath());
		 				}
 		 			}
	 		}	
	 	}
	}
	
	private static boolean isNullString(String a) {
		try {
			if(a.equals("") || a == null) {
				return true;
			} else {
				return false;
			}
		} catch (NullPointerException e) {
			return false;
		}
	}
	
	private static boolean matchesDate(File f) {
		return new Date(f.lastModified()).compareTo(dFindingDate) >= 0;
	}
	
	
}