Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


A Java File Search Utility
A Java File Search Utility

File searches are traditionally accomplished by an operating system utility. Most operating systems provide some sort of search facility that allows the user to track down misplaced or forgotten files. However, the facilities differ in their approach for searching files ­ graphical versus command-line interface, comprehensive versus limited search capability.

If you work in multiple environments as I do, you become reliant on search functionality available in one environment that may not be supported in another. This article details a Java file search utility that provides a consistent user interface and consistent functionality when searching for files.

Interface
The FindFile utility is made up of two classes: FindFile and FindFileFrame, located in FindFile.java. The FindFile class (see Listing 1 on JDJ Web site) simply contains a main() method, which is the entry point for the application. The main() method instantiates the FindFileFrame class (see Listing 2 on Web site) where the utility's GUI is constructed and where the main processing logic is contained. The GUI is constructed using panels combined with three layout managers (java.awt.FlowLayout, java.awt.- GridLayout and java.awt.BorderLayout) in favor of the more flexible, yet arguably more complicated and tedious java.- awt.GridBagLayout layout manager. I work predominantly on Win32 operating systems (iWin9x, WinNT); therefore I modeled the FindFile utility's user interface (see Figure 1) after the Win32 Find utility (see Figure 2).

Implementation
The FindFileFrame class implements the java.lang.Runnable interface and two event listener interfaces: java.awt.event.TextListener and java.awt.event.ActionListener. The java.awt.event.TextListener interface method, textValueChanged(), enables and disables the Find button based on the length of text entered in the File Name field. This prevents the user from starting a file search without first typing in something for a filename. The Look In field is optional and directs the utility to start the file search in the specified directory. If the field is left blank, the search is started in the current directory. The search is limited to the specified directory unless the Include Subfolders checkbox is selected. The user is able to specify a case-sensitive search by selecting the Case Sensitive checkbox.

The file search is performed in a separate thread via the java.lang.Runnable interface's run() method to allow the user the ability to interact with the utility. The run() method calls the updateUI() method with a true parameter to disable several user interface components prior to the search. The run() method then calls the checkForFile() method, which recursively cycles through any directories in the list only if the Include Subfolders checkbox is selected. The utility supports wild card character (i.e., * and ?) file searches through the use of a Java regular expression shareware package called pat, written by Steven R. Brandt and available at www.javaregex.com. Because the package uses a wild card character syntax slightly different from the format used for Win32 and UNIX operating systems, the entered filename is first converted to a format the package understands via the convert() method. If a file matching the specified filename is found, it's added to a java.awt.List component along with the file's fully qualified path. As the search progresses, the names of the directories searched are displayed in a java.awt.Label component located just below the search results. When the search is completed, the updateUI() method is called again, this time with a false parameter to enable the UI components.

Threading Issues
A started thread normally stops when its run() method executes to completion. In the case of this utility, however, a Stop button is provided to allow the user to cancel the file search at any time. Prior to JDK 1.2.x, a thread was prematurely terminated by calling the java.lang.Thread class's stop() method. However, because of its unsafe behavior that method has since been deprecated (see the JDK 1.2.x javadoc HTML help file for the java.lang.Thread class's stop() method to view detailed information concerning the method's deprecation). Rather than use a deprecated, unsafe method I chose an alternative mechanism to terminate the file search prematurely. When the utility's Stop button is clicked, the boolean instance variable, searching, is set to false, causing the file search to end normally as this variable is interrogated in the checkForFile() method's for loop.

Performance
Typically, what is gained in portability with a Java program is usually lost in performance. However, with the advent of the HotSpot compiler this is becoming less of an issue. I compiled and tested the FindFile utility using the three major JDK releases (JDK 1.1.8, 1.2.2, and 1.3.0 RC2) on a 450 MHz Pentium III workstation with 96 MB of RAM running WinNT. The timings represent the average number of seconds both utilities took to search for the same file five times in succession. The results are listed in Figure 3. Your timings will vary based on the JVM and operating system in use, the operating system activity and the speed of your workstation's processor.

Summary
The FindFile utility detailed here provides a consistent user interface and consistent functionality when used in heterogeneous environments. The utility is quite functional as it stands; however, more features can easily be added if desired.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

I was really interested in how you managed to implement such a thing...however I could not see the code you say you have.

Can I get a copy of the code?

No, I have not receive any copy

Did anyone of you get the source code?

Why I can''t open http://photos.sys-con.com/story/res/36412/FindFile.java?

I am interested in your search file implementation but it is not possible to view it. Please send me a copy. Thank you

I was really interested in how you managed to implement such a thing...however I could not see the code you say you have.

Can I get a copy of the code?

I could not get ur file. So that I could not comment on it. I am intrested in it and I want to see the flow in ur file. If u wish to send pls send me one copy of ''.java'' file. And The article is good, ur thinking on search is also good.


Your Feedback
vartika wrote: I was really interested in how you managed to implement such a thing...however I could not see the code you say you have. Can I get a copy of the code?
Kwee wrote: No, I have not receive any copy
Ed wrote: Did anyone of you get the source code?
Lin Rong Xiang wrote: Why I can''t open http://photos.sys-con.com/story/res/36412/FindFile.java?
Djien Kwee wrote: I am interested in your search file implementation but it is not possible to view it. Please send me a copy. Thank you
Ron wrote: I was really interested in how you managed to implement such a thing...however I could not see the code you say you have. Can I get a copy of the code?
Malyadri Naidu wrote: I could not get ur file. So that I could not comment on it. I am intrested in it and I want to see the flow in ur file. If u wish to send pls send me one copy of ''.java'' file. And The article is good, ur thinking on search is also good.
Enterprise Open Source Magazine Latest Stories . . .
Apache Deltacloud, the Red Hat-contributed ReSTful API that abstracts differences between clouds so services on any cloud can be managed – provided of course there’s a driver – has graduated from the Apache Foundation’s incubator and is now a full-fledged Top-Level Project (TLP). The...
With Cloud Expo 2012 New York (10th Cloud Expo) just four months away, what better time to start introducing you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference... We have technical and st...
AMD said late Tuesday that its chief sales officer Emilio Ghilardi had left the company and that CEO and president Rory Read is going to do his job while a replacement is sought. AMD didn’t say why Ghilardi left but it’s assumed Read wants his own people. Read is relatively new to th...
During the lifespan of M3 (Monitis Monitor Manager) there has always been something lacking – timers. M3 execution procedure was outlined in this previous article. The execution mentioned in the latter was a one-time-execution, whereas server monitoring requires periodic invocati...
Red Hat is putting its bought-in Gluster scale-out NAS storage technology, acquired in October, on the Amazon cloud. It’s styled Red Hat Virtual Storage Appliance for Amazon Web Services and other clouds are supposed to follow in short order.
A new episode of the screencast series is now available at the OpenNebula YouTube Channel. This screencast demonstrates the new easily-customizable self-service portal for cloud consumers. Its aim is to offer a simplified access to shared infrastructure for non-IT end users. The scree...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON Featured Whitepapers
ADS BY GOOGLE